Modules, network interface configuration and routes

Certify and Increase Opportunity.
Be
Govt. Certified Linux Administrator

Usually, ethernet devices register themselves as being eth X, where X is the device number. The first Ether-net device is eth0, the second is eth1, and so on.

The Linux kernel supports a number of hardware drivers for various types of equipment. There is a number of standard names for interfaces in Linux. Most drivers support more than one interface, in which case the interfaces are numbered, as in eth0 and eth1.

  • lo – This is the local loopback interface. It is used for testing purposes, as well as a couple of network applications. It works like a closed circuit in that any datagram written to it will immediately be returned to the host’s networking layer. There’s always one loopback device present in the kernel, and there’s little sense in having more.
  • eth0, eth1,.. – These are the Ethernet card interfaces. They are used for most Ethernet cards, including many of the parallel port Ethernet cards.
  • tr0, tr1,.. – These are the Token Ring card interfaces. They are used for most Token Ring cards, including non-IBM manufactured cards.
  • sl0, sl1,.. – These are the SLIP interfaces. SLIP interfaces are associated with serial lines in the order in which they are allocated for SLIP.
  • ppp0, ppp1,.. – These are the PPP interfaces. Just like SLIP interfaces, a PPP interface is associated with a serial line once it is converted to PPP mode.
  • plip0, plip1,.. – These are the PLIP interfaces. PLIP transports IP datagrams over parallel lines. The interfaces are allocated by the PLIP driver at system boot time and are mapped onto parallel ports. In the 2.0.x kernels there is a direct relationship between the device name and the I/O port of the parallel port, but in later kernels the device names are allocated sequentially, just as for SLIP and PPP devices.
  • ax0, ax1,.. – These are the AX.25 interfaces. AX.25 is the primary protocol used by amateur radio operators. AX.25 interfaces are allocated and mapped in a similar fashion to SLIP devices.

There are many other types of interfaces available for other network drivers.

If the driver is configured as a module and you have auto-loading modules set up, you will need to tell the kernel the mapping between device names and the module to load in the /etc/modprobe.conf file. For example, if your eth0 device is an Intel PRO/1000 card, you would add the following line to your /etc/modprobe.conf file

alias eth0 e1000

where e1000 is the name of the device driver. You will need to set this up for every network card you have in the same system.

Device Name

For computers with multiple NICs, it is important to have fixed device names. Many configuration problems are caused by interface name changing. udev is responsible for which device gets which name.

Interfaces are now prefixed with en (ethernet), wl (WLAN), or ww (WWAN) followed by an automatically generated identifier, creating an entry such as enp0s25. This behavior may be disabled by adding net.ifnames=0 to the kernel parameters. Current NIC names can be found via sysfs or ip link. For example:

$ ls /sys/class/net

lo enp0s3

Configuration Files

The configuration files for network interfaces are located in the /etc/sysconfig/network-scripts/ directory. The scripts used to activate and deactivate these network interfaces are also located here. Although the number and type of interface files can differ from system to system, there are three categories of files that exist in this directory:

  • Interface configuration files
  • Interface control scripts
  • Network function files

The files in each of these categories work together to enable various network devices.

the primary configuration files used in network configuration. Understanding the role these files play in setting up the network stack can be helpful when customizing a Red Hat Enterprise Linux system. The primary network configuration files are as follows:

  • /etc/hosts – The main purpose of this file is to resolve host names that cannot be resolved any other way. It can also be used to resolve host names on small networks with no DNS server. Regardless of the type of network the computer is on, this file should contain a line specifying the IP address of the loopback device (127.0.0.1) as localhost.localdomain.
  • /etc/resolv.conf – This file specifies the IP addresses of DNS servers and the search domain. Unless configured to do otherwise, the network initialization scripts populate this file.
  • /etc/sysconfig/network – This file specifies routing and host information for all network interfaces. It is used to contain directives which are to have global effect and not to be interface specific.
  • /etc/sysconfig/network-scripts/ifcfg-interface-name – For each network interface, there is a corresponding interface configuration script. Each of these files provide information specific to a particular network interface.

Interface configuration files control the software interfaces for individual network devices. As the system boots, it uses these files to determine what interfaces to bring up and how to configure them. These files are usually named ifcfg-name, where name refers to the name of the device that the configuration file controls.

Ethernet Interfaces

