I am running Ubuntu on a Amazon EC2 Server. I have a Public IP Address (

I am unable to bind the public IP address to UDP Port:

udp listen Cannot assign requested address

So, I am trying to change ifconfig to show the Public IP Address instead of the Private IP Address. However, the network changes I have tried have not worked.

Edit /etc/network/interfaces.d/eth0.cfg

# The primary network interface
auto eth0
#iface eth0 inet dhcp
iface eth0 inet static

The Gateway, I based on the results of a route -n command:

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface         UG    0      0        0 eth0   U     0      0        0 eth0

Current ifconfig settings:

eth0      Link encap:Ethernet  HWaddr 06:01:36:ee:0f:0d
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::401:36ff:feee:f0d/64 Scope:Link
          RX packets:8169768 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8126026 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:6143591550 (6.1 GB)  TX bytes:6277418496 (6.2 GB)

FYI, the Static IP Address ( is done using Amazon's Elastic IP address.

Anyone have a suggestion on how to change add the Public IP Address to the interfaces?

2 Answers 2


This is not how EC2 works.

All EC2 instances sit behind Amazon's NAT infrastructure. It is not possible to directly assign an EIP or other public IP directly to an EC2 instance.

  • That would seem to imply that there is no way to bind the public ip address. That I can only bind the private ip address.
    – Daryl
    Mar 23, 2016 at 16:41
  • 2
    That's correct. When you assign an EIP to an instance, Amazon configures a 1:1 NAT between the EIP and the private IP of your instance. Why do you think you need to directly bind the public IP?
    – EEAA
    Mar 23, 2016 at 16:42

Your AWS host is not directly aware of its public IP, EIP or otherwise. AWS takes care of that for you. That means your application cannot differentiate between something connecting to the internal IP and external.

From your application perspective you would bind to, AWS translates the external address to your internal address.

  • Thanks for your response Jason, great suggestion. Unfortunately, in my particular case, testing generated errors too.
    – Daryl
    Mar 24, 2016 at 15:30
  • That is odd -- most of the time you can bind to to indicate 'all' local interfaces, such as and your local IP address. Mar 24, 2016 at 15:50

You must log in to answer this question.

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