Выбрать главу

discard 9/udp  sink null

systat  11/tcp users

Typically, there are two entries for each service because most services can use either TCP or UDP for their transmissions. Usually after /etc/services is initially configured, you will not need to change it.

Using /etc/nsswitch.conf After Changing Naming Services

This file was initially developed by Sun Microsystems to specify the order in which services are accessed on the system. A number of services are listed in the /etc/nsswitch.conf file, but the most commonly modified entry is the hosts entry. A portion of the file can look like this:

passwd: files

shadow: files

group:  files

#hosts: db files nisplus nis dns

hosts:  files dns

This tells services that they should consult standard UNIX/Linux files for passwd, shadow, and group (/etc/passwd, /etc/shadow, /etc/group, respectively) lookups. For host lookups, the system checks /etc/hosts and if there is no entry, it checks DNS. The commented hosts entry lists the possible values for hosts. Edit this file only if your naming service has changed.

Setting a Name Server with /etc/resolv.conf

/etc/resolv.conf is used by DNS, the domain name service. (DNS is covered in detail in Chapter 23.) The following is an example of resolv.conf:

nameserver 192.172.3.8

nameserver 192.172.3.9

search mydomain.com

This sets the nameservers and the order of domains for DNS to use. The contents of this file are set automatically if you use Dynamic Host Configuration Protocol, or DHCP (see the section on "DHCP" later in this chapter).

CAUTION

If you make use of NetworkManager to handle your network connections, don't make any changes to /etc/resolv.conf, because it will cause havoc for NetworkManager. Instead, let NetworkManager dynamically work with this file of its own accord.

Setting DNS Search Order with /etc/host.conf

The /etc/host.conf file lists the order in which your machine will search for hostname resolution. The following is the default /etc/host.conf file:

order hosts, bind

In this example, the host checks the /etc/hosts file first and then performs a DNS lookup. A couple more options control how the name service is used. The only reason to modify this file is if you use NIS for your name service or you want one of the optional services. The nospoof option can be a good option for system security. It compares a standard DNS lookup to a reverse lookup (host-to-IP then IP-to-host) and fails if the two don't match. The drawback is that often when proxy services are used, the lookup fails, so you want to use this with caution.

Examining Host Network Settings in /etc/sysconfig/network

Changes to /etc/sysconfig/network do take effect until you restart the networking daemons or reboot the system. If you use Fedora's graphical configuration network tools (described in the next section), you should not edit this file. The file might look like this:

NETWORKING=yes

HOSTNAME=myhost

GATEWAY=192.112.50.99

A GATEWAYDEV setting is also available to associate a specific network device (such as eth0 or eth1 and so on). An additional optional entry to /etc/sysconfig/network is for NIS domain machines and would look like this:

NISDOMAIN=rebel

The network file previously supported a FORWARD_IPV4 value, which determined whether the host forwarded IP packets (usually "yes" for routers). This setting is now saved in /etc/sysctl.conf as a net.ipv4.ip_forward setting, which can be modified if the forwarding changes are required. See the sysctl.conf man page for more information.

Laying the Foundation: The localhost Interface

The first thing that needs to happen before you can successfully connect to a network or even to the Internet is creating a localhost interface, sometimes also called a loopback interface, but more commonly referenced as lo. The TCP/IP protocol (see "Networking with TCP/IP" later in this chapter) uses this interface to assign an IP address to your computer and is needed for Fedora to establish a PPP interface.

Checking for the Availability of the Loopback Interface

You should not normally have to manually create a loopback interface because Fedora creates one automatically for you during installation. To check that one is set up, you can use the ifconfig command while working as root to show something similar to this:

# ifconfig

lo Link encap:Local Loopback

   inet addr:127.0.0.1 Mask:255.0.0.0

   UP LOOPBACK RUNNING MTU:16436 Metric:1

   RX packets:12 errors:0 dropped:0 overruns:0 frame:0

   TX packets:12 errors:0 dropped:0 overruns:0 carrier:0

   collisions:0 txqueuelen:0

   RX bytes:760 (760.0 b) TX bytes:760 (760.0 b)

What you see in this example is evidence that the loopback interface is present and active. It shows that the inet addr is the IP number assigned to the localhost, typically 127.0.0.1 along with the broadcast mask of 255.255.255.0, and that there has been little activity on this interface (RX = receive and TX = transmit). If your output does not look like the preceding one, you must hand-configure the localhost interface after you finish the rest of this section.

Configuring the Loopback Interface Manually

The localhost interface's IP address is specified in a text configuration file that is used by Fedora to keep record of various networkwide IP addresses. The file is called /etc/hosts and usually exists on a system, even if it is empty. The file is used by the Linux kernel and other networking tools to enable them to access local IP addresses and hostnames. If you have not configured any other networking interfaces, you may find that the file only contains one line:

127.0.0.1 localhost.localdomain localhost

This line defines the special localhost interface and assigns it an IP address of 127.0.0.1. You might hear or read about terms such as localhost, loopback, and dummy interface; all these terms refer to the use of the IP address 127.0.0.1. The term loopback interface indicates that to Linux networking drivers, it looks as though the machine is talking to a network that consists of only one machine; the kernel sends network traffic to and from itself on the same computer. Dummy interface indicates that the interface doesn't really exist as far as the outside world is concerned; it exists only for the local machine.

Each networked Fedora machine on a LAN will use this same IP address for its localhost. If for some reason a Fedora computer does not have this interface, edit the /etc/hosts file to add the localhost entry, and then use the ifconfig and route commands as root to create the interface like this: