我在azure上有一个测试服务器(ubuntu 16.04 xenial(。我想在这个vm上绑定多个网卡。我可以从azure门户绑定网卡。在vm中,我可以看到(ip a(那个网卡和ip。当我尝试通过第一张网卡(eth0(上网时,它成功了。但当我尝试这个:
ping 8.8.8.8-I eth1
它无法访问互联网。
在文档中,它说为vm添加静态路由。我尝试了以下命令,但结果是一样的:
ip路由通过192.168.1.1 dev-eth1 metric 10 添加默认值
此外,我不能添加没有度量的路由这是我的默认路线表:
root@test:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
168.63.129.16 192.168.0.1 255.255.255.255 UGH 0 0 0 eth0
169.254.169.254 192.168.0.1 255.255.255.255 UGH 0 0 0 eth0
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
root@test:~# ip route add default via 192.168.1.1 dev eth1
RTNETLINK answers: File exists
root@test:~# ip route add default via 192.168.1.1 dev eth1 metric 10
root@test:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
0.0.0.0 192.168.1.1 0.0.0.0 UG 10 0 0 eth1
168.63.129.16 192.168.0.1 255.255.255.255 UGH 0 0 0 eth0
169.254.169.254 192.168.0.1 255.255.255.255 UGH 0 0 0 eth0
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
root@test:~# ping 8.8.8.8 -I eth0
PING 8.8.8.8 (8.8.8.8) from 192.168.0.4 eth0: 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=50 time=2.51 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=50 time=2.10 ms
^C
--- 8.8.8.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 2.102/2.308/2.514/0.206 ms
root@test:~# ping 8.8.8.8 -I eth1
PING 8.8.8.8 (8.8.8.8) from 192.168.1.4 eth1: 56(84) bytes of data.
^C
--- 8.8.8.8 ping statistics ---
18 packets transmitted, 0 received, 100% packet loss, time 17410ms
如果您想从第二个NIC访问公共网络,请尝试以下命令:
ip route add default via 192.168.1.1 dev eth1 table 11
ip rule add from 192.168.1.4 table 11
11在这里只是一个标识符,如果您添加第三个NIC,您可以将其路由添加到表12、13…
完成后,您应该使用您的第二个NIC专用IP来ping公共网络地址:
ping 8.8.8.8 -I 192.168.1.4
希望能有所帮助。