Renaming Default eth0

The above short tutorial shows how to rename the default Network Interface Cards (NIC) label with your own names instead of eth0, eth1..etc. This may be useful for those who have multi number of NIC cards listening on different networks. Setting up your own names may helpful for easy identification.

 

Renaming EthX

 

Though various tutorials are available online, i found the following steps are easier and error free and also works well in various Linux Distributions. The following steps how to rename the eth0 using the nameif command (comes with net-tools package, you can install it using yum install net-tools) and how to setup it on boot.

 

Use the ifconfig command to find the current interace names and the hardware address(HWaddr). An example screen-caps below.

 

Default-Eth0

 

Edit or create a new file (/etc/mactab) using your favorite editor and add the following lines(i have renamed eth0 to gnutoolbox in the below example so make sure you are adding your own name instead of gnutoolbox).

 

# The 00:11:D8:xx:xx:xx is the HWaddr
gnutoolbox 00:11:D8:xx:xx:xx

 

Now run the nameif command

 

  • # nameif

 

You will be getting the following error

 

cannot change name of eth0 to gnutoolbox: Device or resource busy

 

So, first take the interface down, then rename it.

 

Warning : If you have connected the server using ssh remotly you will lose the connection (you need to do this on TTY)

 

  • # ifconfig eth0 down
    # nameif
    # ifconfig gnutoolbox up
    # ifconfig

 

The output will look below like the below screen-caps.

 

Renamed Eth0

 

 

Making the changes permanent at boot time

 

Nameif needs to be run early in the boot cycle, before the network interfaces are brought up.  This means adding it to /etc/rc.d/init.d/network . Edit the start of the file as follows:

 

#!/bin/bash
# Begin $rc_base/init.d/network – Network Control Script

# Based on ethnet script from LFS-3.1 and earlier.
# Rewritten by Gerard Beekmans  – [email protected]

source /etc/sysconfig/rc
source $rc_functions
source /etc/sysconfig/network

case “$1” in
start)
if [ -e /etc/mactab ]
then
# if /etc/mactab exists then set up the named interfaces
nameif
fi
for file in $(grep -il “ONBOOT=yes” $network_devices/ifconfig.*)
do

 

This ensures that nameif is run with /etc/mactab, if that file exists.

 

Now go to /etc/sysconfig/network-scripts directory and rename /etc/sysconfig/network-scripts/ifcfg-eth0 interface file to ifconfig.yourname and edit it so that DEVICE=yourname.