# 109.2 Basic Network Configuration

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

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:
Example:
* $ 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 144.11.20.101
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.
* 127.0.0.1 m1530-rhel localhost localhost.localdomain
* ::1 localhost6
* # other hosts
* 192.168.1.108 mesa mesa.domain.org
* 192.168.1.119 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

The kernel's current idea of the machine's host name is reported by the hostname command:
* # hostname
* m1530-rhel.example.com
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) \;
* /etc/sysconfig/network-scripts/ifcfg-eth0
* /etc/sysconfig/network
* /etc/hosts
* /etc/dhclient-eth0.conf
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):
* NETWORKING=yes
* HOSTNAME=mesa.domain.org
* GATEWAY=192.168.1.254
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:
* DEVICE=eth0
* BOOTPROTO=static
* BROADCAST=192.168.1.255
* IPADDR=192.168.1.108
* NETMASK=255.255.255.0
* ONBOOT=yes
For a card that's configured using DHCP the file would be simpler:
* DEVICE=eth0
* BOOTPROTO=dhcp
* ONBOOT=yes
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 192.168.10.1 netmask 255.255.128.0
* /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:192.168.81.130 Bcast:192.168.81.255 Mask:255.255.255.0
* inet6 addr: fe80::20c:29ff:fe76:1368/64 Scope:Link
* UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
* 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

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 10.0.0.0 through the device eth1 and use 192.168.1.108 as the gateway for that network:
* #/sbin/route add -net 10.0.0.0 gw 192.168.1.108 dev eth1
Add a default gateway:
* /sbin/route add default gw 192.168.1.1 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
* 192.168.1.0 0.0.0.0 255.255.255.0 eth0
* 10.1.8.0 192.168.1.108 255.0.0.0 eth1
* 127.0.0.0 0.0.0.0 255.0.0.0 lo
* 0.0.0.0 192.168.1.254 0.0.0.0 eth0
Here, the first entry defines the directly connected network for eth0. It says that no gateway is needed to reach the network 192.168.1.0 The second entry defines a specific route to the network 10.1.8.0. The last entry defines the default route. Since this rule has a Genmask of 0.0.0.0 and a Destination of 0.0.0.0 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 192.168.10.0 network and you add a route to the 192.168.1.0 network you may find that machines in the latter network are not responding. This may be because no route has been set from the 192.168.1.0 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:
office 192.168.3.0
It is then possible to use network names with tools like route, for example:
* route add -net office.org netmask 255.0.0.0
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