将默认网关添加到路由表

时间:2019-10-15 18:49:18

标签: routing routes gateway

从空的路由表开始:

$ ip route show
# no output

然后为 eth1 (IP 10.120.5.16,网络掩码255.255.224.0)创建了路由表 101

$ ip route add 10.120.0.0/19 dev eth1 src 10.120.5.16 table 101
$ ip rule add from 10.120.5.16 table 101

然后尝试为表 101 添加默认网关,但失败了:

$ ip route add default via 10.120.0.1 dev eth1 table 101
RTNETLINK answers: Network is unreachable

但是可以使用-I eth1 ping 10.120.0.1:

$ ping 10.120.0.1 -I eth1
PING 10.120.0.1 (10.120.0.1) from 10.120.5.16 eth1: 56(84) bytes of data.
64 bytes from 10.120.0.1: icmp_seq=1 ttl=255 time=1.49ms
64 bytes from 10.120.0.1: icmp_seq=1 ttl=255 time=1.52ms

并非没有指定接口:

$ ping 10.120.0.1
connect: Network is unreachable

问题:如何为路由表设置默认网关?

其他信息

$ ip route show table 101
10.120.0.0/19 dev eth1 scope link src 10.120.5.16
$ ip rule show
0:        from all lookup local
32765:    from 10.120.5.16 lookup 101
32766:    from all lookup main
32767:    from all lookup default

操作系统:Ubuntu 14.04

0 个答案:

没有答案