8i | 9i | 10g | 11g | 12c | 13c | 18c | 19c | 21c | 23c | Misc | PL/SQL | SQL | RAC | WebLogic | Linux

Home » Articles » Linux » Here

Routing IP Traffic on Linux

Most of the time routing will be done by your network hardware, but it can be done using Linux.

This article provides an introduction to routing IP traffic on Linux, with specific reference to the information needed for the RHCE EX300 certification exam.

Remember, the exams are hands-on, so it doesn't matter which method you use to achieve the result, so long as the end product is correct.

Related articles.

Route IP Traffic

Routes are dynamically managed using the route or ip route commands.

A default routes can be managed as follows.

# route del default gw 192.168.0.1
# route add default gw 192.168.0.1

# ip route del default via 192.168.0.1
# ip route add default via 192.168.0.1

Specific routes can be added, with or without a default gateway setting, using the following commands.

# route add -net 172.168.2.0 netmask 255.255.255.0 dev eth0
# route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.0.1 dev eth0

# ip route add 172.168.3.0/24 dev eth0
# ip route add 172.168.4.0/24 via 192.168.0.1 dev eth0

Route information is be displayed as follows.

# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.0.1     0.0.0.0         UG    0      0        0 eth0
link-local      *               255.255.0.0     U     1002   0        0 eth0
172.168.2.0     *               255.255.255.0   U     0      0        0 eth0
172.168.3.0     *               255.255.255.0   U     0      0        0 eth0
172.168.4.0     192.168.0.1     255.255.255.0   UG    0      0        0 eth0
192.168.0.0     *               255.255.255.0   U     0      0        0 eth0
192.168.1.0     192.168.0.1     255.255.255.0   UG    0      0        0 eth0
#

# ip route
default via 192.168.0.1 dev eth0  proto static 
169.254.0.0/16 dev eth0  scope link  metric 1002 
172.168.2.0/24 dev eth0  scope link 
172.168.3.0/24 dev eth0  scope link 
172.168.4.0/24 via 192.168.0.1 dev eth0 
192.168.0.0/24 dev eth0  proto kernel  scope link  src 192.168.0.190 
192.168.1.0/24 via 192.168.0.1 dev eth0
#

Routes are removed using the following commands.

# route del -net 172.168.2.0 netmask 255.255.255.0 dev eth0
# route del -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.0.1 dev eth0

# ip route del 172.168.4.0/24 via 192.168.0.1 dev eth0
# ip route del 172.168.3.0/24 dev eth0

Create Permanent Static Routes

The static routes configured in the previous section are all transient, in that they are lost on reboot. To configure a permanent static route for an interface, create a file with the following format "/etc/sysconfig/network-scripts/route-<INTERFACE>". For example, we could create the "/etc/sysconfig/network-scripts/route-eth0" file with the following entries.

172.168.2.0/24 via 192.168.0.1 dev eth0
172.168.4.0/24 via 192.168.0.1 dev eth0

We can then stop and start the interface as follows.

# cd /etc/sysconfig/network-scripts/
# ifdown eth0
# ifup eth0

In addition, the default gateway can be specified globally in the "/etc/sysconfig/network" file, for the interface in the "/etc/sysconfig/network-scripts/ifcfg-<INTERFACE>".

For more information see:

Hope this helps. Regards Tim...

Back to the Top.