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

LD_LIBRARY_PATH environment variable, you can set it like so:

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

55 * * * * * dbadmin LD_LIBRARY_PATH=/usr/local/dblib ;/usr/local/bin/db−backup.sh

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

/etc/csh.*

The /etc/csh.* files contain systemwide defaults for csh and tcsh. When a user logs in with either of these shells, the shell executes any commands it finds in /etc/csh.login. Similarly, when the user logs out, /etc/csh.logout is executed. You can place general shell configuration information in /etc/csh.cshrc.

/etc/dhclient.conf

Many operating systems give you very basic DHCP client configuration with no opportunity to fine−tune or customize it; you either use it or you don't. Any operating system that uses the Internet Software Consortium's DHCP client, including all of the BSDs, lets you fine−tune your DHCP client setup.

In most cases, an empty DHCP client file (/etc/dhclient.conf) will give you full DHCP functionality, but won't work correctly in all situations. Perhaps you're connecting to a DHCP server across the country, your local LAN is having problems, or you have multiple DHCP servers. You may be able to solve these problems by tweaking your DHCP configuration. A DHCP lease contains your network configuration information, such as the IP address you get, the default route, and the nameservers available for your use. Without a valid, correct lease, you won't have Internet connectivity.

Entries in dhclient.conf resemble C code and generally include a variable declaration, followed by a value. Each line ends in a semicolon.

Prolonging Lease Requests

When dhclient starts, it requests the last IP address it used (leased) and, by default, spends ten seconds trying to get that address. The reboot time is the length of time the client will spend trying to get the old address re−issued. To change this waiting time, use the reboot statement. For example, I've been on large corporate networks where the DHCP server was in another state; by adjusting the reboot time upwards, I could easily get my previous network address. Just specify the reboot time in dhclient.conf, with a trailing semicolon in standard C code style.

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

reboot 20;

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

If the client cannot get its previous IP address in the reboot time, it will request a new one instead.

191

Rejecting Bad DHCP Servers

One of dhclient's more interesting features is its ability to reject bad DHCP servers. For example, some networks allow just about anyone to hook just about anything to them, like the ones found on exhibition floors or at some development companies. In such situations it's quite possible for there to be a rogue DHCP server on the floor, and if your system receives a DHCP lease that just doesn't work, it might be from a rogue server.

To identify a bad DHCP server, examine the leases you have received in /var/db/dhclient.leases. This file lists all the leases you have ever received, including the bad one. Identifying a bad DHCP server is a matter of trial and error. Get the IP address of each DHCP server, and reject them one at a time until you get a working configuration. For example, if the bad server's address was 192.168.1.84, enter

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

reject 192.168.1.84

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

Note If you find a rogue DHCP server on one of your networks, it's much better to find and disable the rogue server than to patch around it with a reject statement. On a foreign network, however, you don't generally have the privilege to do that.

Announcing Host Information

If you are on someone else's network and feel like being kind to the local network administrator, add a send statement to your dhclient.conf. The DHCP server will record the information you put in your send statement in its lease database. The local network administrator can use this information to find you if your system starts misbehaving and damaging the network. (You might not think this is a good thing, but making yourself easy to find is much better than making the administrator hunt you down.)

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

send host−name "mwlucas−laptop.bigcompany.com";

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

Of the many other options in dhclient.conf, like the ability to refuse leases that don't include information you want, most are relatively useless under normal (and most abnormal) circumstances. For truly detailed information on dhclient's more exotic options read dhclient.conf(5).

/etc/fstab

The /etc/fstab file describes the filesystems on the system. For details on the File System Table, see Chapter 16.

/etc/ftp.*

The /etc/ftp.* files control how the system's FTP server behaves. For details on /etc/ftpusers, /etc/ftpchroot, /etc/ftpwelcome, /etc/ftpmotd, and general FTP operations, see Chapter 15's nice little write−up on FTP.

192

/etc/hosts.allow

The /etc/hosts.allow file controls who can access daemons compiled with TCP Wrappers support. It's covered in painful detail in Chapter 8.

/etc/hosts.equiv

The /etc/hosts.equiv file allows trusted remote systems to log in or run commands on the local system without providing a password or even logging in. Hosts listed in this file are assumed to have performed user authentication on a trusted system, and hence the local system doesn't have to bother re−authenticating the user.

This file is handy and useful on friendly networks, but, unfortunately, there is no such thing as a friendly network nowadays. In fact, any one disgruntled employee can destroy a corporate network with this service. A machine running /etc/hosts.equiv on the naked Internet is pretty much dog meat for the first script kiddie who wanders by. In fact, /etc/hosts.equiv and its related services have even bitten top−notch security experts.

Still, should you decide to use this risky feature, you must have rsh or rlogin, or both, enabled in /etc/inetd.conf (see Chapter 13). The format is simple: a hostname, followed by an optional username.

For example, assume you have two UNIX boxes, "daffy" and "bugs". If bugs's /etc/hosts.equiv includes "daffy", a user on daffy can get a shell on bugs without typing a password.

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

daffy; rlogin bugs

Last login: Tue Apr 3 19:12:08 from 192.168.1.200

Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994

The Regents of the University of California. All rights reserved.

FreeBSD 5.0−CURRENT (PETULANCE) #0: Mon Aug 21 12:27:59 EDT 2000 You have mail.

bugs;logout

rlogin: connection closed. daffy;

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

See? No password. This works well, unless some intruder has broken into daffy. Remember, if you use this tool, a compromise on one machine means that every machine on your network is compromised. Rlogin and related tools are really unsuitable for any modern networked environment.

