cannot find device "eth0" when trying to add secondary ip to AWS EC2

Jayreis asked:

I have followed a youtube video on creating an ec2 and then adding two elastic ip addresses to the instance. However when I ssh into the ubuntu server to add the new secondary ip I get an error that says

cannot find device "eth0"

when I run the below command

sudo ip addr add 172.31.32.210/20 dev eth0

Note I released that ip so its not my ip address anymore but you can see the command I am using. What would cause this error and how to resolve?

If I run a ip link command I get the below:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether 0e:e4:6d:b4:d6:93 brd ff:ff:ff:ff:ff:ff

My answer:


The problem is that your network interface is named ens5, not eth0. You should use the correct interface name in your commands. Having interfaces actually named eth0 after the system is booted has been deprecated for years, and these days you should treat it as an example only, especially when using outdated tutorials.


View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.