How to write rules for persistent net names?

To answer your specific question, add this to persistent-net.rules:

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="AA:AA:AA:AA:AA:AA", ATTR{dev_id}=="0x0", ATTR{type}=="1", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="BB:BB:BB:BB:BB:BB", ATTR{dev_id}=="0x0", ATTR{type}=="1", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="CC:CC:CC:CC:CC:CC", ATTR{dev_id}=="0x0", ATTR{type}=="1", NAME="eth1"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="DD:DD:DD:DD:DD:DD", ATTR{dev_id}=="0x0", ATTR{type}=="1", NAME="eth1"

Leave persistent-net-generator.rules alone. udev will not overwrite the rules you added manually but the generator rules will cause new rules to be added for new cards as usual.


Usually all I want to do in terms of naming interfaces is to swap eth0 and eth1. I let the system create the file /etc/udev/rules.d/70-persistent-net-rules, then edit it by switching the names, restart, then configure the interface stanzas in the network config files. Tedious but gets it done. There's a hint at the top of the file about this:

/etc/udev/rules.d/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 0x8086:0x108c (e1000e) (custom name provided by external tool)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:25:90:22:74:24", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"