With comparatively recent modifications to rlogin and rsh, you can require a password to access another system. If you're going to do that, however, you might as well implement things properly and start using ssh (see Chapter 13).

/etc/hosts.lpd

The /etc/hosts.lpd file is one of the simplest files in /etc. Hosts listed here, each on their own line, may print to the printer(s) controlled by this machine. While you can use hostnames, DNS problems can choke printing, so use IP addresses instead.

193

Unlike many other UNIX configuration files, this one does not accept network numbers or netmasks; you must list individual hostnames or IP addresses.

/etc/inetd.conf

The inetd daemon handles incoming network connections for smaller daemons that don''t run frequently. For details, see the section on inetd in Chapter 13.

/etc/locate.rc

The locate(1) program finds all files of a given name. For example, to find locate.rc, enter the following:

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

# locate locate.rc

/etc/locate.rc

/usr/share/examples/etc/locate.rc

/usr/src/usr.bin/locate/locate/locate.rc

#

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

You'll see that locate.rc can be found in three places. One is in the main /etc directory, the second is in the system examples directory, and the third is in the system source code.

Once a week your FreeBSD system scans its disks, builds a list of everything it finds, and stores that list in a database. The list−building program uses the values shown in /etc/locate.rc as defaults (/etc/locate.rc does not affect how locate(1) itself runs). To change some of those parameters, and thereby change how your locate database is built and what it contains, consider setting the following in /etc/locate.rc:

The file−finding program stores its temporary files in TMPDIR. If you're low on space in your system temporary directory, you can change this path.

The location of the weekly database can be changed via the FCODES variable. This can have repercussions on other parts of the locate system, however, so be prepared for odd results.

The SEARCHPATHS value lists every directory you want searched. This defaults to /, the whole disk; to index only a portion of your disk, set a specific value here.

The PRUNEPATHS value lists directories you don't want to index. This defaults to excluding temporary directories that traditionally contain only short−lived files.

The FILESYSTEMS variable controls the sort of filesystem you want to index. The default is UFS, the standard FreeBSD filesystem, but you can list other filesystem types, such as MD (memory disks) or NFS (network filesystem). If you have foreign filesystems mounted, such as an EXT2FS partition, you might want to include them as well. (By the way, indexing network filesystems is a bad idea; if all of your servers start indexing the fileserver, you will bog down the network badly.)

/etc/login.access

Some servers have hundreds of users, each with different needs. So how do you assign different privileges to each?

194

FreeBSD includes a few different ways to control user access. The /etc/login.access file controls a user's ability to log in. Every time you try to open a connection to a FreeBSD system, the permissions in login.access are checked first. If login.access contains rules that forbid logins from that user, the login attempt fails immediately. This file defaults to empty, meaning there are no restrictions on anyone with a username and password.

The /etc/login.access file has three colon−delimited fields. The first either grants (+) or denies ( ) the right to log in; the second is a list of users or groups; and the third is a list of connection sources.

The /etc/login.access file permits an "all" and "all except" syntax, much like /etc/hosts.allow uses for TCP Wrappers (see Chapter 8), allowing the administrator to make basic but expressive rules. The login program checks rules on a first−fit basis, rather than a best fit. When the system finds a rule where both the group and the connection source match, it immediately accepts or rejects the connection. As such, rule order is very important.

For example, to only allow members of the wheel group and the user root to log in to the system console, you might try to use:

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

+:wheel root:console

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

The problem with this rule, though, is that it doesn't actually deny users login privileges. Since the default is to accept logins, and all this entry does is explicitly grant login rights to two sets of users, this won't stop people from logging in.[1] Other rules will continue to be processed. If my username is javerage, and I try to log in to the console, this rule doesn't deny me access.

So rather than use a statement like the preceding one, try one like this, the inverse:

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

−:ALL EXCEPT wheel root:console

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

This will reject connections more quickly, and run less risk of administrator error. As a rule, it's best to build your lists by rejecting logins, rather than permitting them.

When applying this rule, we see that Joe Average matches this rule and is immediately rejected. Since rules are applied based on first fit, there's no chance that a later rule will match, so we avoid unintended access.

Connection Source

The last field in the /etc/login.access file, the connection source, has the greatest variety of values. You can use several different types of information here: hostnames, host addresses, network numbers, domain names, LOCAL, and ALL.

195

Hostnames

Hostnames rely upon DNS or the hosts file. If you suspect your nameserver might suffer a hack at some time, you probably don't want to use this system; intruders can give a hostname any IP address that they like, and fool your system into accepting the connection. Still, you could do this:

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

−:ALL EXCEPT wheel:fileserver.mycompany.com

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

Users in your wheel group could log in from the fileserver, but nobody else could.

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

ALL

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

ALL means always match. This is particularly useful in combination with EXCEPT, as we'll see next.

Host Addresses and Networks

Host addresses look like hostnames, but they're immune to spoofed DNS.

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

−:ALL EXCEPT wheel:169.254.8.3

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

A network number is anything that ends in a period, like this:

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

−:ALL EXCEPT wheel:169.254.8.

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

This would allow anyone in the wheel group to log in from a machine whose IP address began with 169.254.8, and deny everyone else.

For example, if you didn't want anyone to access your firewall unless they logged in from a management workstation, you could do something like this:

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

−:ALL EXCEPT wheel:ALL EXCEPT 192.168.89.128 192.168.170.33

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

LOCAL

The most complicated location is LOCAL, which matches any hostname without a dot in it (generally only hosts in the local domain). For example, http://www.absolutebsd.com/ thinks that any host in "AbsoluteBSD.com" matches LOCAL.

This works via reverse DNS (see Chapter 12), which is the process where you look up a host's

196