Ict-innovation/LPI/109.2

= 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:

You can probe the hardware directly with lspci:

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

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:

(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:

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:

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.

Running ifconfig with no parameters will show the current settings:

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.

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:

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:

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:

Add a default gateway:

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

Listing the kernel routing table:

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:



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