Linux Rename Eth0 Network Interface Card Name [ Udev ]

A wireless NIC is showing as wlan0 but I need to be appear as eth1. How can I rename wlan0 devices through udev as eth1? How do I change or rename eth0 as wan0 under Linux operating systems?

The best way to rename Ethernet devices is through udev. It is the device manager for the Linux kernel. Primarily, it manages device nodes in /dev. It is the successor of devfs and hotplug, which means that it handles /dev directory and all user space actions when adding/removing devices, including firmware load.
Tutorial details
Difficulty level Intermediate
Root privileges Yes
Requirements Linux + udev
Reboot required
Est. reading time N/A
The order of the network interfaces may be unpredictable under certain configurations. Between reboots it usually stays the same, but often after an upgrade to a new kernel or the addition or replacement of a network card (NIC) the order of all network interfaces changes. For example, what used to be rl0 now becomes wlan0 or what used to be eth0 now becoems eth2 or visa versa.

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 eth0 as wan0

To rename eth0 as wan0, edit a file called 70-persistent-net.rules in /etc/udev/rules.d/ directory, enter:
# vi /etc/udev/rules.d/70-persistent-net.rules
The names of the Ethernet devices are listed in this file as follows:

# PCI device 0x14e4:0x1680 (tg3)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="b8:ac:6f:65:31:e5", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

Locate and identify the line with the NIC from step 1 (look for the MAC address). It may look like above. In this example, the interface eth0 will be renamed to wan0 (change NAME="eth0" to NAME="wan0"):

# PCI device 0x14e4:0x1680 (tg3)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="b8:ac:6f:65:31:e5", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="wan0"

Save and close the file. Reboot the system to test changes:
# reboot
Verify new settings:
# ifconfig -a
# ifconfig wan0
# ifconfig -a | less
# ip addr show

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 20 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
20 comments… add one
  • Rahul Panwar Jan 2, 2013 @ 10:01

    Can i change the MAC address of a using udev rule. Actually i am getting random MAC for a Ethernet interface on my device. So i can’t rename that interface as in this rule MAC address is comparing.

    • Rizwan Oct 24, 2013 @ 23:28

      Try using “macchanger”

  • annazir Jan 2, 2013 @ 10:13

    Hi Rahul,
    Probably you are looking for this. On my ubuntu (10.04-LTS) system. Its like.

    root@ubuntu:/etc/udev/rules.d#cat 70-persistent-net.rules
    # This file was automatically generated by the /lib/udev/write_net_rules
    # program, run by the persistent-net-generator.rules rules file.
    # You can modify it, as long as you keep each rule on a single
    # line, and change only the value of the NAME= key.

    # PCI device 0x10ec:0x8139 (8139cp)
    SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”64:63:62:61:10:02″, ATTR{dev_id}==”0x0″, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth0″

    Change here what you want.

    • Rahul Panwar Jan 2, 2013 @ 13:41

      Thanks for your reply. :-)
      In my case ATTR{address}==”xx:xx:xx:xx:xx:xx″ is random, it changed on every reboot, so i can’t compare this.
      I need to make it static first, is there any way to do this?

      • Balvinder Jan 2, 2013 @ 16:46

        looks like you’re using some virtualization software, In that case, its the Virtualization software whether its Xen, KVM, Hyper-V, VMWare or any other, has the option to put the static MAC address. You’ll have to look out for the options..

        • Rahul Panwar Jan 3, 2013 @ 10:06

          Thanks Balvinder,
          I am working on a embedded self designed card and i have only one option to put the static MAC by using kernel. But i don’t want to change the kernel again. So looking for udev alternate, if it is possible. Like i can change the device name, can i change the MAC as well?

      • annazir Jan 3, 2013 @ 7:22

        Add this entry into your rc.local file

        ifconfig eth0 down hw ether 00:C1:26:10:30:C5 up

        • Rahul Panwar Jan 3, 2013 @ 10:02

          udev rule initiate before rc.local execution, so i don’t think that will work.

  • Jalal Hajigholamali Jan 5, 2013 @ 6:01


    Thanks a lot

  • sudeep Sep 3, 2013 @ 7:26

    thank you man !!!!!

  • dawabz94 Apr 14, 2014 @ 13:34

    Helpful explanations, thanks !

  • sammy martin May 29, 2014 @ 10:29

    This helped me a great deal after I seen that my network card started showing up with a p33p1 name instead of the eth0. Thank you.

  • cyrf0006 Jun 16, 2014 @ 9:54

    Hi everyone,
    Once I made the changes to 70-persistent-net.rules file (change eth2 to eth0 in my case) and reboot, the main adapter name have not changed (still eth0). Am I missing something? Should I check somewhere else?
    p.s. I am using CrunchBang

  • kannank Oct 17, 2014 @ 5:29

    Thanks problem was solved

  • ITguruBalu Dec 4, 2014 @ 5:46

    Very Helpful explanation… Thanks for sharing…

  • phil May 12, 2015 @ 15:34

    excellent. really helped me.

  • Sreekumar Jul 3, 2015 @ 12:29

    Excellent !!! When I search I used to add cyberciti… bcos I am confident that I would get answer :)

    Thank you all…

    • hisham Oct 5, 2015 @ 4:10

      same with me.. :)

  • Arshad Bhutto Aug 18, 2015 @ 12:02

    excellent reall helped me.thanks

  • sandeep Mar 7, 2016 @ 4:33


Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum