Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Absolute BSD - The Ultimate Guide To FreeBSD (2002).pdf
Скачиваний:
25
Добавлен:
17.08.2013
Размер:
8.15 Mб
Скачать

Configuring Ntpd

Ntpd requires a configuration file, /etc/ntpd.conf. Here's a sample:

...............................................................................................

driftfile /etc/ntp/drift

server 203.94.99.229

server 192.37.16.177

...............................................................................................

Let's do the easy thing first. The ntpd program needs a temporary file; in the preceding example, it's /etc/ntp/drift. While ntpd will create this file itself, it won't create any directories, so we have to create the /etc/ntp directory. We then list two chosen Tier 2 servers by IP address for the servers to communicate with. That's it!

Your servers can be set up to broadcast time updates across the local Ethernet, sharing time information with any other local servers running ntpd. This sounds good, but it is not a good idea on a server exposed to the public Internet.

Starting Ntpd

Once you have /etc/ntp.conf, just type ntpd to start ntpd. To start ntpd at boot, add the following entry in /etc/rc.conf.

...............................................................................................

xntpd_enable="YES"

...............................................................................................

Inetd

The inetd daemon handles connections for less frequently used daemons. For example, since most systems don't have a steady stream of incoming FTP requests, there's no need for the additional overhead of an FTP daemon listening, when it's going to be idle 99.9 percent of the time. Instead, inetd listens on the FTP port. When an FTP request comes in, inetd starts up the FTP daemon and hands off the request.

Inetd also handles functions that are so small and rarely used that they're easier to implement locally, rather than route them through a separate program. This includes things such as discard (which dumps any data it receives into the black hole of /dev/null), chargen (which pours out a stream of characters), and so on. These are disabled by default, but are available if needed. The standard inetd configuration includes information for many standard UNIX services, including telnet, ftp, and pop3. It also includes information for quite a few obscure protocols.

/etc/inetd.conf

Take a look at /etc/inetd.conf. Most daemons have separate IP and IPv6 configurations, so if you're not running IPv6, you can ignore all IPv6 entries. Let's look at one line from this file, the ftp configuration:

311

...............................................................................................

v ftp w stream x tcp y nowait z root { /usr/libexec/ftpd | ftpd −l

...............................................................................................

The first field (v) is the service name, which must match a name in /etc/services. Inetd relies upon the service name to determine which TCP or UDP port to open.

The second field (w) is the socket type. All TCP connections are type stream, while UDP connections are type dgram. There are other possible values, but if you're considering using them you're either (a) reading documentation for a particular program, or (b) almost certainly wrong.

The third field (x) is the protocol, which can be tcp, udp, tcp6, or udp6 (udp6 and tcp6 protocols are for IPv6 connections). As IPv6 grows more accepted and integrated with server programs, you'll start to see protocol labels of udp46 and tcp46. This means that the daemon can accept either sort of connection.

The next field (y) indicates whether inetd should wait for the particular service to accept the connection, or just start the program and go away. As a general rule, TCP programs use nowait while UDP programs need wait. If a service uses nowait, you can control the maximum number of connections per second the service will allow by adding a slash and a number directly after the nowait, like this: nowait/5. If you don't do this, and you receive a flood of connections, inetd will start as many copies of the program as it needs to service those requests. (This is a simple way to knock a server off the Internet.)

The next field (z) says who the daemon runs as. Some daemons can run as special, dedicated users. We'll see specific examples of that in the next two chapters.

The sixth field ({) is the full path to the program that inetd runs when it receives a connection request. If it's a service included in inetd, it appears as internal.

The last field (|) gives the command to start an external program and any command−line options needed.

Configuring Programs in Inetd

/etc/inetd.conf seems to need a lot of information, but if you want to add a program, you can probably copy an existing line and use it with minor modifications. For example, let's consider implementing a very trivial network service, the Quote of the Day (QotD) service. When you connect to the QotD port, a QotD server sends back a random quote and disconnects. FreeBSD includes a randomquote generator in its games collection, fortune(1). This random quote generator is all we need to use to implement an inetd−based network program. We'll use the fortune program to generate our random quotes.

Port Number

If you search /etc/services for "qotd", you'll find that it's listed as port 17. QotD runs on port 17.

Network Protocol

Since the QotD service requires that you connect to a network port, and get something back, it's going to be a TCP−based service. (The alternative, UDP, would not work, because UDP

312

connections don't expect anything to come back.) We have to specify TCP in our inetd configuration. Any TCP service seems that you have to specify "nowait" in the fourth field in our inetd.conf entry.

User

We'll run our quote−generating command as root. In an ideal world, we would create a separate user just for this service, but I'm not going to bother for this example.

Path

Fortune lives in /usr/games/fortune.

Running the Command

We don't need any command−line options for fortune. (You could use −o if you want, but that's probably not a good idea on a publicly available server.)

Sample inetd.conf Configuration

Putting this all together, our line in /etc/inetd.conf looks like this:

...............................................................................................

qotd stream tcp nowait root /usr/games/fortune fortune

...............................................................................................

While this example is trivial, other alterations to /etc/inetd.conf are no more difficult.

Inetd Security

Newer sysadmins tend to think of inetd as a single service with a monolithic security state. Nothing could be further from the truth. Inetd itself is fairly secure, but it unfairly takes a certain amount of blame for problems in the programs it forwards requests to. Some of the programs provide insecure protocols (such as telnet and ftp), while others have a history of abuse.

Still, many people categorically disable inetd. Others make sure that all the services are disabled except enable inetd itself, because several ports provide services via inetd, and having it enabled makes installing these programs slightly easier. I recommend disabling inetd unless you have specific services that you want to provide, and then enabling only those services.

Starting Inetd

You can start inetd at the command line by just typing inetd as root. Alternatively, you can set it to start automatically at boot by changing /etc/rc.conf:

...............................................................................................

inetd_enable="YES"

...............................................................................................

313

Changing Inetd's Behavior

You can set flags in /etc/rc.conf, in the variable inetd_flags, to alter inetd's startup behavior. The default inetd flags turn on TCP Wrappers, as per /etc/hosts.allow (see Chapter 8). Here are some other useful flags:

Flag Description

−l

Logs every successful connection.

Sets a maximum number of connections per second that can be

−c

made to any service. The default is unlimited. Note that unlimited is not the same as “infinite“—your hardware will only handle so many connections.

−C

Sets a maximum number of times a single remote IP address can connect to a service. The default is unlimited.

 

Sets the maximum number of

times

any one service

can be

−R

started in one minute. The

default is 256. If you set this to

 

0, you allow an unlimited number

of connections.

 

−a

Sets the IP address to bind to. Inetd usually listens on all available IP addresses.

−w

Uses TCP Wrappers for external services as per hosts.allow (see Chapter 8)

−W

Uses TCP Wrappers for internal services as per hosts.allow (see Chapter 8)

As an extreme example, if you wanted to use TCP Wrappers, allow only two connections per second from one host, and allow an unlimited number of connections per minute, you would set this as follows:

...............................................................................................

inetd_flags="−Ww −C 2 −R 0"

...............................................................................................

314