如何設定static route

88.9.10.128是一個host

指定要連結到88.9.10.128這台主機的封包,會經由wlan0的192.168.11.1這個gateway出去

Flags的H待表示一個Host

route add 88.9.10.128 gw 192.168.11.1 dev wlan0
# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.11.1    0.0.0.0         UG    0      0        0 wlan0
0.0.0.0         192.192.192.1   0.0.0.0         UG    0      0        0 eth0
88.9.10.128     192.168.11.1    255.255.255.255 UGH   0      0        0 wlan0
192.168.11.0    0.0.0.0         255.255.255.0   U     0      0        0 wlan0
192.192.192.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0

設定static route

連結到172.100.100.0網段的封包,必須經過192.192.192.1這個gw(當沒有指定是經由那個界面出去時,會經由gw去判斷,應該是那個interface出去)

route add -net 172.100.100.0 netmask 255.255.255.0  gw 192.192.192.1

連結到172.101.101.0網段的封包,必須經過192.192.192.1這個gw,並且明定指出是經由eth0這個界面出去

route add -net 172.101.101.0 netmask 255.255.255.0  gw 192.192.192.1 dev eth0
# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.11.1    0.0.0.0         UG    0      0        0 wlan0
0.0.0.0         192.192.192.1   0.0.0.0         UG    0      0        0 eth0
88.9.10.128     192.168.11.1    255.255.255.255 UGH   0      0        0 wlan0
172.100.100.0   192.192.192.1   255.255.255.0   UG    0      0        0 eth0
172.101.101.0   192.192.192.1   255.255.255.0   UG    0      0        0 eth0
192.168.11.0    0.0.0.0         255.255.255.0   U     0      0        0 wlan0
192.192.192.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0

刪除一條route 規則

route del -net 172.100.100.0 netmask 255.255.255.0 dev eth0
# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.11.1    0.0.0.0         UG    0      0        0 wlan0
0.0.0.0         192.192.192.1   0.0.0.0         UG    0      0        0 eth0
88.9.10.128     192.168.11.1    255.255.255.255 UGH   0      0        0 wlan0172.101.101.0   192.192.192.1   255.255.255.0   UG    0      0        0 eth0
192.168.11.0    0.0.0.0         255.255.255.0   U     0      0        0 wlan0
192.192.192.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0

刪除UGH的route 規則

route del 88.9.10.128
# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.11.1    0.0.0.0         UG    0      0        0 wlan0
0.0.0.0         192.192.192.1   0.0.0.0         UG    0      0        0 eth0
172.101.101.0   192.192.192.1   255.255.255.0   UG    0      0        0 eth0
192.168.11.0    0.0.0.0         255.255.255.0   U     0      0        0 wlan0
192.192.192.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0

猜你喜欢

转载自blog.csdn.net/u011028408/article/details/84026269