how to change network interface names in fedora

fedora now lets udev assign network interface names based on the almost random junk that it receives from the BIOS at boot. that means that instead of predictable names like eth0, eth1 or wlan0, wlan1; network interfaces now have names like wlp0n1 or something similar.

while new code can be changed to accommodate this silliness, the problem is that it breaks tons of existing code- and for no really good reason.

if one encounters this madness in a new box, a couple of rules can be added to udev. for example, this can be placed into a file named /etc/udev/rules.d/75-persistent-net.rules:

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="54:ee:75:xx:xx:xx", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="5c:c5:d4:xx:xx:xx", NAME="wlan0"

they’ve also broken ifconfig so that existing code now fails to parse the mac address from its output. this is the output from a less silly distro like debian or amazon linux:

$ ifconfig eth0
eth0    Link encap:Ethernet  HWaddr 06:78:6b:ad:c5:2b
        inet addr:10.16.0.93  Bcast:10.16.0.255  Mask:255.255.255.0
    inet6 addr: fe80::478:6bff:fead:c52b/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST  MTU:9001  Metric:1

and fedora’s dain-bramaged output:

$ ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::56ee:75ff:fe4d:ffe8  prefixlen 64  scopeid 0x20<link>
    ether 54:ee:75:4d:ff:e8  txqueuelen 1000  (Ethernet)

(sigh)

since this is a linux-specific problem, it’s appropriate to use a linux-specific solution, and instead of parsing the output of ifconfig, use the files in /sys/class/net:

$ cat /sys/class/net/eth0/address
54:ee:75:xx:xx:xx
$ cat /sys/class/net/wlan0/address
5c:c5:d4:xx:xx:xx