renaming network interface in Ubuntu 16.04 with systemd fails

This may or may not help .. I would check /etc/udev/rules.d and see if you have 70-persistent-net.rules. You should be able to rename them using that file

Mine looks like this:

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="e0:cb:ee:d7:ff:9a", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

If you have the entries for your cards in this file you can change the name to what ever you want by changing the "NAME=TheNameYouWant"


An option that doesn't require udev rules (an alternative to systemd-networkd .link files) that works with Ubuntu 16.04 as well as many other Linux versions is

Example:

ifconfig peth0 down  
ip link set peth0 name eth0  
ifconfig eth0 up 

In the example above peth0 is the original interface name and eth0 is the desired name. Plug in the name you currently have where peth0 is and the name you want where eth0 is. No reboot is required or suggested. Repeat the process for the second interface card

Tested on Ubuntu 16.04 with kernel 4.4.0-36-generic #55-Ubuntu

Edit: If you are looking for a persistent solution that survives reboot see Changing Network Interfaces name Ubuntu 16.04

Sources: https://www.freedesktop.org/software/systemd/man/systemd.link.html

http://kernelpanik.net/rename-a-linux-network-interface-without-udev/

Testing.

Note: since @antti-haapala method worked before and suddenly stopped you might be interested to know that "As a special case, an empty file (file size 0) or symlink with the same name pointing to /dev/null disables the configuration file entirely (it is "masked")". <-Source


  • All the three custom naming methods, explained systemd: Predictable Network Interface Names, are related to udev rules.

    systemd .link's & udev rules have folder priority. /etc overrides /run overrides /lib.

    So check the current setup.

    # links
    ls -l /*/systemd/network/
    
    # rule that read links
    ls -l /*/udev/rules.d/80-net-setup-link.rules
    
    # rule that check for /etc/.../80-net-setup-link.rules & net.ifnames
    ls -l /*/udev/rules.d/73-usb-net-by-mac.rules
    

    After any change in these udev rules (adding/removing override files) to be effective, The boot RAM disk should be updated:

    sudo update-initramfs -u
    

    By default, these are the only files you may find

    ~$ ls -l /*/systemd/network/
    /etc/systemd/network/:
    total 0
    
    /lib/systemd/network/:
    total 12
    -rw-r--r-- 1 root root 404 Jul 12 17:28 80-container-host0.network ##(virtual-interface)
    -rw-r--r-- 1 root root 482 Jul 12 17:28 80-container-ve.network ##(virtual-interface)
    -rw-r--r-- 1 root root  80 Jul 12 17:28 99-default.link
    
    
    ~$ ls -l /*/udev/rules.d/80-net-setup-link.rules
    -rw-r--r-- 1 root root 292 Jul 12 17:28 /lib/udev/rules.d/80-net-setup-link.rules
    
    ~$ ls -l /*/udev/rules.d/73-usb-net-by-mac.rules
    -rw-r--r-- 1 root root 551 Jul 12 16:37 /lib/udev/rules.d/73-usb-net-by-mac.rules
    

    I have tested all of them in VBox fresh 16.04 install as documented in below link, all methods works as expected:

    Ubuntu 16.04 Complicated Interface Names

  • /etc/udev/rules.d/70-persistent-net-rules is from older releases replaced by systemd .link's (but they are not auto created), I added it here to check its existence for specific problems but not for AnttiHaapala's case.