|
Controlling Access to Your Services with xinetd
Creatures of the Linux UnderworldWhenever you learn about controlling access to a Linux box, one "creature" you usually encounter is the "superdaemon." A superdaemon is a daemon that controls other daemons--and daemons are typically network service control programs that run long-term behind the scenes, waiting for when they need to step into action. In the Linux realm, "the superdaemon" has typically referred inetd, which handles requests for a number of daemons that either aren't used often enough to justify running in the background all of the time, or have such a simple job that a standalone daemon simply isn't needed. The problem with inetd is that this superdaemon makes little attempt to be secure. It allows you to disable various services if you don't want to use them, but there is no fine control available. Enter xinetd (http://www.xinetd.org). This program is a "secure" replacement for inetd, meaning in this case that it offers many features that allow you to control who accesses which services, and from where. I always keep the Titanic in mind when I talk about security or safety, meaning that nothing is fully secure, but any level of native access control in the superdaemon certainly helps us to protect our systems. Some distributions (such as Mandrake and Red Hat) currently come with xinetd installed and enabled by default. Yours might include xinetd but not by default, or you can download the tool from the project site.
xinetd Versus inetd, an OverviewLet's take a look at the real differences between xinetd and inetd before we get into using xinetd. Anyone who's dealt with the inetd superdaemon is likely familiar with its configuration file, inetd.conf. This file contains a list of all of the services the daemon controls, along with commented out items that it could control if you wanted to activate those services. That's pretty much all there is to inetd. You can control these services using additional features of Linux itself, such as hosts.allow, hosts.deny, traffic filtering, and so on. But for many people that's not enoughmost of the files discussed in this article are in the /etc directory on most Linux distributions, but sometimes distributions like to utilize a different setup, so you might have to dig for them. xinetd has a collection of configuration files. The base file is xinetd.conf, which allows for general configuration. Along with the main configuration file is the subdirectory xinetd.d, which contains a series of individual files pertaining to various applications. Each of these files is loaded by the xinetd.conf when xinetd loads its configuration data into memory. Within each of the xinetd configuration files you have a wide range of choices to control where people can access a service from, what local accounts they can use to access the service, what remote accounts they can use, and much more.
Installing xinetdSince there are so many distributions that don't come with xinetd already installed by default, I'll go through the process of getting and installing xinetd from its web site. Those who have access to this tool already or through their distribution's package management system might prefer to install from there insteadlook for the distribution version first, that will make your life much easier since it will ensure your distribution knows the program is installed. Point your browser to the xinetd site, and download the source file. You'll find that it's remarkably small, and that the installation is a pretty standard process. To compile and install this software, do the following:
That's the first stage. Notice that your new configuration file was copied into /tmp. Do not try to use the default file. It likely won't work.
Understanding xinetd Configuration FilesThe xinetd program has two major configuration setups. First, there's the default configuration, which is in the file /etc/xinetd.confthough your distribution might put this file in a different place. Then there's a group of files typically in the /etc/xinetd.d directory that each corresponds to a different service. We'll start with xinetd.conf. A default setup for this file might look like: # Simple configuration file for xinetd
defaults
{
only_from = localhost
instances = 60
log_type = SYSLOG authpriv
log_on_success = HOST PID
log_on_failure = HOST
cps = 25 30
}
includedir /etc/xinetd.d
If you've only seen the inetd configuration file before, it should
already be obvious just how different xinetd setup is. Contained in
xinetd.conf are your global defaultsthough you can do individual
configurations here as well. The globals are assigned in the defaults
statement, and its contents are marked off with the braces (
If you see the following as the last line then your xinetd is set up to look in /etc/xinetd.d (or whatever directory is specified) for specific configurations: includedir /etc/xinetd.d You can add such a line as well, if needed. When we turn our attention to the broader range of elements you might configure for specific services, we discover that there is a long list of options. Rather than spending the time and space covering every option in detail, I'll cover one specific example so that we can get on to more tutorial. You can get more information about any option, and of course the whole list of available options, in the xinetd.conf man page. Let's use the vsftpd xinetd configuration file: # default: off
# description: The vsftpd FTP server serves FTP connections. It uses \
# normal, unencrypted usernames and passwords for authentication.
service ftp
{
disable = no
socket_type = stream
wait = no
user = root
server = /usr/sbin/vsftpd
nice = 10
}
Notice that this file, like all of its cousins in /etc/xinetd.conf,
starts with a line in the form
Inside the braces are the options for this specific service. Here I'm only going to define what these particular settings mean. We'll get into the specifics of these options in the tutorial. The vsftpd setup is, from top to bottom:
All of these settings are in addition to what was set in xinetd.conf.
Configuring xinetd.conf and the xinetd.d filesWhen it comes to configuring your own superdaemon, you might be much more fussy than just accepting the defaults. The first thing you need to do is determine which services you want to configure, because what the service is and does will tell you what statements you must include, and what statements won't work at all. Once you've got a list of what you want to custom configure, decide if you want to alter xinetd.conf itself, or to create a separate file in the xinetd.d directory. I typically recommend that if it's not global, to use the separate files. It just keeps things neater. Now you have to choose what you want to set for this particular service. There are forty-four available parameters, but only two that must be set for any service. These two are:
The other required parameters depend on the type of service you're setting up. For the services that xinetd does not handle for you, such as incoming FTP and web requests, you must also have:
Another pair of services are referred to as RPC services, and unlisted services. An RPC (Remote Procedure Call) service is a C programming library that supports client/server architecture, allowing a machine to send a command to another machine, which executes the command and then sends back the results. An unlisted service is one that isn't included in /etc/services or /etc/rpcthe file that contains the list of all RPC services. Keeping the RPC and unlisted services in mind, the remaining required statements (if appropriate for the service you're setting up) are:
From here, everything is optional. Rather than putting you to sleep covering all of the items in the xinetd.conf man page, here are the ones you are most likely to want to use or to run into when editing existing filessee the xinetd.conf man page for in depth specifics on exact syntax and options:
Most of these entries are used in the format: statement = item1 item2 ... So, once you know what service you want to configure, where you want to configure it (what file), and what portions you want to configure, you create an entry that looks like this whether you're doing it in the main file or in one of the separate files: servicename
statement1 = item1 item2 ...
statement2 = item1 item2 ...
...
}
Once you're finished making these configuration changes, be sure to restart xinetd so it can load the new setup. It's typically a good idea to use the control scripts if your distribution supports them. For example, in Red Hat Linux you would type: /etc/rc.d/init.d/xinetd restart Hopefully you've found here that xinetd deserves further investigation. If you're used to inetd then this more secure superdaemon can give you a few headaches at first, but the better control over who's accessing your system, and when, makes up for it.
Sites of interest:
Dee-Ann LeBlanc has written over 10 computer books, over sixty articles, taught classes, and more, mostly involving the Linux operating system and its programs. You can follow her work and share your input through her new mailing list at http://www.dee-annleblanc.com/mailman/listinfo/general, or find out more in general at http://www.Dee-AnnLeBlanc.com/.
|