Jul 222008
 

Many of the core Fedora / Redhat commands and configuration files covered in this chapter can be used in Debian based operating systems, but there are some key differences.

The /etc/network/interfaces File

The main network configuration file is the /etc/network/interfaces file in which all the network interface parameters are defined. The file is divided into stanzas:

The auto Stanza

The auto stanza defines the interfaces that should be automatically initialized when the system boots up.

The mapping Stanza

This stanza maps configuration parameters for an interface depending on the output of a script. For example, on booting the script could prompt you as to whether your laptop Linux system is at home or work with the mapping statement using the answer to configure the appropriate IP address.

By default the much simpler hotplug system is used which assumes that the interfaces will have only one purpose. Typical hotplug configurations simply assign each physical interface with a matching logical interface name (nick name).

mapping hotplug
        script grep
        map eth0 eth0
        map eth1

In this case interface eth0 is specifically given the logical name eth0, while the logical name for eth1 is implied to be the same.

The iface Stanza

The iface stanza defines the characteristics of a logical interface. Typically the first line of these stanzas starts with the word iface, followed by the logical name of the interface, the protocol used, and finally the type of addressing scheme to be used, such as DHCP or static. Protocol keywords include inet for regular TCP/IP, inet6 for IPv6, ipx for the older IPX protocol used by Novell, and loopback for loopback addresses.

Subsequent lines in the stanza define protocol characteristics such as addresses, subnet masks, and default gateways. In this example, interface eth1 is given the IP address 216.10.119.240/27 while interface eth0 gets its IP address using DHCP.

# The primary network interface
auto eth1
iface eth1 inet static
        address 216.10.119.240
        netmask 255.255.255.224
        network 216.10.119.224
        broadcast 216.10.119.255
        gateway 216.10.119.241
        dns-nameservers 216.10.119.241

# The secondary network interface
auto eth0
iface eth0 inet dhcp

Note: When static IP addresses are used, a default gateway usually needs to be defined. Remember to place the gateway statement in the correct stanza with the appropriate router IP address.

Creating Interface Aliases

IP aliases can be easily created in the /etc/network/interfaces file once the main interface has already been defined. A modified duplicate of the main interfaces’ iface stanza is required. A colon followed by the sub interface number needs to be added to the first line, and only the subnet mask and the new IP address needs to follow as can be seen in this example for interface eth1:1 with the IP address 216.10.119.239.

auto eth1:1
iface eth1:1 inet static
       address 216.10.119.239
       netmask 255.255.255.224

Adding Permanent Static Routes

The up option in the appropriate iface stanza of the /etc/network/interfaces file allows you to selectively run commands once the specified interface becomes activated with the ifup command. This makes it useful when adding permanent static routes.

In this example, a route to the 10.0.0.0/8 network via router address 216.10.119.225 has been added. Remember, the up option and the command must reside on the same line of the stanza.

# The primary network interface
auto eth1
iface eth1 inet static
        ...
        ...
        ...
        up route add -net 10.0.0.0 netmask 255.0.0.0 gw 216.10.119.225 eth1

A complete /etc/network/interfaces file

We can now construct a complete file based on the previous examples we discussed. Just like in Fedora, interfaces can be activated with the ifup and ifdown commands.

#
# Debian / Ubuntu
#

#
# File: /etc/network/interfaces
#

# The loopback network interface
auto lo
iface lo inet loopback

# This is a list of hotpluggable network interfaces.
# They will be activated automatically by the hotplug subsystem.
mapping hotplug
        script grep
        map eth0 eth0
        map eth1 eth1

# The primary network interface
auto eth1
iface eth1 inet static
        address 216.10.119.240
        netmask 255.255.255.224
        network 216.10.119.224
        broadcast 216.10.119.255
        gateway 216.10.119.241
        # dns-* options are implemented by the resolvconf package, if installed
        dns-nameservers 216.10.119.241
        wireless-key 98d126d5ac
        wireless-essid schaaffe

        up route add -net 10.0.0.0 netmask 255.0.0.0 gw 216.10.119.225 eth1

auto eth1:1
iface eth1:1 inet static
        address 216.10.119.239
        netmask 255.255.255.224

# The secondary network interface
auto eth0
iface eth0 inet dhcp

For more information on the /etc/network/interfaces file just issue the command man interfaces from the command line.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.