2

I am having problems adding a 2nd IP on AWS EC2 instance. I am running Ubuntu 14.04.

I already tried this:

a) Right clicked the instance and added a 'private IP' from the manage Private IP. b) Ssh'ed into the machine and added a file /etc/network/interfaces.d/eth0_0.cfg with this content:

auto eth0:0 iface eth0:0 inet dhcp

then I ran sudo ifup eth0:0 and I get:

Internet Systems Consortium DHCP Client 4.2.4 Copyright 2004-2012 Internet Systems Consortium. All rights reserved. For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/eth0:0/0a:ee:d5:2f:e3:36 Sending on
LPF/eth0:0/0a:ee:d5:2f:e3:36 Sending on Socket/fallback DHCPDISCOVER on eth0:0 to 255.255.255.255 port 67 interval 3 (xid=0x4dfeb91a) DHCPREQUEST of 172.31.21.78 on eth0:0 to 255.255.255.255 port 67 (xid=0x4dfeb91a) DHCPOFFER of 172.31.21.78 from 172.31.16.1 DHCPACK of 172.31.21.78 from 172.31.16.1 RTNETLINK answers: File exists bound to 172.31.21.78 -- renewal in 1683 seconds.

But I cannot see it using ifconfig. I can only see this if I run ifconfig eth0:0

eth0:0 Link encap:Ethernet HWaddr 0a:ee:d5:2f:e3:36
UP BROADCAST RUNNING MULTICAST MTU:9001 Metric:1

any ideas how I can activate the 2nd private IP?

  • I'd recommend looking at this blog post. Very comprehensive: lisenet.com/2014/… – kontinuity Jan 28 '15 at 13:25
  • @kontinuity - that may not be what the OP intended. Adding a 2nd network interface is not the same as adding a 2nd ip to an existing interface. Although I think you may have to allocate the ip address in the AWS GUI before assigning it to the eni (ethernet network interface). I'll have to run the experiment and I'll report back. – LHWizard May 25 '15 at 18:27
4

i worked on ubuntu 12.04.. you may check is the command still working on 14.04.

append /etc/network/interfaces

auto eth0:1
iface eth0:1 inet static
address 10.0.10.101 ### this address is the secondary IP you created on aws console

i dont think AWS support DHCP so the addresses are fixed.

after you append, run this

/etc/init.d/network restart

it will start 2 network interfaces.

2

For Ubuntu 16.04: append to /etc/network/interfaces.d/50-cloud-init.cfg

auto eth0:1
iface eth0:1 inet static
address 172.1.2.3

Where 172.1.2.3 is your secondary private ip. Then execute

sudo systemctl restart networking

You can check that it's ok by ifconfig:

ifconfig | fgrep -A2 eth0:1
  • My default interface was ens3 instead of eth0, so I had to replace that in the instructions above to make it work. – Felipe Lima Nov 6 '17 at 3:02
  • The file that you're saying to change is generated automatically by cloud-init and will be override after stop/start the instance. – Elias Soares Nov 22 '17 at 14:27
  • If someone need to use multiple network interfaces or multiple ips on single interface, I've made an updated port of ec2-net-tools for Ubunti 16.04 that automatically identies and configure interfaces and routes just like on Amazon Linux for EC2. Please see github.com/iget-master/ubuntu-ec2net – Elias Soares Nov 26 '17 at 2:59
0

Also for Ubuntu 16.04 you can associate more than two IPs by adding the next in line:

auto eth0:1
iface eth0:1 inet static
address 172.1.2.1

auto eth0:2
iface eth0:2 inet static
address 172.1.2.2

There is also a note in the file that if you want these changes to persist across an instance you need create the file /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:

network: {config: disabled}
-3

Your machine can only have one IP address per logical network interface. You could use bridge-utils to create two virtual network interfaces which each would get their own DHCP lease by virtue of having different MAC addresses.

Why do you want your machine to have two IPs?

  • 7
    this is simply not true. Linux supports multiple addresses per interface – Cfreak Aug 25 '14 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.