One of the most common interface files is /etc/sysconfig/network-scripts/ifcfg-eth0, which controls the first Ethernet network interface card or NIC in the system. In a system with multiple NICs, there are multiple ifcfg-ethX files (where X is a unique number corresponding to a specific interface). Because each device has its own configuration file, an administrator can control how each interface functions individually. The following is a sample ifcfg-eth0 file for a system using a fixed IP address:

DEVICE=eth0

BOOTPROTO=none

ONBOOT=yes

NETMASK=255.255.255.0

IPADDR=10.0.1.27

USERCTL=no

The values required in an interface configuration file can change based on other values. For example, the ifcfg-eth0 file for an interface using DHCP looks different because IP information is provided by the DHCP server:

DEVICE=eth0

BOOTPROTO=dhcp

ONBOOT=yes

NetworkManager is graphical configuration tool which provides an easy way to make changes to the various network interface configuration files. However, it is also possible to manually edit the configuration files for a given network interface. Below is a listing of the configurable parameters in an Ethernet interface configuration file:

  • BONDING_OPTS=parameters – sets the configuration parameters for the bonding device, and is used in /etc/sysconfig/network-scripts/ifcfg-bondN. These parameters are identical to those used for bonding devices in /sys/class/net/bonding_device/bonding, and the module parameters for the bonding driver as described in bonding Module Directives.
  • BOOTPROTO=protocol – where protocol is one of the following:
    • none — No boot-time protocol should be used.
    • bootp — The BOOTP protocol should be used.
    • dhcp — The DHCP protocol should be used.
  • BROADCAST=address – where address is the broadcast address. This directive is deprecated, as the value is calculated automatically with ipcalc.
  • DEVICE=name – where name is the name of the physical device (except for dynamically-allocated PPP devices where it is the logical name).
  • DHCP_HOSTNAME=name – where name is a short host name to be sent to the DHCP server. Use this option only if the DHCP server requires the client to specify a host name before receiving an IP address.
  • DNS{1,2}=address – where address is a name server address to be placed in /etc/resolv.conf provided that the PEERDNS directive is not set to no.
  • ETHTOOL_OPTS=options – where options are any device-specific options supported by ethtool. For example, if you wanted to force 100Mb, full duplex: ETHTOOL_OPTS=”autoneg off speed 100 duplex full”. Instead of a custom initscript, use ETHTOOL_OPTS to set the interface speed and duplex settings. Custom initscripts run outside of the network init script lead to unpredictable results during a post-boot network service restart.
  • HOTPLUG=answer – where answer is one of the following:
    • yes — This device should be activated when it is hot-plugged (this is the default option).
    • no — This device should not be activated when it is hot-plugged.

The HOTPLUG=no option can be used to prevent a channel bonding interface from being activated when a bonding kernel module is loaded.

  • HWADDR=MAC-address – where MAC-address is the hardware address of the Ethernet device in the form AA:BB:CC:DD:EE:FF. This directive must be used in machines containing more than one NIC to ensure that the interfaces are assigned the correct device names regardless of the configured load order for each NIC’s module. This directive should not be used in conjunction with MACADDR.
  • IPADDR=address – where address is the IPv4 address.
  • IPV6ADDR=address – where address is the first static, or primary, IPv6 address on an interface. The format is Address/Prefix-length. If no prefix length is specified, /64 is assumed. Note that this setting depends on IPV6INIT being enabled.
  • IPV6_AUTOCONF=answer where answer is one of the following:

yes — Enable IPv6 autoconf configuration for this interface.

no — Disable IPv6 autoconf configuration for this interface.

If enabled, an IPv6 address will be requested using Neighbor Discovery (ND) from a router running the radvd daemon.

  • MACADDR=MAC-address – where MAC-address is the hardware address of the Ethernet device in the form AA:BB:CC:DD:EE:FF. This directive is used to assign a MAC address to an interface, overriding the one assigned to the physical NIC. This directive should not be used in conjunction with the HWADDR directive.
  • MASTER=bond-interface – where bond-interface is the channel bonding interface to which the Ethernet interface is linked. This directive is used in conjunction with the SLAVE directive.
  • NETMASK=mask – where mask is the netmask value.
  • NETWORK=address – where address is the network address. This directive is deprecated, as the value is calculated automatically with ipcalc.

Manual Configuration

