Книга: Fedora™ Unleashed, 2008 edition

Network Configuration Files

Network Configuration Files

As previously stated, seven network configuration files can be modified to make changes to basic network interaction of your system. The files are as follows:

/etc/hosts — A listing of addresses, hostnames, and aliases

/etc/services — Network service and port connections

/etc/nsswitch.conf — Linux network information service configuration

/etc/resolv.conf — Domain name service domain (search) settings

/etc/host.conf — Network information search order (by default, /etc/hosts and then DNS)

/etc/sysconfig/network — The hostname, IP address, boot activation control, and gateway settings (along with optional IPv6 settings)

/etc/sysconfig/network-scripts/ifcfg-eth0 — Network settings for the eth0 network device; see the file sysconfig.txt under the /usr/share/doc/initscripts/ directory for details about optional settings

After the first six of these files have been modified, the changes are active. As with most configuration files, comments can be added with a hash mark (#) preceding the comment. The last file (/etc/sysconfig/network) requires the networking daemons to be restarted before the file is used. All seven of these files have a man page written about them for more information.

Adding Hosts to /etc/hosts

The /etc/hosts file is a map of IP to hostnames. If you are not using DNS or another naming service, and you are connected to a large network, this file can get quite large and can be a real headache to manage. A small /etc/hosts file can look something like this:

127.0.0.1      localhost.localdomain localhost
128.112.50.69  myhost.mydomain.com myhost
128.112.50.169 yourhost.mydomain.com yourhost

The first entry is for the loopback entry. The second is for the name of the machine. The third is another machine on the network. If no naming service is in use on the network, the only host that myhost recognizes by name is yourhost. (IP addresses on the network can still be used.)

If your network is using a naming service, the last line is not needed and can be deleted. However, if myhost connects to yourhost frequently, it might be good to leave the entry so that myhost does not need to consult the naming service each time. This can save time and reduce the strain on the network or the name service server. Edit this file if you need to change your hostname or IP address or if you aren't using a naming service and a host has been added to your network.

Service Settings in /etc/services

The /etc/services file maps port numbers to services. The first few lines look similar to this (the /etc/services file can be quite long, more than 500 lines):

# Each line describes one service, and is of the form:
#
# service-name port/protocol [aliases ... ] [# comment]
tcpmux  1/tcp  # TCP port service multiplexer
tcpmux  1/udp  # TCP port service multiplexer
rje     5/tcp  # Remote Job Entry
rje     5/udp  # Remote Job Entry
echo    7/tcp
echo    7/udp
discard 9/tcp  sink null
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.

Оглавление книги


Генерация: 0.603. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз