July 20, 2015

Ubuntu 14.04: renaming ethernet interfaces from “em1″ to “eth0″

Step #1: Find out the MAC address of the Ethernet device

Type the following command:
# ifconfig -a | grep -i --color hwaddr
Sample outputs:
eth0      Link encap:Ethernet  HWaddr b8:ac:6f:65:31:e5
pan0      Link encap:Ethernet  HWaddr 4a:71:40:ed:5d:99
vmnet1    Link encap:Ethernet  HWaddr 00:50:56:c0:00:01
vmnet8    Link encap:Ethernet  HWaddr 00:50:56:c0:00:08
wlan0     Link encap:Ethernet  HWaddr 00:21:6a:ca:9b:10
Note down the MAC address.

Step #2: Rename em0 as eth0


Renaming the NIC is simple process unless it is ubuntu 14.04.
So, we need to do some changes in /etc/default/grub to fix this.
I confirm that setting the following  to /etc/default/grub will fix the problem:
GRUB_CMDLINE_LINUX_DEFAULT=”net.ifnames=1 biosdevname=0″
followed by
$sudo update-grub
and setup the naming in
/etc/udev/rules.d/70-persistent-net.rules

To setup the naming in 70-persistent-net.rules:

In case of “70-persistent-net.rules” file not found in the /etc/udev/rules.d/ directory, We can regenerate the one using the following steps:
export INTERFACE=p2p1
export MATCHADDR=$(ip addr show $INTERFACE | grep ether | awk '{print $2}')
/lib/udev/write_net_rules
cat /etc/udev/rules.d/70-persistent-net.rules
repeat the above command for all the interface you have, with the appropriate name substitution.
Here’s how to rename your network card in Ubuntu 14.04:
  1. Get your ethernet card MAC address: ifconfig | grep HWaddr
    keep it handy (open a new Terminal window for following steps)
  2. cd /etc/udev/rules.d
  3. backup your file: cp 70-persistent-net.rules 70-persistent-net.rules.bak
  4. edit your file: sudo nano 70-persistent-net.rules
  5. very carefully type: SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="xx:xx:xx:xx:xx:xx", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
    where the xx:xx:xx are your MAC HWAddr from Step 1
    Type this all as one big long line, then save and exit.
  6. edit /etc/network/interfaces to refer to eth0 instead of m1 or whatever
  7. $reboot
  8. login and type ifconfig to confirm your network adapter is at eth0
Now you should see the new name for your NIC.
Before:
# lshw -businfo -C network
Bus info Device Class Description
===================================================
pci@0000:03:00.0 eth0 network NetXtreme II BCM5709 Gigabit Ethernet
pci@0000:03:00.1 eth1 network NetXtreme II BCM5709 Gigabit Ethernet
pci@0000:04:00.0 eth2 network NetXtreme II BCM5709 Gigabit Ethernet
pci@0000:04:00.1 p1p1 network NetXtreme II BCM5709 Gigabit Ethernet
After:
# lshw -businfo -C network
Bus info Device Class Description
================================================
pci@0000:03:00.0 eth0 network NetXtreme II BCM5709 Gigabit Ethernet
pci@0000:03:00.1 eth1 network NetXtreme II BCM5709 Gigabit Ethernet
pci@0000:04:00.0 eth2 network NetXtreme II BCM5709 Gigabit Ethernet
pci@0000:04:00.1 p1p1 network NetXtreme II BCM5709 Gigabit Ethernet

or method below
Hello,

I had the same problem as you (I had a em1 NIC instead of a normal eth0). After trying several things, the one that solved my problem was this:

Edit /etc/default/grub and find these lines:
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX=""


Add biosdevname=0, just like this:
GRUB_CMDLINE_LINUX_DEFAULT="biosdevname=0"
GRUB_CMDLINE_LINUX="biosdevname=0"


Then run:
sudo update-grub
sudo reboot


At least this worked for me. After that I modified the /etc/network/interfaces in order to have the IP I wanted for eth0.
If this didn't work for you, I also made some changes before this, maybe they could work for you:

First try

Get your MAC address like you did or with this command (look for the serial attribute):
sudo lshw -class network
Then:
cd /etc/udev/rules.d
sudo nano 70-persistent-net.rules

Add this(substitute the xx:xx:xx:xx:xx with your MAC address. I don't know if dev_id should be the physical id of the "lshw" command):
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="xx:xx:xx:xx:xx:xx", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
And reboot!


Second try

sudo cp /lib/udev/rules.d/75-persistent-net-generator.rules /etc/udev/rules.d/
cd /etc/udev/rules.d
sudo nano 75-persistent-net-generator.rules

And add at the end this(substitute xx:xx:xx with the first part of your MAC address):
ENV{MATCHADDR}==”xx:xx:xx:*”, GOTO=”globally_administered_whitelist”
And reboot!

Cheers,

0 comments:

Post a Comment