You can use one of the above tools or configure the network the old fashioned way as follows:

  • First to use networking on any permanent basis you should setup the file /etc/sysconfig/network similar to the example shown below.
  • Assign an ip address with “ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up”.
  • Tell your machine that a hub is ready for information with the command “route add -net 192.168.0.0 netmask 255.255.255.0 eth0”
  • To contact hosts outside your network if a machine with IP address 192.168.1.1 is the gateway use the command “route add default gw 192.168.1.1 eth0”
  • If using a dialup connection use the command “route add default ppp0” The word default says if the packet is not for a machine on your local network, send it to the default device.

These settings are not permanent, but go away the next time you boot. They are normally set up in the directory /etc/sysconfig/network-scripts. Add the network interface to the file /etc/sysconfig/network-scripts/ifcfg-eth*. For example the file ifcfg-eth0 if for the first ethernet interface, ifcfg-eth1 for the second, ifcfg-lo is for the local interface. An example file from my system is:

DEVICE=”eth0″

IPADDR=”192.168.1.100″

NETMASK=”255.255.0.0″

ONBOOT=”yes”

BOOTPROTO=”none”

IPXNETNUM_802_2=””

IPXPRIMARY_802_2=”no”

IPXACTIVE_802_2=”no”

IPXNETNUM_802_3=””

IPXPRIMARY_802_3=”no”

IPXACTIVE_802_3=”no”

IPXNETNUM_ETHERII=””

IPXPRIMARY_ETHERII=”no”

IPXACTIVE_ETHERII=”no”

IPXNETNUM_SNAP=””

IPXPRIMARY_SNAP=”no”

IPXACTIVE_SNAP=”no”

Unless you know what you’re doing it is best to use a network configuration tool. I cannot guarantee the accurateness of how to set these files up on your system.

hostname

A hostname is a unique name created to identify a machine on a network: it is configured in /etc/hostname. The file can contain the system’s domain name, if any. To set the hostname, do:

# hostnamectl set-hostname myhostname

This will put myhostname into /etc/hostname. It is recommended to also set the hostname in /etc/hosts:

/etc/hosts

# /etc/hosts: static lookup table for host names

#<ip-address>  <hostname.domain.org>          <hostname>

127.0.0.1         localhost.localdomain  localhost          myhostname

::1                    localhost.localdomain  localhost          myhostname

To temporarily set the hostname (until reboot), use hostname from inetutils – # hostname myhostname

Configuration Tools

There are many network configuration tools today. They are:

Tool Details
netconf A GUI interactive interface available
linuxconf A GUI interactive interface available which includes netconf configuration.
netconfig A GUI step by step interface
ifconfig A text based program to configure the network interface. Type “man ifconfig” for info.

These programs will modify values in the following files:

  • /etc/sysconfig/network – Defines your network and some of its characteristics.
  • /etc/HOSTNAME – Shows the host name of this host. IF your name is “myhost” then that is exactly the text this file will contain.
  • /etc/resolv.conf – Specifies the domain to be searched for host names to connect to, the nameserver address, and the search order for the nameservers.
  • /etc/host.conf – Specifies the order nameservice looks to resolve names.
  • /etc/hosts – Shows addresses and names of local hosts.
  • /etc/networks – Provides a database of network names with network addresses similar to the /etc/hosts file. This file is not required for operation.
  • /etc/sysconfig/network-scripts/ifcfg-eth* – There is a file for each network interface. This file contains the IP address of the interface and many other setup variables.

Analysis Tools

  • netstat – Displays information about the systems network connections, including port connections, routing tables, and more. The command “netstar -r” will display the routing table.
  • traceroute – This command can be used to determine the network route from your computer to some other computer on your network or the internet. To use it you can type “route IPaddress” of the computer you want to see the route to.
  • nslookup – Used to query DNS servers for information about hosts.
  • arp – This program lets the user read or modify their arp cache.
  • tcpdump – This program allows the user to see TCP traffic on their network.

ifconfig

ifconfig in short “interface configuration” utility for system/network administration in Unix/Linux operating systems to configure, manage and query network interface parameters via command line interface or in a system configuration scripts.

The “ifconfig” command is used for displaying current network configuration information, setting up an ip address, netmask or broadcast address to an network interface, creating an alias for network interface, setting up hardware address and enable or disable network interfaces.

Running the ifconfig command with no arguments – ifconfig, will display information about all network interfaces currently in operation.

Options

