How to Swap eth0 and eth1 Interface Names in Ubuntu Server for Proper Network Configuration


2 views

During Ubuntu Server installations, the system sometimes assigns interface names in a counterintuitive order - particularly when mixing onboard and PCI network cards. In this case, we have:

  • eth1: Motherboard NIC (should be primary/eth0)
  • eth0: PCI NIC (should be secondary/eth1)

While the current configuration technically works (eth1 gets DHCP while eth0 remains inactive), it violates standard network administration conventions where primary interfaces should be eth0.

Modern Ubuntu versions use udev rules to persistently name network interfaces based on:

  1. PCI bus enumeration order
  2. MAC addresses
  3. Physical port locations

We can override this behavior through udev rules or GRUB configuration.

Create or modify the udev rules file:

sudo nano /etc/udev/rules.d/70-persistent-net.rules

Modify the existing entries to swap the interface names. For example:

# PCI card (original eth0)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:1a:2b:3c:4d:5e", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

# Onboard NIC (original eth1)  
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:1f:2e:3d:4c:5b", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

Apply the changes:

sudo udevadm trigger --action=add
sudo udevadm control --reload-rules

For systems using predictable interface names (Ubuntu 15.10+):

sudo nano /etc/default/grub

Add to GRUB_CMDLINE_LINUX:

GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"

Update GRUB and reboot:

sudo update-grub
sudo reboot

After applying either method, verify the interface naming:

ip link show
# or
ifconfig -a

You should now see:

  • Motherboard NIC as eth0
  • PCI NIC as eth1

During Ubuntu Server 8.04 LTS installation, the system sometimes detects network interfaces in reverse order - assigning eth1 to the onboard NIC and eth0 to the PCI card. This becomes problematic when:

  • You need consistent interface naming across multiple servers
  • Network configurations assume specific interface ordering
  • Virtual machines depend on particular physical NIC assignments

Ubuntu traditionally uses the ethX naming scheme based on:

1. The order of NIC detection during kernel initialization
2. The PCI device enumeration sequence
3. The driver loading order

Create a custom udev rules file to enforce consistent naming:

sudo nano /etc/udev/rules.d/70-persistent-net.rules

Add rules similar to this (replace MAC addresses with your actual values):

# PCI NIC (current eth0) → new eth1
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", 
ATTR{address}=="00:1a:2b:3c:4d:5e", NAME="eth1"

# Onboard NIC (current eth1) → new eth0  
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*",
ATTR{address}=="00:0f:1e:2d:3c:4b", NAME="eth0"

Modify /etc/network/interfaces to reflect the new names:

auto eth0
iface eth0 inet dhcp

auto eth1
iface eth1 inet static
    address 192.168.1.1
    netmask 255.255.255.0

After reboot, verify with:

ip link show
ifconfig -a

Common issues and fixes:

  • If interfaces don't rename: Check MAC addresses in udev rules
  • If networking fails: Verify interface names in all config files
  • For VM passthrough: Update bridge configurations if used

For older systems, you can try boot parameters:

sudo nano /etc/default/grub
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"
sudo update-grub

This forces traditional ethX naming but may affect other systems.