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

Sometimes, an ethernet interface will install itself as “p1p1″ or the like instead of the traditional “eth0″. Where most of documents related to openstack assume that the default name of NIC is eth* for configuring bridge interface.

It is not a big issue when you follow the document in step by step process. Since, we can just replace the eth0 with our NIC name such as p1p1.

But what if we choose to install openstack using automated script. It become hard to go through entire script to change the default name of NIC with specific new name.

So in that case, it will be better if we have the choice for renaming the NIC .

Renaming the NIC is simple process unless it is ubuntu 14.04. Since, there is a bug reported on renaming the NIC.

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=="p*", 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 p1p1 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

 

Cheers,

Vinoth

4 Comments

  • Nigel Aves says:

    This tutorial worked perfectly, thank you. (I’m using Ubunto 14.04

    The one thing that did not work was the setup on the 70-persistent-net.rules file. The top of the file has this warning … which proved to be true …

    # You can modify it, as long as you keep each rule on a single
    # line, and change only the value of the NAME= key.

    So I only changed the NAME=”eth0″ field and left the rest untouched.

    After changing to your line networking was never initialized after boot.

    SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”bc:ae:c5:65:51:ab”, KERNEL==”p*”, NAME=”eth0″

    The above settings worked perfectly for me ….

  • Anisul Huq says:

    Hi,
    KERNEL==”p*” should be KERNEL==”eth*”

    Bye.

Leave a Comment