Option Detail
-a Display information for all network interfaces, even if they are down.
-s Display a short list in a format identical to the command “netstat -i”.
-v Verbose mode; display additional information for certain error conditions.
interface The name of the interface. This is usually a driver name followed by a unit number, for example “eth0” for the first Ethernet interface. If your kernel supports alias interfaces, you can specify them with eth0:0 for the first alias of eth0. You can use them to assign a second address. To delete an alias interface use ifconfig eth0:0 down. Note: for every scope (i.e. same net with address/netmask combination) all aliases are deleted, if you delete the first (primary).
up This flag causes the interface to be activated. It is implicitly specified if an address is assigned to the interface.
down This flag causes the driver for this interface to be shut down.
[-]arp Enable (or disable, if the “-” prefix is specified) the use of the ARP protocol on this interface.
[-]promisc Enable (or disable, if the “-” prefix is specified) the promiscuous mode of the interface. If promiscuous mode is enabled, all packets on the network will be received by the interface.
[-]allmulti Enable or disable all-multicast mode. If multicast mode is enabled, all multicast packets on the network will be received by the interface.
metric N This parameter sets the interface metric, which is used by the interface to make routing decisions. N must be an integer between 0 and 4294967295. If you’re not sure what a network metric is, or whether you should change it, you can safely leave this setting alone.
mtu N This parameter sets the Maximum Transfer Unit (MTU) of an interface. This setting is used to limit the maximum packet size transferred by the interface. If you’re not sure about it, you can safely leave this setting alone.
dstaddr address Set the remote IP address for a point-to-point link (such as PPP). This keyword is now obsolete; use the pointopoint keyword instead.
netmask address Set the IP network mask for this interface. This value defaults to the usual class A, B or C network mask (as derived from the interface IP address), but it can be set to any value.
add address/prefixlen Add an IPv6 address to an interface.
del address/prefixlen Remove an IPv6 address from an interface.
tunnel aa.bb.cc.dd Create a new SIT (IPv6-in-IPv4) device, tunnelling to the given destination.
irq address Set the interrupt line used by this device. Not all devices can dynamically change their IRQ setting.
io_addr address Set the start address in I/O space for this device.
mem_start address Set the start address for shared memory used by this device. Only a few devices need this.
media type Set the physical port or medium type to be used by the device. Not all devices can change this setting, and those that can vary in what values they support. Typical values for type are 10base2 (thin Ethernet), 10baseT (twisted-pair 10Mbps Ethernet), AUI (external transceiver) and so on. The special medium type of auto can be used to tell the driver to auto-sense the media. Again, not all drivers can do this.
[-]broadcast [address] If the address argument is given, this will set the protocol broadcast address for this interface. Otherwise, it will set (or clear, if the “-” prefix is used) the IFF_BROADCAST flag for the interface.
[-]pointopoint [address] This keyword enables the point-to-point mode of an interface, meaning that it is a direct link between two machines with nobody else listening on it. If the address argument is also given, set the protocol address of the other side of the link, just like the obsolete dstaddr keyword does. Otherwise, set or clear the IFF_POINTOPOINT flag for the interface.
hw class address Set the hardware address of this interface, if the device driver supports this operation. The keyword must be followed by the name of the hardware class and the printable ASCII equivalent of the hardware address. Hardware classes currently supported include ether (Ethernet), ax25 (AMPR AX.25), ARCnet and netrom (AMPR NET/ROM).
multicast Set the multicast flag on the interface. This should not normally be needed as the drivers set the flag correctly themselves.
address The IP address to be assigned to this interface.
txqueuelen length Set the length of the transmit queue of the device. It is useful to set this to small values for slower devices with a high latency (such as a connection over a modem, or over ISDN) to prevent fast bulk transfers from disturbing interactive traffic like telnet too much.

Multiple IP Addresses

If you want to configure your network card to act as more than one IP address, issue the following command:

ifconfig dummy 192.168.1.102 netmask 255.255.255.0

This uses the dummy system interface capability supported in the kernel to setup another virtual interface which operates at IP address 192.168.1.102. Substitute the IP address that you want your virtual interface to be with an appropriate netmask for your network. To disable this, issue the following command.

ifconfig dummy down

