如何在Azure的VM上添加多个网卡?

我在azure上有一个测试服务器(ubuntu 16.04 xenial)。我想将此虚拟机绑定多个网卡。我可以从azure门户网站绑定网卡。在vm中,我可以看到(ip a)该网卡和ip 。当我尝试通过第一个网卡(eth0)进入互联网时,它是成功的。但是当我尝试这样做时:

  

ping 8.8.8.8 -I eth1

无法访问互联网。

在文档中说为您的虚拟机添加静态路由。我尝试使用以下命令,但结果相同:

  

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
mfj111071 回答:如何在Azure的VM上添加多个网卡?

如果要从第二个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

希望有帮助。

本文链接:https://www.f2er.com/3144875.html

大家都在问