azure - 使用 Azure 中的第二个(或多个)NIC 访问互联网

标签 azure networking nic

我在 Azure 中有一个虚拟机,带有 Ubuntu 19.04 和 4 个网卡,每个网卡都附加了一个公共(public) IP,作为示例,这是第二个网卡:

enter image description here

如您所见,它的公共(public) 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"

我的虚拟机与本文中的虚拟机相同:article

最佳答案

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

这里有一些示例供您引用(例如 thisthis )。

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

关于azure - 使用 Azure 中的第二个(或多个)NIC 访问互联网,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59112745/

相关文章:

c++ - 将 IP 地址添加到 NIC 的跨平台方式(使用 C++)

git - Azure Web 应用程序部署导致 VS Team Services 中的 PowerShell 失败

Azure 磁盘速度

node.js - 不支持的投影选项 : $concat On Azure CosmosDb

http - 如何在 C 中通过 HTTP 协议(protocol)发送图像?

networking - 使用(免费)嵌入式 TCP/IP 堆栈的经验?

linux - 修复内核丢弃来自外部网络的数据包

linux - 如何查看我的网卡的供应商信息?

.net - 使用 Visual Studio 2022 中的 Dotnet 6 部署的 Azure 功能不起作用

linux - 机器上的两个 NIC,将它们绑定(bind)到 OS 分配的单独接口(interface)