Another way to use multiple IP addresses on one ethernet card is to set up a new file in your /etc/sysconfig/network-scripts directory. Copy your ifcfg-eth0 role to ifcfg-eth0:0. Edit that file and rename the device to “eth0:0” and the IP address to the desired IP address. You may also want to modify BROADCAST, NETWORK, or NETMASK. You can continue adding IP addresses by using :1, :2, etc such as ifcfg-eth0:2.

To make it effective, you must reboot your system or issue the command “/etc/rc.d/init.d/network restart” as root.

Routing

Routing table information is used to route incoming and outgoing network diagrams to other machines. On most simple configurations, there are three routes. One for sending packets to your own machine, one for sending packets to other machines on your network and one for sending packets to other machines outside your network through the gateway. Two programs (ifconfig and route) are used to configure these parameters.

In Linux, the “ifconfig” command is used to configure the NIC and the command “route” is used to set up routing tables for that machine. Changes made with “route” without adding the changes to permanent files will no longer be valid when you reboot the machine. The command “ifconfig eth0 192.168.2.2 netmask 255.255.255.0” will set the NIC card up with its address and network number. You can type “netconfig”, then select “basic host information” and do the same thing. The command “route add -net default gw 192.168.2.1 dev eth0” will add the route required for this computer for its gateway. This can be done using “ifconf” by selecting “routing and gateways” and “defaults”, then setting the address of the default gateway, and enabling routing. Please be aware that various versions of Linux have different means of storing and retrieving network and routing information and you must use the tools that come with your system or learn it well enough to determine what files to modify. On some versions the file “/etc/sysconfig/static-routes” can be modified to make your route changes permanent, but this does not apply to your default route. Other files are “/etc/sysconfig/routed” and “/etc/sysconfig/network”. Other files include “/etc/gateways”, “/etc/networks”, “/proc/net/route”, “/proc/net/rt_cache”, and “/proc/net/ipv6_route”. The file “/etc/sysconfig/network-scripts” is a script file that controls the network setup when the system is booted.

If you type “route” for this machine, the routing table below will be displayed:

Destination      Gateway           Genmask         Flags    Metric  Ref       Use      Iface

192.168.2.2     *          255.255.255.255         UH      0          0          0          eth0

192.168.2.0     *          255.255.255.0 U         0          0          0          eth0

127.0.0.0         *          255.0.0.0         U         0          0          0          lo

default  192.168.2.1     0.0.0.0 UG      0          0          0          eth0

All computers that are networked have a routing table in one form or another. A routing table is a simple set of rules that tell what will be done with network packets. In programming language it is easiest to think of it as a set of instructions, very similar to a case statement which has a “default” at its end. If can also be thought of as a series of if..then..elseif..then..else statements. If the lines above are labeled A through C and a default (the last line), an appropriate case statement is: (Don’t count the header line)

