109.2 Basic Network Configuration edit

Candidates should be able to view, change and verify configuration settings on client hosts

Key Knowledge Areas

  • Manually and automatically configure network interfaces
  • Basic TCP/IP host configuration.

The Network Interface edit

The network interface card (NIC) must be supported by the kernel. You may be able to determine which card you are using (and whether your kernel recognises it) by examining the output from dmesg, which shows the content of the kernel's message buffer:


$ dmesg | grep eth0

e1000: eth0: e1000_probe: Intel(R) PRO/1000 Network Connection

e1000: eth0: e1000_watchdog_task: NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None

eth0: no IPv6 routers present

You can probe the hardware directly with lspci:

$ lspci | grep -i ethernet

09:00.0 Ethernet controller: Marvell Technology Group Ltd. 88E8040 PCI-E Fast Ethernet Controller (rev 12)

lspci -v gives more detail. Here is the relevant part of the output:

09:00.0 Ethernet controller: Marvell Technology Group Ltd. 88E8040 PCI-E Fast Ethernet Controller (rev 12)

Subsystem: Dell Device 022e

Flags: bus master, fast devsel, latency 0, IRQ 28

Memory at f9ffc000 (64-bit, non-prefetchable) [size=16K]

I/O ports at de00 [size=256]

Capabilities: <access denied>

Kernel driver in use: sky2

Kernel modules: sky2

From the example above we see the Ethernet controller type, the memory and I/O address assignments, the IRQ in use, and the relevant kernel driver module (sky2 in this example). This information can be useful either if the wrong module is being used or if the resources (I/O or IRQ) are not available.

Occasionally, this information can either be used to insert a module with a different i/o address (using the modprobe or insmod utilities) or can be saved in /etc/modules.conf. This file is consulted by modprobe; placing entries here will save the settings for the next system boot. However, the kernel will normally auto-detect the card and load the correct module.

Name resolution

A machine must be able for perform host name resolution; that it, to translate a machine name such as neptune.example.com to an IP address such as

The file /etc/hosts is one way to perform name resolution. At minimum you will see an entry in this file for the loopback address (traditionally called localhost). The file may also contain entries for other machines, but usually only machines in the local network:

# Do not remove the following line, or various programs
# that require network functionality will fail. m1530-rhel localhost localhost.localdomain
::1 localhost6
# other hosts mesa mesa.domain.org pico

(Note also the IPV6 entry for localhost6)

Name resolution can also be performed by consulting DNS. There's more detail on this in topic 109.4: Configure client-side DNS.

The file /etc/nsswitch.conf is used to tell the resolvers in the standard C library where to look for their information. A resolver is a routine that looks up something (like a user name or a host name) and returns some corresponding information (such as the UID or the IP address). The line in nsswitch.conf that controls host name resolution looks something like this:

hosts: files dns

This entry tells the resolver to first look at the local file (/etc/hosts) then to consult DNS. Other sources for host name lookups that can be specified here include nis and nisplus

Network configuration edit

The kernel's current idea of the machine's host name is reported by the hostname command:

# hostname


The machine's host name is set in various files. On some distributions (e.g. Ubuntu) the file /etc/hostname is used. Others (e.g. RedHat) set it in /etc/sysconfig/network. The following command might help you to find out where the host name is defined on your distribution. This example is on RedHat:

# find /etc -type f -exec grep -l $(hostname) {} \;





The file /etc/sysconfig/network defines if networking must be started. On a RedHat system it also defines the host name and the default gateway. These are settings that apply to the machine as a whole (i.e. they are not specific to one network interface):


On a RedHat system the file /etc/sysconfig/network-scripts/ifcfg-eth0 contains the configuration parameters for eth0. This example shows how the file might look for an interface with a statically-assigned IP address:


For a card that's configured using DHCP the file would be simpler:


Stop and Start Networking

  • From the command line

The main tool used to bring up the network interface is /sbin/ifconfig. Once initialised, the kernel module aliased to eth0 in /etc/modules.conf (e.g tulip.o) is loaded and assigned an IP and netmask value. As a result the interface can be stopped and restarted without loosing this information as long as the kernel module is inserted.

Examples: Using ifconfig.

/sbin/ifconfig eth0 netmask

