Sometimes, (un)scheduled maintenance will take down a webserver for a long enough time that we’ll want to let visitors know. By writing a quick and simple few lines, we can warn users that our server will be down for the next while.
This is where inetd comes in. Inetd is the ‘superserver’ which provides coordination for network services like ftp, telnetd, and various other daemons for Unix-like operating systems.
By abusing this system slightly, we can use
echo to act as our serving programs, echoing HTML, and have inetd pass out the served data as a TCP stream. This is what the web is in its most basic form, and using inetd in this way just implements enough protocol to be recognizable by a web browser.
There is one caveat though – since
echo can’t process the incoming data, we will have to forge a valid HTTP response header. This requires prepending “HTTP/1.1 200” to any HTML served.
As a All-in-One-Liner, this translates to:
80 stream tcp nowait nobody /bin/echo echo -e HTTP/1.1 200 OK\n\n<body><p>Hello World</p></body></html>
cat instead of
echo, we can have a one-liner that pulls HTML from a file:
80 stream tcp nowait nobody /bin/cat cat /path/to/file
Plopping these lines into the end of /etc/inetd.conf and restarting the service is enough to have your barebones HTTP ‘server’ up and running. Now all we need to do is browse to our server and we should see…
A good example ‘down for service’ HTML (shown rendered, above) file can be found here. One thing that needs to be done to any HTML file, is including the
HTTP 200 response at the top. This will be enough ‘fool’ web browsers into thinking they are communicating with a legitimate server:
HTTP/1.1 200 OK <title>Site Maintenance</title> <h1>We'll be back soon!</h1> <div> <p>Sorry for the inconvenience but we are performing some maintenance at the moment. We'll be back online shortly!</p> </div
Almost every system comes bundled with some form of inetd already installed, so this method has the benefit portability. Net/Open/FreeBSDs all ship inetd with the base system; RHEL/CentOS includes it in the ‘full’ images’ base; Ubuntu/Debian/Mint require an apt-get install openbsd-inetd to install inetd.
Now, have a Happy Maintenance Window everyone!