3

I have EC2 instance (Linux OS) and I added second network interface to it. I got public Elastic IP and assigned to the network interface. Then I assigned network interface to the EC2 Instance.

When I run on EC2 Instance

ifconfig

I get eth0 and eth1 info with private IP addresses correctly assigned. When I select "Manage IP addresses" for my EC2 Instance on AWS I get: enter image description here

Both network interfaces are in the same subnet and security group. I can ping public IP for eth0 but I can not ping public IP for eth1.

What am I missing?

UPDATE: I noticed that Public DNS of second (IP 52.27.x.x) is exactly the same as for first IP 34.212.x.x

1 Answer 1

3

Unless you're using Windows or AWS Linux you are going to need to configure the interface manually.

Launching an Amazon Linux or Windows Server instance with multiple network interfaces automatically configures interfaces, private IPv4 addresses, and route tables on the operating system of the instance.

There is also a caveat in the Best Practices section about a potential issue with having two (or more) interfaces on the same subnet.

If you attach two or more network interfaces from the same subnet to an instance, you may encounter networking issues such as asymmetric routing. If possible, use a secondary private IPv4 address on the primary network interface instead. For more information, see Assigning a Secondary Private IPv4 Address.

Caveat The following steps are a parsed version of the second reference listed below, ymmv.

The steps I followed to create the secondary interface were:

  1. Create a /etc/sysconfig/network-scripts/ifcfg-eth1 file with the following:

    DEVICE=eth1
    NAME=eth1
    HWADDR=<value of link/ether from "ip a" command>
    BOOTPROTO=dhcp
    ONBOOT=yes
    TYPE=Ethernet
    USERCTL=no
    NM_CONTROLLED=no
    
  2. Edit the /etc/sysconfig/network and add:

    GATEWAYDEV=eth0
    
  3. Prevent cloud-init from overwriting your changes edit /etc/cloud/cloud.cfg and add:

    network:
     ; config: disabled
    
  4. Restart the network

    systemctl restart network
    
  5. Create a secondary routing table

    ip route add default via <default route ip from "ip route" output> dev eth1 table <new table number>
    
  6. Add the route to the new table

    ip route add <secondary private ip> dev eth1 table <new table number from above>
    
  7. Set the rule in the policy database

    ip rule add from <secondary private ip> lookup 1000
    
  8. Create a static route file /etc/sysconfig/network-scripts/route-eth1 and add:

    default via <default route IP> dev eth1 table 1000
    <private ip> dev eth1 table 1000
    
  9. Create a rule file for rule-eth1 /etc/sysconfig/network-scripts/rule-eth1:

    from <secondary private ip> lookup <new table number>
    

NOTE

On Step 4 you may get an error restarting the network. If you do, move/rename the ifcfg-eth0 file, and pkill dhclient. I then had to put the ifcfg-eth0 file back to get it to be picked up on reboot.

References

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html

https://aws.amazon.com/premiumsupport/knowledge-center/ec2-centos-rhel-secondary-interface/

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/MultipleIP.html#ManageMultipleIP

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .