Rename a Linux Network Interface by MAC Address with nameif
You will rename one Ethernet network interface by matching its MAC address with nameif. The result is a predictable interface name such as lan0, which can make older boot scripts or fixed network rules easier to follow. Allow about 15 minutes, plus a maintenance window if the interface carries a live connection.
The route
Jump straight to the step you need, or tick off Done means at the end.
Checkpoint
This guide changes a kernel network-interface name. Do it from a local console or an out-of-band session if the target interface is your current SSH connection. The command should run before the interface is up, and it normally needs root privileges.
1. Check the installed command
This guide follows the installed nameif(8) manual. On this system it is supplied by net-tools 2.10-0.1ubuntu4.4. The manual documents two modes: a configuration file, normally /etc/mactab, or one interface name and MAC address on the command line. It also says that the tool currently works only with Ethernet interfaces.
$ command -v nameif
/usr/sbin/nameif
$ dpkg-query -W -f='${Package} ${Version}\n' net-tools
net-tools 2.10-0.1ubuntu4.4
$ nameif --help
usage: nameif [-c configurationfile] [-s] {ifname macaddress}
--help is not a supported option here, so the installed program reports usage and a non-zero status. That output still confirms the available option shape. Do not infer extra long options from examples for a different release.
2. Record the real interface and MAC address
Use an ordinary, unprivileged command to list the current names and hardware addresses. Replace OLD_IFACE with the physical Ethernet interface you intend to rename. Do not guess the MAC from a different host or from a virtual bridge.
$ ip -br link
OLD_IFACE UP 90:1b:0e:da:cc:ef <BROADCAST,MULTICAST,UP,LOWER_UP>
$ ip link show dev OLD_IFACE
3: OLD_IFACE: <BROADCAST,MULTICAST,UP,LOWER_UP> ...
link/ether 90:1b:0e:da:cc:ef brd ff:ff:ff:ff:ff:ff
Your interface number, flags and MAC will differ. Copy the address exactly, including all six hexadecimal pairs. Check that the interface is Ethernet and that the proposed new name is not already in use:
$ ip link show dev NEW_IFACE
Device "NEW_IFACE" does not exist.
If that command finds an existing interface, stop. A name collision is a configuration problem to resolve before attempting a rename.
3. Create a minimal mactab entry
The default configuration file is /etc/mactab. Each non-comment line contains the new interface name followed by an Ethernet MAC address. Comments begin with #. Keep the file small while testing, and use a name that your network manager and firewall rules also understand.
# new-name ethernet-mac-address
NEW_IFACE 90:1b:0e:da:cc:ef
Create or edit it with elevated privileges:
$ sudoedit /etc/mactab
$ sudo chmod 0644 /etc/mactab
$ sudo sed -n '1,20p' /etc/mactab
# new-name ethernet-mac-address
NEW_IFACE 90:1b:0e:da:cc:ef
The chmod command is optional if the file already has a suitable mode. Do not put passwords, shell commands or interface settings on these lines. nameif reads names and MAC addresses; it does not configure an address, route or DHCP client.
4. Stop the interface before renaming it
This is the service-disrupting step. Bringing down a connected interface interrupts traffic and may disconnect your terminal. Save your work and use an out-of-band console when necessary.
$ sudo ip link set dev OLD_IFACE down
$ ip link show dev OLD_IFACE
3: OLD_IFACE: <BROADCAST,MULTICAST> ...
Some network managers can bring the interface back up while you are working. If that happens, stop or pause the manager using your distribution's normal maintenance procedure, then confirm the interface is still down. Do not blindly add a service-specific command to this guide: the correct unit differs between installations.
5. Apply the MAC-based rename
Run nameif with elevated privileges while the target is down. With no arguments it reads /etc/mactab and processes its entries.
$ sudo nameif
$ ip link show dev NEW_IFACE
3: NEW_IFACE: <BROADCAST,MULTICAST> ...
link/ether 90:1b:0e:da:cc:ef brd ff:ff:ff:ff:ff:ff
A successful run normally prints nothing. Verify both the new name and the MAC address. If nameif reports an error, do not bring the interface up yet. Check the spelling, MAC address, duplicate names, permissions and interface state first.
For a one-off rename, the command-line form avoids changing /etc/mactab:
$ sudo nameif NEW_IFACE 90:1b:0e:da:cc:ef
For a different configuration file, use -c with its path:
$ sudo nameif -c /path/to/mactab NEW_IFACE 90:1b:0e:da:cc:ef
Do not combine a one-off test with a stale file entry unless you have checked every entry that the chosen mode will process.
6. Restore service and check dependent configuration
Renaming changes the identifier used by later commands. Update any network-manager profile, firewall rule, routing script or monitoring rule that still refers to OLD_IFACE. Then bring the new interface up and verify it:
$ sudo ip link set dev NEW_IFACE up
$ ip -br link show dev NEW_IFACE
NEW_IFACE UP 90:1b:0e:da:cc:ef <BROADCAST,MULTICAST,UP,LOWER_UP>
$ ip addr show dev NEW_IFACE
3: NEW_IFACE: ...
link/ether 90:1b:0e:da:cc:ef ...
The exact flags and address lines depend on the host. If a network service owns the interface, use that service's normal reload or reconnect operation after its configuration has been updated. A renamed link does not automatically receive the old link's IP configuration from every network manager.
7. Recover from a failed or unwanted rename
If the rename failed, leave the interface down and inspect the error before retrying. The most common trap is running while the interface is up, which the manual says will fail.
To undo a successful rename, use the old name and the same MAC address in a temporary or edited configuration, again while the interface is down:
$ sudo ip link set dev NEW_IFACE down
$ sudo nameif OLD_IFACE 90:1b:0e:da:cc:ef
$ ip link show dev OLD_IFACE
3: OLD_IFACE: <BROADCAST,MULTICAST> ...
link/ether 90:1b:0e:da:cc:ef ...
If /etc/mactab is now the permanent source of the new name, edit or remove that entry before the next boot or rename attempt. Removing a configuration line is a deliberate change: keep a backup until the replacement network configuration has been tested.
Done means
- You matched the target Ethernet interface by its actual MAC address.
- You chose a name that was not already in use.
- You recorded the mapping in
/etc/mactabor used the one-off command form. - You brought the interface down before running
nameif. - You verified the new name and MAC, then updated dependent network configuration.
- You know how to rename it back if the new name causes a problem.