Renaming a network interface on Linux


Sometimes, when you add/remove a network card in Linux, the system automatically change the name of the interfaces (for example your eth0 became eth1). Depending of the system, it can cause a big problem to you, so you can use the command nameif to rename it back (or just rename your interfaces):

Create a file named /etc/mactab with the interface names and its mac address:
eth0 00:0B:DB:D5:6E:DD
eth1 00:03:47:3b:ef:b9
eth2 00:0B:DB:D5:6E:DE
banana01 00:03:47:3B:EF:B8

After that, you should run the command nameif (/sbin/nameif) to apply your new configuration.

Note 01: you can rename your interfaces to whatever you want.
Note 02a: before run the nameif, you should stop the interfaces.
Note 02b: you can do an ifdown <interface>
Note 03: if you reboot the server, this configuration will be lost, so you can create a simple shell script to rename it automatically on boot:

vi /etc/init.d/nameif
#!/bin/bash

case "$1" in
start)
    echo "Renaming the network interfaces..."
    /sbin/nameif
;;

stop)
    echo "Ok"
;;
esac

chmod 755 /etc/init.d/nameif
ln -s /etc/init.d/nameif /etc/rc3.d/S04nameif

I know that you can use udev to rename an interface, but I believe that nameif is simpler.

  1. No comments yet.
(will not be published)