Linux: Setup static routes
Jump to navigation
Jump to search
Force traffic out on eth1 instead of eth0 (def gw), even though IP of system i'm accessing out on eth1 falls within the eth0 subnet
- Route tables before
[root@mgmt001 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.31.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
172.31.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 ib0
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
192.168.0.0 0.0.0.0 255.255.0.0 U 0 0 0 ib0
239.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 ib0
0.0.0.0 172.31.4.1 0.0.0.0 UG 0 0 0 eth0
- Add static route
route add -net 172.31.3.0 netmask 255.255.255.0 dev eth1- Route tables afterwards
[root@mgmt001 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.31.3.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 ###########################
172.31.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
172.31.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 ib0
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
192.168.0.0 0.0.0.0 255.255.0.0 U 0 0 0 ib0
239.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 ib0
0.0.0.0 172.31.4.1 0.0.0.0 UG 0 0 0 eth0- Add a default gateway
route add default gw 192.168.1.254 eth0- Add a route to another network (e.g. rocks headnode to access ipmi modules from local host)
david@lt-david:~$ sudo route add -net 172.16.0.0 netmask 255.255.0.0 gw 172.16.1.1
david@lt-david:~$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.3 0.0.0.0 UG 0 0 0 wlan0
10.0.0.0 0.0.0.0 255.0.0.0 U 2 0 0 wlan0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 wlan0
172.16.0.0 172.16.1.1 255.255.0.0 UG 0 0 0 wlan0
172.16.0.0 0.0.0.0 255.255.0.0 U 0 0 0 wlan0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0