在 Ubuntu 实例上无法访问 AWS VPC 中的第二个 ENI

Jon*_*Jon 5 networking ubuntu amazon-ec2 amazon-web-services amazon-vpc

我刚刚进入 VPC,试图了解一切是如何运作的。到目前为止,我遇到的最大障碍是,每当我向机器添加第二个弹性 NIC 时,VPC 中的任何其他人都无法访问第二个 IP。这是我所做的

  • 推出 Canonical 为 Ubuntu 12.10 x64 EBS 提供的 AMI。
  • 在启动期间,我为两个网络接口(同一子网)配置了它
  • 机器启动后,我将以下内容添加到 /etc/network/interfaces :

自动 eth1

iface eth1 inet dhcp

  • ifup eth1
  • 运行ifconfig,验证第二个地址已启动。

在我的主要(互联网可访问)实例上:

  • ping(新实例 eth0 的 IP) - 有效
  • ping(新实例 eth1 的 IP) - 失败

没有阻止 ping 的 ACL,因为它适用于 eth0。机器上没有防火墙设置。我已经尝试了 4 个不同的实例,跨越多个具有多个接口的 SG 和 AZ,所有实例都具有相同的结果。

我一直把头撞在墙上的时间比我愿意承认的时间长。我无法弄清楚错误在哪里。

son*_*njz 11

默认情况下,路由表只会将流量路由到eth0. 即使 ubuntu 检测到另一个 ENI,您仍然必须将流量路由到它。

你必须做一些高级路由:

1) 立即和暂时启用对第二个 ENI 的访问。

来源:http : //www.rjsystems.nl/en/2100-adv-routing.php

# this will show your route table, i'll assume you have eth0 and eth1
# and your default is for eth0 to point to the gateway
# for this example lets assume the following:
# eth0 = 192.168.100.5 
# eth1 = 192.168.100.10
# gateway = 192.168.100.1
ip route show ;

# first step is to create a routing table for your new device
cat /etc/iproute2/rt_tables ;
echo 2 eth1_rt >> /etc/iproute2/rt_tables ;

# next add the eth1_rt route table, so by default it will also point to the gateway
ip route add default via 192.168.100.1 dev eth1 table eth1_rt ;

# next take a look at your ip rules
# i'll assume the defaults here, and things flows to default with priority 32767
ip rule;

# let's add a rule, if we see traffic from eth1's IP address,
# use its new routing table we setup, and give it higher priority than default
ip rule add from 192.168.100.10 lookup eth1_rt prio 1000 ;

# done! now check your traffic from both IPs, they should both work.
Run Code Online (Sandbox Code Playgroud)

2)在重新启动时启用对第二个 ENI 的访问,但持续存在。

来源:http : //blog.bluemalkin.net/multiple-ips-and-enis-on-ec2-in-a-vpc/

此外,如果您希望此更改持续存在,您可以在接口文件中进行所有这些更改,只需重新启动网络服务或重新启动即可使其生效。

# NOTE: add the eth1_rt routing table to /etc/iproute2/rt_tables as show in previous section

# original config to make dchp, I add mine to /etc/network/interfaces.d/eth1.cfg
auto eth1
iface eth1 inet dchp
    # your extra rules for eth1
    up ip route add default via 192.168.100.1 dev eth1 table eth1_rt
    up ip rule add from 192.168.100.10 lookup eth1_rt prio 1000
Run Code Online (Sandbox Code Playgroud)

要使此操作完全生效,请重新启动系统。

注意:我试过了,/etc/init.d/networking restart;但它没有发现路由/规则更改,不知道为什么,所以我重新启动了。如果您想让它立即和持久,请执行这两种方法。