我在 Azure 中有一个虚拟机,带有 Ubuntu 19.04 和 4 个网卡,每个网卡都附加了一个公共 IP,作为示例,这是第二个网卡:
如您所见,它的公共 IP 为 191.234.186.19。
我的目标是能够从具有不同 IP 地址的每个 NIC 访问互联网,但在虚拟机内部我只能使用第一个网络访问它eth0
.
看着# route -n
我得到这个输出:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.1 0.0.0.0 UG 100 0 0 eth0
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth3
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
168.63.129.16 10.0.0.1 255.255.255.255 UGH 100 0 0 eth0
169.254.169.254 10.0.0.1 255.255.255.255 UGH 100 0 0 eth0
我尝试使用以下命令为其他网卡添加路由:
sudo ip route add default via 10.0.0.1 dev eth1 metric 101
sudo ip route add default via 10.0.0.1 dev eth2 metric 102
sudo ip route add default via 10.0.0.1 dev eth3 metric 103
但我仍然无法使用这些网卡连接到互联网,只能eth0
.
我错过了什么吗?我是否需要更改/配置其他任何内容才能使其正常工作?
为了完整起见,我使用此命令来测试连接:
curl --interface eth1 api.ipify.org?format=json -w "\n"
而我的VM和本文中的VM是一样的:article https://www.itinsights.org/Use-multiple-public-IP-addresses-in-Azure-VM/
我怀疑你可能需要
1) 为第二个、第三个和第四个接口定义新的路由表,
2)将默认路由添加到这些表中
3) 并定义规则以确保返回数据包始终路由回原始数据包发送的同一接口。
有几个例子供您参考(例如this https://www.thomas-krenn.com/en/wiki/Two_Default_Gateways_on_One_System and this http://www.rjsystems.nl/en/2100-adv-routing.php).
我只想指出几点,在针对您的具体情况进行设置时可能会有所帮助:iproute https://www.systutorials.com/docs/linux/man/8-ip-route/允许您维护多个路由表。要指示操作系统使用不同的路由表,您需要定义rules http://man7.org/linux/man-pages/man8/ip-rule.8.html在最简单的形式中,将强制使用与发起连接的接口相对应的路由表。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)