0

In order, through the CLI:

  • I create the vpc {10.1.0.0/16}
  • I create two subnetworks {10.1.0.0/24, 10.1.1.0/24}
  • I create the EC2 instance with the default NIC in the 10.1.0.0/24 subnet aws ec2 run-instances --image-id $AWS_IMAGE --count 1 --instance-type $AWS_INSTANCE_TYPE --key-name $AWS_KEY_NAME --security-group-ids "$SG_ID" --subnet-id "$SUBNET_ID" --private-ip-address $AWS_GATEWAY_IP
  • I create a new NIC with the 10.1.1.0/24 subnet aws ec2 create-network-interface --subnet-id $SEC_SUBNET_ID --groups $SG_ID --private-ip-address $AWS_GATEWAY_SEC_IP
  • I attach the new NIC to the previously created EC2 instance aws ec2 attach-network-interface --network-interface-id $SEC_NIC_ID --instance-id $AWS_GATEWAY_ID --device-index 1

When I access through ssh the EC2 instance the second NIC is DOWN, if I turn it UP manually it doesn't have its private IP address and I have to set it manually also.

How can I make the secondary NIC enabled by default?

ale93p
  • 103
  • 3

2 Answers2

0

Up to now, the only solution I was able to find is to manually set up the interface directly in the machine:

# sudo ifconfig eth1 up
# sudo ifconfig eth1 10.1.1.x netmask 255.255.255.0

The first command is to enable the interface, the second one is to assign to it an ip address. For now I assigned the same IP amazon was automatically assigning to the NIC, I don't know if setting a different IP would cause consistency problems.

ale93p
  • 103
  • 3
0

You have to configure the interfaces yourself on Ubuntu. Multiple interfaces, all using DHCP (and sometimes with multiple assigned addresses per interface) do not configure themselves and there's nothing to add the policy routes you need, for trafffic to exit on the correct interfaces.

Amazon Linux does this automatically, using a package called ec2-net-tools.

This has apparently been ported for Ubuntu compatibility, or at least there's an effort to do so in progress: https://github.com/ademaria/ubuntu-ec2net

Or you can fire up an Amazon Linux instance and reverse-engineer the operations it performs.

Michael - sqlbot
  • 22,658
  • 2
  • 63
  • 86