switch(address){

case A: send to me;break;

case B: send to my network;break;

case C: send to my local interface;break;

default: send to gateway 192.168.2.1

An appropriate if statement is:

if (address=me) then send to me;

elseif (address=my network) then send to my network;

elseif (address=my local) then send to my local interface;

else send to my gateway 192.168.2.1;

In everyday terms this is similar to a basic decision process. Imagine you are holding a letter. If it is addressed to you, you keep it, if it is addressed to someone in your town, you drop it in the local slot at the post office, but if it is addressed to someone out of town, you would drop it in the out of town slot.

The routing table is arranged from the most specific to the least specific. Therefore as you go down the table, more possibilities are covered. You will notice the first Genmask is 255.255.255.255 and the last is 0.0.0.0. There can be no doubt that the last line is the default. The genmasks between the start and the end have a decreasing number of least significant bits set.

The above default routing table may be added manually with the command:

route add -net default gw 192.168.2.1 dev eth0

The routing table for machine a gateway for the network 192.168.2.0 to be routed to network 192.168.1.0 is as follows. The network card addresses are 192.168.2.1 and 192.168.1.2.

Destination      Gateway           Genmask         Flags    Metric  Ref       Use      Iface

192.168.2.1     *          255.255.255.255         UH      0          0          0          eth0

192.168.1.2     *          255.255.255.255         UH      0          0          0          eth1

192.168.2.0     192.168.2.1     255.255.255.0 UG      0          0          0          eth0

192.168.2.0     *          255.255.255.0 U         0          0          0          eth0

192.168.1.0     192.168.1.2     255.255.255.0 UG      0          0          0          eth1

192.168.1.0     *          255.255.255.0 U         0          0          0          eth1

127.0.0.0         *          255.0.0.0         U         0          0          0          lo

default  192.168.1.1     0.0.0.0 UG      0          0          0          eth0

The Iface specifies the card where packets for this route will be sent. The address of eth1 is 192.168.1.2 and eth0 is 192.168.2.1. The NIC card addresses could have easily been switched. Line 1 (above) provides for the eth0 address, while line 2 provides for the address of eth1. Lines 3 and 4 are the rules for traffic going from network 192.168.1.0 to network 192.168.2.0 which will be sent out on NIC eth0. Lines 5 and 6 are the rules for traffic going from network 192.168.2.0 to network 192.168.1.0 which will be sent out NIC eth1. This may seem confusing, but please note the first value on lines 3 and 4 is 192.168.2.0 which the header indicates as the destination of the packet. Don’t think of it as source! The last line is the default line which specifies that any packet not on one of the networks 192.168.1.0 or 192.168.2.0 will be sent to the gateway 192.168.1.1. This is how the internet access can be attained, though IP masquerading will probably be used. The flags above mean the following:

U – Route is up

H – Target is a host

G – Use gateway

There are other flags, you can look up by typing “man route”. Also the metric value above, indicating the distance to the target, is not used by current Linux kernels but may be needed by some routing daemons. Please note that if route knows the name of the gateway machine, it may list its name rather than the IP address. The same is true for defined networks. Networks may be defined in the file “/etc/networks” as in the example:

net1 192.168.1.0

net2 192.168.2.0

The routing table above can be set up with the following commands.

route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.2.1 dev eth0

route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.2 dev eth1

Again be aware that you are specifying destination networks here and the ethernet device and address the data is to be sent on. In some versions of Linux this can be specified using “netconf” by selecting “routing and gateways” and “other routes to networks” and entering the following

Network          Netmask          Gateway

192.168.2.0     255.255.255.0 192.168.2.1

192.168.1.0     255.255.255.0 192.168.1.2

Alternatively in Redhat Linux, you can add the following two lines to the file “/etc/sysconfig/static-routes”:

eth0 net 192.168.2.0 netmask 255.255.255.0 gw 192.168.2.1

eth1 net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.2

The commands to delete the above routes with route are:

route del -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.2.1 dev eth0 route del -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.2 dev eth1

Be aware, the program route is very particular on how the commands are entered. Even though it may seem that you entered them as the man page specifies, it will not always accept the commands. I don’t know if this is a bug or not, but if you enter them as described here with the network, netmask, gateway, and device specified, it should work. The slightest misnomer in network name, netmask, gateway, device, or command syntax and the effort will fail.

Dynamic Routing

It is done by routed. To run the routed daemon, all you need to do is to start routed. There is no configuration file. Routed will listen for RIP updates on the network and use them to build a routing table. RIP is not a good routing choice for very large networks but is easy to administer and works well for small networks.

The /etc/gateways file allows static routes to be added to the routed daemon so that routes associated with routers that can’t provide updates to routing tables are manually provided for. The format of the file is as follows:

startkeyword destinationaddress gateway gwaddress metric value active/passive

  • The startkeyword is one of – net – A route to a network or host – A route to a host
  • The destination address tells where the packet. If the destination is 0.0.0.0, then that is the default route
  • The gateway defines the external gateway used to reach the destination, with the gwaddress specifying the IP address of the gateway.
  • Metric is a required keyword and the metric value is the cost (in hops) to the destination.
  • The active/passive value indicates whether a router performs routing updates. Active indicates it does.

An example follows:

net 0.0.0.0 gateway 10.11.199.1 metric 1 active net 192.168.198.0 gateway 10.11.199.20 metric 1 active

Static Routing

Routing will be configured on routing devices, therefore it should not be necessary to configure static routes on Red Hat Enterprise Linux servers or clients. However, if static routes are required they can be configured for each interface. This can be useful if you have multiple interfaces in different subnets. Use the route command to display the IP routing table.

Static route configuration is stored in a /etc/sysconfig/network-scripts/route-interface file. For example, static routes for the eth0 interface would be stored in the /etc/sysconfig/network-scripts/route-eth0 file. The route-interface file has two formats: IP command arguments and network/netmask directives.

IP Command Arguments Format – Define a default gateway on the first line. This is only required if the default gateway is not set via DHCP:

default X.X.X.X dev interface

X.X.X.X is the IP address of the default gateway. The interface is the interface that is connected to, or can reach, the default gateway.

Define a static route. Each line is parsed as an individual route:

X.X.X.X/X via X.X.X.X dev interface

X.X.X.X/X is the network number and netmask for the static route. X.X.X.X and interface are the IP address and interface for the default gateway respectively. The X.X.X.X address does not have to be the default gateway IP address. In most cases, X.X.X.X will be an IP address in a different subnet, and interface will be the interface that is connected to, or can reach, that subnet. Add as many static routes as required.

The following is a sample route-eth0 file using the IP command arguments format. The default gateway is 192.168.0.1, interface eth0. The two static routes are for the 10.10.10.0/24 and 172.16.1.0/24 networks:

default 192.168.0.1 dev eth0

10.10.10.0/24 via 192.168.0.1 dev eth0

172.16.1.0/24 via 192.168.0.1 dev eth0

Static routes should only be configured for other subnets. The above example is not necessary, since packets going to the 10.10.10.0/24 and 172.16.1.0/24 networks will use the default gateway anyway. Below is an example of setting static routes to a different subnet, on a machine in a 192.168.0.0/24 subnet. The example machine has an eth0 interface in the 192.168.0.0/24 subnet, and an eth1 interface (10.10.10.1) in the 10.10.10.0/24 subnet:

10.10.10.0/24 via 10.10.10.1 dev eth1

Network/Netmask Directives Format – You can also use the network/netmask directives format for route-interface files. The following is a template for the network/netmask format, with instructions following afterwards:

ADDRESS0=X.X.X.X

NETMASK0=X.X.X.X

GATEWAY0=X.X.X.X

  • ADDRESS0=X.X.X.X is the network number for the static route.
  • NETMASK0=X.X.X.X is the netmask for the network number defined with ADDRESS0=X.X.X.X.
  • GATEWAY0=X.X.X.X is the default gateway, or an IP address that can be used to reach ADDRESS0=X.X.X.X

The following is a sample route-eth0 file using the network/netmask directives format. The default gateway is 192.168.0.1, interface eth0. The two static routes are for the 10.10.10.0/24 and 172.16.1.0/24 networks. However, as mentioned before, this example is not necessary as the 10.10.10.0/24 and 172.16.1.0/24 networks would use the default gateway anyway:

ADDRESS0=10.10.10.0

NETMASK0=255.255.255.0

GATEWAY0=192.168.0.1

ADDRESS1=172.16.1.0

NETMASK1=255.255.255.0

GATEWAY1=192.168.0.1

Subsequent static routes must be numbered sequentially, and must not skip any values. For example, ADDRESS0, ADDRESS1, ADDRESS2, and so on.

Below is an example of setting static routes to a different subnet, on a machine in the 192.168.0.0/24 subnet. The example machine has an eth0 interface in the 192.168.0.0/24 subnet, and an eth1 interface (10.10.10.1) in the 10.10.10.0/24 subnet:

ADDRESS0=10.10.10.0

NETMASK0=255.255.255.0

GATEWAY0=10.10.10.1

DHCP should assign these settings automatically, therefore it should not be necessary to configure static routes on Linux servers or clients.

Check the connection

The basic installation procedure typically has a functional network configuration. Use ping to check the connection:

$ ping www.google.com

PING www.l.google.com (74.125.132.105) 56(84) bytes of data.

64 bytes from wb-in-f105.1e100.net (74.125.132.105): icmp_req=1 ttl=50 time=17.0 ms

If the ping is successful (you see 64 bytes messages as above), then the network is configured. Press Control-C to stop the ping. If the ping failed with an Unknown hosts error, it means that your machine was unable to resolve this domain name. It may be related to your service provider or your router/gateway. Try pinging a static IP address to prove that your machine has access to the Internet:

$ ping 8.8.8.8

PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.

64 bytes from 8.8.8.8: icmp_req=1 ttl=53 time=52.9 ms

If you are able to ping 8.8.8.8 but not www.google.com, check your DNS configuration. The hosts line in /etc/nsswitch.conf is another place you can check. If not, check for cable issues before diagnosing further.

Back to Tutorial

Apply for Linux Administration Certification Now!!

http://www.vskills.in/certification/Certified-Linux-Administrator

Share this post
[social_warfare]
TCP/IP & IPv6
Netfilter

Get industry recognized certification – Contact us

keyboard_arrow_up