AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 471957
Accepted
Jon
Jon
Asked: 2013-01-24 20:48:50 +0800 CST2013-01-24 20:48:50 +0800 CST 2013-01-24 20:48:50 +0800 CST

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

  • 772

我刚刚进入 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 一起使用。机器上没有防火墙设置。我已经在具有多个接口的多个 SG 和 AZ 中尝试了 4 个不同的实例,结果都相同。

在这件事上,我用头撞墙的时间比我愿意承认的要长。我不知道错误在哪里。

ubuntu
  • 2 2 个回答
  • 9057 Views

2 个回答

  • Voted
  1. Best Answer
    sonjz
    2014-07-22T11:48:48+08:002014-07-22T11:48:48+08:00

    默认情况下,路由表只会将流量路由到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.
    

    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
    

    要使其完全生效,请重新启动系统。

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

    • 11
  2. Titi Wangsa bin Damhore
    2015-11-22T13:57:19+08:002015-11-22T13:57:19+08:00

    我是这样做的。我使用静态IP。最初我使用 dhcp 来获取 2 个项目。IP 地址和网络掩码。这是分步说明:

    启动实例

    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
    

    这些将立即生效,并将通过重新启动持续存在。

    • 0

相关问题

  • 无法通过 Ubuntu VPN 访问外部网络

  • ubuntu apt-get upgrade - 如何在 shell 中单击确定?

  • VirtualBox 上 Ubuntu 的访客优化技巧 [关闭]

  • 外部硬盘上的 virtualbox 虚拟硬盘驱动器(Vista 主机上的 ubuntu 客户机)

  • 如何在 Ubuntu 上挂载 LVM 分区?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve