我刚刚进入VPC,试图了解如何一切正常。 到目前为止,我遇到的最大障碍是,无论何时向机器添加第二个Elastic NIC,第二个IP都不能被VPC中的其他人访问。 这是我做的
auto eth1
iface eth1 inet dhcp
在我的主要(互联网访问)的实例:
没有ACL阻止ping,因为它与eth0一起工作。 机器上没有防火墙设置。 我已经尝试了4个不同的实例跨越几个SG和AZ与多个接口,都具有相同的结果。
我已经把我的头撞在墙上的时间超过了我所承认的时间。 我无法弄清楚错误在哪里。
路由表默认只会将stream量路由到eth0 。 即使Ubuntu检测到其他的ENI,你仍然必须将stream量路由到它。
你将不得不做一些高级路由:
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.
2)在重新启动但是持续的情况下启用对第二个ENI的访问。
来源: http : //blog.bluemalkin.net/multiple-ips-and-enis-on-ec2-in-a-vpc/
此外,如果您希望此更改持续存在,则可以在界面文件中进行所有这些更改,并重新启动networking服务或重新启动以使其生效。
# 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
为了充分发挥作用,请重新启动系统。
注意:我试过/etc/init.d/networking restart; 但它没有拿起路线/规则的变化,不知道为什么,所以我重新启动。 如果你想立即坚持,做两种方法。
这是我怎么做的。 我使用静态IP。 最初我使用DHCP来获得2项。 IP地址和networking掩码。 以下是一步一步的说明:
启动实例
sudo cp /etc/network/interfaces.d/eth0.cfg /etc/network/interfaces.d/eth1.cfg sudo sed -i "s/eth0/eth1/g" /etc/network/interfaces.d/eth1.cfg sudo ifdown eth1 sudo ifup eth1 sudo ifconfig eth1 | tee /tmp/ifconfig-eth1-output.txt sudo ifdown eth1 sudo rm -f /etc/network/interfaces.d/eth1.cfg ETH0_IP=$(cat /tmp/ifconfig-eth1-output.txt | grep "inet addr:" | cut -f 2 -d':' | cut -f 1 -d' ') ETH0_NETMASK=$(cat /tmp/ifconfig-eth1-output.txt| grep "inet addr:" | cut -f 4 -d':') ETH0_GATEWAY=$(echo ${ETH0_IP} | sed "s/[0-9]*$/1/g") echo "auto eth1" > /tmp/eth1.cfg echo "iface eth1 inet static" >> /tmp/eth1.cfg echo "address ${ETH0_IP}" >> /tmp/eth1.cfg echo "netmask ${ETH0_NETMASK}" >> /tmp/eth1.cfg echo "up ip route add default via ${ETH0_GATEWAY} dev eth1 table 1 metric 10001" >> /tmp/eth1.cfg echo "up ip rule add from ${ETH0_IP}/32 table 1 priority 10001" >> /tmp/eth1.cfg echo "up ip route flush cache" >> /tmp/eth1.cfg sudo cp -f /tmp/eth1.cfg /etc/network/interfaces.d/ sudo ifup eth1
应该这样做,运行这些来检查。
curl --silent http://ipinfo.io curl --interface eth0 --silent http://ipinfo.io curl --interface eth1 --silent http://ipinfo.io
这些将立即生效,并将继续通过重新启动。