/sbin/ifconfig eth0 down

/sbin/ifconfig eth0 up

Running ifconfig with no parameters will show the current settings:

# ifconfig eth0

eth0 Link encap:Ethernet HWaddr 00:0C:29:76:13:68

inet addr: Bcast: Mask:

inet6 addr: fe80::20c:29ff:fe76:1368/64 Scope:Link


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

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

collisions:0 txqueuelen:1000

RX bytes:418797 (408.9 KiB) TX bytes:1338985 (1.2 MiB)

Base address:0x2000 Memory:d8920000-d8940000

Another tool is /sbin/ifup. This utility reads the system’s configuration files in /etc/sysconfig/ and assigns the stored values for a given interface. The script for eth0 is called ifcfg-eth0 and has to be configured. If a boot protocol such as DHCP is defined then ifup will start the interface with that protocol.

Examples: Using ifup.

/sbin/ifup eth0

/sbin/ifup ppp0

/sbin/ifdown eth0

RedHat has no man pages for ifup and ifdown (Ubuntu does!) but on RedHat they are shell scripts so you can examine the code if you wish.

  • . Using the network script

At boot time the network interfaces are initialised with the /etc/rc.d/init.d/network script. All the relevant networking files are sourced in the /etc/sysconfig/ directory. This script can also be run manually.

In addition the script also reads the sysctl options in /etc/sysctl.conf, this is where you can configure the system as a router (allow IP forwarding in the kernel). For example the line:

net.ipv4.ip_forward = 1

will enable ip forwarding. You would need to do this if the machine is being used as a gateway / router.

Using this script, networking can be started, stopped or restarted like this:

# /etc/rc.d/init.d/network start

# /etc/rc.d/init.d/network stop

# /etc/rc.d/init.d/network restart

The last command is useful if you have changed any network settings under /etc/sysconfig. Note however that this command will stop and restart all network interfaces, whereas ifconfig, ifup and ifdown can be used to start and stop individual interfaces.

RedHat also provides a "wrapper" program called service that provides a slightly easier way to run these scripts, for example:

# service network restart

Routing edit

A noticeable difference when using a system script such as ifup rather than ifconfig on its own, is that the system’s routing tables are set in one case and not in the other.

This is because either the /etc/sysconfig/network file is read, where a default gateway is stored, or the DHCP server has sent this information together with the IP number.

The routing tables are configured, checked and changed with the /sbin/route tool.

Routing examples:

Add a static route to the network through the device eth1 and use as the gateway for that network:

#/sbin/route add -net gw dev eth1

Add a default gateway:

/sbin/route add default gw eth0

Routes added in this way are only "for here and now" – they will not survive a reboot.

Listing the kernel routing table:

/sbin/route -n
► Kernel IP routing table
Destination Gateway Genmask Iface eth0 eth1 lo eth0

Here, the first entry defines the directly connected network for eth0. It says that no gateway is needed to reach the network The second entry defines a specific route to the network The last entry defines the default route. Since this rule has a Genmask of and a Destination of it always matches; however it will only be used if a more specific route (one with a longer Genmask) is not found.

If you belong to the network and you add a route to the network you may find that machines in the latter network are not responding. This may be because no route has been set from the network back to your host!! This problem is solved with dynamic routing, using the daemons gated and routed to dynamically update routing tables across a network. However, dynamic routing is not necessary on "stub networks" (where most machines are found) and it is not part of the LPI level 1 objectives.

Permanent Static Routes

Permanent static routes can be defined in the files under /etc/sysconfig. Depending on the version, RedHat takes interface-specific routes from /etc/sysconfig/network-scripts/route-eth0 (for eth0), and non-interface-specific routes from /etc/sysconfig/static-routes. These routes will be added at boot time by the network script.

Naming Networks

Using the /etc/networks file it is possible to assign names to network numbers. A typical entry might look like this:


It is then possible to use network names with tools like route, for example:

route add -net office.org netmask


Figure 109.2-1: A Routing Scenario:

The following is a partial list of the used files, terms and utilities:* /etc/hostname

  • /etc/hosts
  • /etc/resolv.conf
  • /etc/nsswitch.conf
  • ifconfig
  • ifup
  • ifdown
  • route
  • ping

Previous Chapter | Next Chapter