在Linux和Solaris系统中可以有多条默认路由,用以下方式添加至内存:
route add default gateway 192.168.1.1
route add default gateway 10.0.1.1
通信的时候,系统会根据去往的不同网段自动选取。
下例是在Solaris 10上做的:
# netstat -r
Routing Table: IPv4
Destination Gateway Flags Ref Use Interface
-------------------- -------------------- ----- ----- ---------- ---------
default 120.193.133.89 UG 1 17
default 120.193.133.97 UG 1 4
120.193.133.88 NMHH-PB-SV-DNS1-1-HS U 1 0 e1000g0
120.193.133.96 120.193.133.98 U 1 1 e1000g1
224.0.0.0 NMHH-PB-SV-DNS1-1-HS U 1 0 e1000g0
localhost localhost UH 3 81 lo0
# ifconfig -a
lo0: flags=2001000849 mtu 8232 index 1
inet 127.0.0.1 netmask ff000000
e1000g0: flags=1000843 mtu 1500 index 2
inet 120.193.133.90 netmask fffffffc broadcast 120.193.133.91
ether 0:21:28:b1:31:ca
e1000g1: flags=1000843 mtu 1500 index 3
inet 120.193.133.98 netmask fffffffc broadcast 120.193.133.99
ether 0:21:28:b1:31:cb
#
# cat /etc/defaultrouter
120.193.133.89
120.193.133.97
#
# traceroute 120.193.133.94
traceroute: Warning: Multiple interfaces found; using 120.193.133.98 @ e1000g1
traceroute to 120.193.133.94 (120.193.133.94), 30 hops max, 40 byte packets
1 120.193.133.97 (120.193.133.97) 3.240 ms 0.934 ms 0.940 ms
2 120.193.133.85 (120.193.133.85) 1.005 ms 0.848 ms 0.801 ms
3 120.193.133.94 (120.193.133.94) 0.405 ms 0.382 ms 0.344 ms
# traceroute 120.193.133.102
traceroute: Warning: Multiple interfaces found; using 120.193.133.98 @ e1000g1
traceroute to 120.193.133.102 (120.193.133.102), 30 hops max, 40 byte packets
1 120.193.133.97 (120.193.133.97) 1.127 ms 0.893 ms 0.767 ms
2 120.193.133.102 (120.193.133.102) 0.346 ms 0.311 ms 0.330 ms
#
在Linux上还可以针对不同网段添加不同路由:
route add -net 10.0.0.0 gateway 10.0.0.1
route add -net 192.168.0.0 gateway 192.168.0.1
阅读(2248) | 评论(0) | 转发(0) |