Difference between revisions of "Linux: Setup static routes"
Jump to navigation
Jump to search
| (3 intermediate revisions by the same user not shown) | |||
| Line 19: | Line 19: | ||
## or on a Mac | ## or on a Mac | ||
| − | |||
Jons-MacBook-Air:~ root# netstat -r | Jons-MacBook-Air:~ root# netstat -r | ||
Routing tables | Routing tables | ||
| Line 80: | Line 79: | ||
* Add a route to another network (e.g. rocks headnode to access ipmi modules from local host) | * Add a route to another network (e.g. rocks headnode to access ipmi modules from local host) | ||
<syntaxhighlight> | <syntaxhighlight> | ||
| − | route add -net 172.16.0.0 netmask 255.255.0.0 gw | + | route add -net 172.16.0.0 netmask 255.255.0.0 gw 10.16.1.1 |
## or on a Mac | ## or on a Mac | ||
| − | sudo route -n add -net 172.16.0.0/16 172.16.1.1 | + | sudo route -n add -net 172.16.0.0/16 10.16.1.1 |
| + | |||
| + | ## or on Windows | ||
| + | route add 172.16.0.0 mask 255.255.0.0 10.16.1.1 | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | == Delete a static route == | ||
| + | <syntaxhighlight> | ||
| + | ## or on a Mac | ||
| + | sudo route -n delete 172.16.0.0/16 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 12:30, 20 February 2015
Using the route command
Couple of examples using route
Route out eth1
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
## or on a Mac
Jons-MacBook-Air:~ root# netstat -r
Routing tables
Internet:
Destination Gateway Flags Refs Use Netif Expire
default 10.0.0.3 UGSc 68 0 en0
10 link#5 UCS 15 0 en0
10.0.0.1 2:1b:21:1e:2:fc UHLWIi 5 203 en0 1199
10.0.0.3 0:30:48:8d:f7:bb UHLWIi 66 23 en0 1196
10.0.0.5 0:30:48:c2:ab:9e UHLWIi 0 153 en0 623
10.0.0.21 0:25:90:37:7f:9e UHLWIi 0 0 en0 823
10.0.0.24 0:25:90:37:7f:9e UHLWIi 1 24 en0 1123
10.0.0.25 0:25:90:37:7f:9e UHLWIi 0 126 en0 1100
10.0.0.220 0:30:48:74:44:78 UHLWIi 0 2 en0 1175
10.0.2.15 68:a8:6d:29:36:cc UHLWIi 0 1 en0 1087
node1 7c:c5:37:25:59:fb UHLWIi 2 123 en0 694
10.0.2.23 localhost UHS 0 0 lo0
10.0.2.28 4c:f:6e:d3:58:a2 UHLWIi 0 16 en0 669
10.16.1.1 0:25:90:0:82:e1 UHLWIi 1 79 en0 1151
10.255.255.255 ff:ff:ff:ff:ff:ff UHLWbI 0 18 en0
127 localhost UCS 0 0 lo0
localhost localhost UH 3 5774410 lo0
169.254 link#5 UCS 0 0 en0
- Add/Remove static route
# add a route
route add -net 172.31.3.0 netmask 255.255.255.0 dev eth1
# remove the route
route del -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 eth0Add default gateway
- Add a default gateway
route add default gw 192.168.1.254 eth0Add route to another network
- Note: You must be on the same network as the gateway give below
- Add a route to another network (e.g. rocks headnode to access ipmi modules from local host)
route add -net 172.16.0.0 netmask 255.255.0.0 gw 10.16.1.1
## or on a Mac
sudo route -n add -net 172.16.0.0/16 10.16.1.1
## or on Windows
route add 172.16.0.0 mask 255.255.0.0 10.16.1.1Delete a static route
## or on a Mac
sudo route -n delete 172.16.0.0/16