Networking / Beginners

The ifcfg files

Each network interface has an ifcfg configuration file located in /etc/ sysconfig/network-scripts. The device name is added to the end of the filename. So, for example, the configuration file for the first Ethernet interface is called ifcfg-eth0.

This file is created and updated by the Network Configuration program, so you don't have to edit it directly (if you don't want to).

Here's a typical ifcfg file for an interface that has a static IP address:

DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
IPADDR=192.168.1.200
NETMASK=255.255.255.0
BROADCAST=192.168.1.255
NETWORK=192.168.1.0

Here's an example for an interface that uses DHCP:

DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
USERCTL=no

Here, the ifcfg file doesn't have to specify the IP address information because the interface gets that information from a DHCP server.

The following paragraphs describe the settings that you're most likely to see in this file:

  • DEVICE: The name of the device, such as eth0 or eth1.
  • USERCTL: Specifies YES or NO to indicate whether local users are allowed to start or stop the network.
  • ONBOOT: Specifies YES or NO to indicate whether the device should be enabled when Linux boots up.
  • BOOTPROTO: Specifies how the device gets its IP address. Possible values are NONE for static assignment, DHCP, or BOOTP.
  • BROADCAST: The broadcast address used to send packets to everyone on the subnet. For example: 192.168.1.255.
  • NETWORK: The network address. For example: 192.168.1.0.
  • NETMASK: The subnet mask. For example: 255.255.255.0.
  • IPADDR: The IP address for the adapter.

The Hosts file

The Hosts file is a simple list of IP addresses and the host names associated with each address. You can think of the Hosts file as a local DNS database of sorts. Whenever Linux needs to resolve a DNS name, it first looks for the name in the Hosts file. If Linux finds the name there, it doesn't have to do a DNS lookup; it simply uses the IP address found in the Hosts file.

For small networks, common practice is to list the host name for each computer on the network in the Hosts file on each computer. Then, whenever you add a new computer to the network, you just update each computer's Hosts file to include the new computer. That's not so bad if the network has just a few computers, but you wouldn't want to do it that way for a network with 1,000 hosts. That's why other name resolution systems are more popular for larger networks.

The default Linux Hosts file looks something like this:

# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost

Here, the names localhost.localdomain and localhost both resolve to 127.0.0.1, which is the standard local loopback address.

Here's an example of a Hosts file that has some additional entries:

# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 L	Server localhost.localdomain  localhost
192.168.1.1 	linksys
192.168.1.100 	ward.cleaver.com ward
192.168.1.101 	june.cleaver.com june
192.168.1.102 	wally.cleaver.com wally
192.168.1.103 	theodore.cleaver.com theodore beaver

Host names for each of the Cleaver family's four computers and their Linksys router. Each computer can be accessed by using one of two names (for example, ward.cleaver.com or just ward), except the last one, which has three names.

[Previous] [Contents] [Next]