I have a test server(ubuntu 16.04 xenial) on azure.I want to bind multiple network card this vm.I can bind network cards from azure portal.In the vm i can see (ip a) that network card and ip.When i try to reach internet via first network card (eth0) it is succesful.But when i try with this:
ping 8.8.8.8 -I eth1
It can not reach internet.
In the documentation it says add static route for you vm.I tried with following command but result is same:
ip route add default via 192.168.1.1 dev eth1 metric 10
Also i can not add route without metric Here are my default route table:
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
If you want to access public network from your second NIC, try the command below:
ip route add default via 192.168.1.1 dev eth1 table 11
ip rule add from 192.168.1.4 table 11
11 is just an identifier here, if you add third NIC, you can add its route to table 12,13....
With this done, you should use your second NIC private IP to ping public network address:
ping 8.8.8.8 -I 192.168.1.4
Hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.