【问题标题】:Access internet with second (or multiple) NIC in Azure在 Azure 中使用第二个(或多个)NIC 访问 Internet
【发布时间】:2019-11-30 02:48:12
【问题描述】:

我在 Azure 中有一个带有 Ubuntu 19.04 和 4 个 NIC 的 VM,每个都有一个公共 IP,例如,这是第二个 NIC:

如您所见,它的公共 IP 为 191.234.186.19。

我的目标是能够从每个具有不同 IP 地址的 NIC 访问 Internet,但在 VM 内部,我只能使用第一个网络 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

但我仍然无法使用这些 NIC 连接到互联网,只有 eth0

我错过了什么吗?我是否需要更改/配置其他任何内容才能使其正常工作?

为了完整起见,我使用这个命令来测试连接性:

curl --interface eth1 api.ipify.org?format=json -w "\n"

而我的VM和本文中的一样:article

【问题讨论】:

    标签: azure networking nic


    【解决方案1】:

    我怀疑你可能需要 1) 为您的第 2、第 3 和第 4 个接口定义新的路由表, 2)将默认路由添加到这些表 3) 并定义规则以确保返回的数据包总是被路由回发送原始数据包的同一接口。

    这里有一些示例供您参考(例如thisthis)。

    我将指出几点,在针对您的具体情况进行设置时可能会对您有所帮助: iproute 允许您维护多个路由表。要指示操作系统使用不同的路由表,您需要定义rules,以最简单的形式将强制使用与发起连接的接口相对应的路由表。

    【讨论】:

      【解决方案2】:

      看起来只有 eth0 有默认网关。如果没有默认网关,您将无法在本地网络之外进行通信

      【讨论】:

      • 我看了这篇文章docs.microsoft.com/en-us/azure/virtual-machines/windows/…,它似乎解释了如何向辅助网卡添加新路由。由于我使用的是 linux,因此我将他们的教程翻译成这个命令:sudo route add -net 0.0.0.0 netmask 0.0.0.0 gw 10.0.0.1 metric 200 dev eth1 将这一行添加到route -n0.0.0.0 10.0.0.1 0.0.0.0 UG 200 0 0 eth1。但我仍然无法连接 curl。您知道如何将默认网关添加到我的其他 NIC 吗?
      • @Sassa Azure 在docs.microsoft.com/en-us/azure/virtual-machines/linux/… 有 Linux 文档以防万一。好的,不解释如何添加路由了。
      猜你喜欢
      • 1970-01-01
      • 2017-05-17
      • 1970-01-01
      • 1970-01-01
      • 2012-12-05
      • 1970-01-01
      • 1970-01-01
      • 2010-10-23
      • 1970-01-01
      相关资源
      最近更新 更多