Change Network Interface Name: eth0,eth1,eth2+

The best way to rename a network interface is through udev.

Edit the file /etc/udev/rules.d/70-persistent-net.rules to change the interface name of a network device.

The names of the network devices are listed in this file as follows:

# PCI device 0x11ab:0x4363 (sky2)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*",
ATTR{address}=="00:00:00:00:00:00",ATTR{dev_id}=="0x0", ATTR{type}=="1",
KERNEL=="eth*", NAME="eth0"

Rename network interface from eth0 to wan0

To rename interface eth0 to wan0, edit /etc/udev/rules.d/70-persistent-net.rules file and change NAME="eth0" to NAME="wan0".

# PCI device 0x11ab:0x4363 (sky2)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*",
ATTR{address}=="00:00:00:00:00:00",ATTR{dev_id}=="0x0", ATTR{type}=="1",
KERNEL=="eth*", NAME="wan0"

For Centos/RHEL etc.

Rename the network interface configuration file:

# cd etc/sysconfig/network-scripts/
# mv ifcfg-eth0 ifcfg-wan0

Edit the network interface configuration file and replace all occurrences of the old name eth0 with the new one wan0:

# vi /etc/sysconfig/network-scripts/ifcfg-wan0

For Ubuntu etc.

Edit the /etc/network/interfaces file and replace all occurrences of the old name eth0 with the new one wan0:

# sudo nano /etc/network/interfaces

Test changes

Reboot the system to test changes:

# reboot

Verify new settings:

# ifconfig -a

Rename network interface from eth1 back to eth0

Q: Why does my network interface name change?
A: The interface name of a network device increases if the MAC address of a network card changes.

Edit the file /etc/udev/rules.d/70-persistent-net.rules.

Copy the new MAC address from eth1 to the line of your eth0 rule.

Delete the rule for eth1. Save and close the file.

For Centos/RHEL etc.

Check the network interface configuration located under:

# vi /etc/sysconfig/network-scripts/ifcfg-eth0

Don’t forget to replace the old MAC address with the new one.

For Ubuntu etc.

Make sure /etc/network/interfaces file has correct configuration:

# sudo nano /etc/network/interfaces

Test changes

Reboot the system to test changes:

# reboot

Verify new settings:

# ifconfig -a

HowTo: Change Speed and Duplex of Ethernet card in Linux

To change Speed and Duplex of an ethernet card, we can use ethtool – a Linux utility for Displaying or Changing ethernet card settings.

1. Install ethtool

You can install ethtool by typing one of the following commands, depending upon your Linux distribution.

Install ethtool in Fedora, CentOS, RHEL etc.:

# yum install ethtool

Install ethtool in Ubuntu, Debian etc.:

# sudo apt-get install ethtool

2. Get the Speed, Duplex and other information for the interface eth0

To get speed, duplex and other information for the network interface eth0, type the following command as root.

# ethtool eth0

Sample output:

Settings for eth0:
	Supported ports: [ MII ]
	Supported link modes:   10baseT/Half 10baseT/Full 
	                        100baseT/Half 100baseT/Full 
	                        1000baseT/Half 1000baseT/Full 
	Supports auto-negotiation: Yes
	Advertised link modes:  10baseT/Half 10baseT/Full 
	                        100baseT/Half 100baseT/Full 
	                        1000baseT/Half 1000baseT/Full 
	Advertised auto-negotiation: Yes
	Speed: 100Mb/s
	Duplex: Half
	Port: Twisted Pair
	PHYAD: 1
	Transceiver: internal
	Auto-negotiation: on
	Supports Wake-on: g
	Wake-on: d
	Current message level: 0x000000ff (255)
	Link detected: yes

3. Change the Speed and Duplex settings

The following changes are temporary and they’ll stop working after reboot. Read the next section, to make settings permanent.

The next command enables Auto-Negotiate feature:

# ethtool -s eth0 autoneg on

The next command disables Auto-Negotiation, enables Half Duplex and sets up Speed to 10 Mb/s:

# ethtool -s eth0 speed 10 duplex half autoneg off

The next command disables Auto-Negotiation, enables Full Duplex and sets up Speed to 100 Mb/s:

# ethtool -s eth0 speed 100 duplex full autoneg off

4. Change the Speed and Duplex settings Permanently on CentOS/RHEL

To make settings permanent, you need to edit /etc/sysconfig/network-scripts/ifcfg-eth0 file for eth0 interface. This file is used by RHEL, CentOS, Fedora etc.

# vi /etc/sysconfig/network-scripts/ifcfg-eth0

Append the line as follows to disable Auto-Negotiation, enable Full Duplex and set up Speed to 100 Mb/s:

ETHTOOL_OPTS="speed 100 duplex full autoneg off"

Restart the interface to apply changes:

# ifdown eth0 && ifup eth0

Configuring Network on CentOS/RHEL — Basic Configuration

Interface configuration files control the software interfaces for individual network devices.

As the system boots, it uses these files to determine what interfaces to bring up and how to configure them.

These files are usually named ifcfg-<name>, where <name> refers to the name of the device that the configuration file controls.

Because each device has its own configuration file, an administrator can control how each interface functions individually.

Configure Network Interface Settings

You can configure network interface by editing configuration files stored in /etc/sysconfig/network-scripts/ directory.

Lets configure the first network interface eth0. Edit the interface configuration file.

# vi /etc/sysconfig/network-scripts/ifcfg-eth0

Append/Modify as follows:

For a system using a Static IP Address

DEVICE="eth0"
BOOTPROTO="none"
ONBOOT="yes"
IPADDR="192.168.1.15"
NETMASK="255.255.255.0"
GATEWAY="192.168.1.1"

For a system using a DHCP

DEVICE="eth0"
BOOTPROTO="dhcp"
ONBOOT="yes"

Parameter

Description

DEVICE=<name> Name of the physical device
BOOTPROTO=<none|bootp|dhco> Protocol to use.
none – No boot-time protocol should be used
bootp – The BOOTP protocol should be used
dhcp – The DHCP protocol should be used
ONBOOT=<yes|no> Should the device be activated at boot-time
IPADDR=<address> IP address
GATEWAY=<address> Gateway IP address
NETMASK=<mask> Netmask value

Configure Networking

Edit the main network configuration file:

# vi /etc/sysconfig/network

Append the following settings:

NETWORKING="yes"
HOSTNAME="Your.Server.Name"

Restart networking:

# /etc/init.d/network restart

If the modifying of the file /etc/sysconfig/network is not needed, then you can restart only the interface:

# ifdown eth0 && ifup eth0

Configure DNS settings

Edit ‘resolv.conf’ file:

# vi /etc/resolv.conf

Append your DNS servers:

nameserver 192.168.1.2
nameserver 192.168.1.3

If you don’t have private DNS servers, you can pick them from a list of Free Fast Public DNS Servers

Test Your Settings

Check if the Gateway is reachable:

# ping 192.168.1.1

Check if the Public IPs are reachable:

# ping 8.8.8.8

Check if DNS works:

# nslookup google.com