linux添加网关和出接口不同网段的路由
1.eth0的ip地址为10.1.1.1/24路由信息如下# route -nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface192.168.150.0 0.0.0.0 255.255.255.0 U
1.eth0的ip地址为10.1.1.1/24
路由信息如下
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.150.0 0.0.0.0 255.255.255.0 U 0 0 0 mgmt
10.1.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1007 0 0 mgmt
0.0.0.0 192.168.150.254 0.0.0.0 UG 0 0 0 mgmt
2.直接添加路由网关和出接口相同网段会失败
# route add -net 2.0.0.0/8 gw 20.1.1.1 eth0
SIOCADDRT: No such process
3.正确配置方式:
#route add -net 0.0.0.0 eth0
#route add -net 2.0.0.0/8 gw 20.1.1.1 eth0
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.150.0 0.0.0.0 255.255.255.0 U 0 0 0 mgmt
10.1.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1007 0 0 mgmt
2.0.0.0 20.1.1.1 255.0.0.0 UG 0 0 0 eth0
0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 eth0
0.0.0.0 192.168.150.254 0.0.0.0 UG 0 0 0 mgmt
ps
一种使用场景:
拓扑:
linux1-eth0--------eth0-linux2-eth1
linux1:
eth0 10.1.1.1/24
linux2:
eth0 20.1.1.1/24
eth1 2.2.2.2/24
1.linux1
route add -net 0.0.0.0 eth0
route add -net 2.0.0.0/8 gw 20.1.1.1 eth0
2.linux2
route add -net 0.0.0.0 eth0
route add -net 10.0.0.0/8 gw 10.1.1.1 eth0
3配置如上后linux1 ping 2.2.2.2可通
更多推荐
所有评论(0)