Posts Tagged ‘cards’

How to change order of network cards eth0 and eth0 (swap lan cards) on Debian GNU / Linux

Friday, September 21st, 2012

Swap eth0 and eth1 lan card / how to change network card order on Debian Gnu / linux

I have a Debian server with 2 network adapter cards – (eth0 and eth1). The first lan card eth0 is Mainboard embedded (integrated) one.

The hardware of the Lenovo ThinkCentre host was purchased with one LAN Card but a second one was added in order to make the machine capable of doing NAT routing with iptables.

The machine is to be configured as a router in 1st lan card eth0, an internet UTP cable should influx and the 2nd lan card is to be connected to a Network Switch and will be used to NAT network traffic from the internal network of number of hosts with assigned local IP addresses like (192.168.0.1 – 255) etc.

Everyone knows that integrated Network cards, are usually inferior to the normal non-integrated ones and besides that if a high voltage (during Weather Storm) enters through UTP cable attached to the integrated LAN Card it is quite likely the whole Mainboard to burn out …

With saying this back to my case I had to make the Internet to connect on eth0 on a Debian Linux host which was supposed to run as a Network router. As eth0 was the one where I had to configure the Internet real IP address to be assigned, I preferred eth0 to be attached to the non-integrated Ethernet Card which was automatically recognized and assigned to be eth1 by kernel.

Therefore I needed to swap interfaces eth0 and eth1, here is how this is done on Debian GNU / Linux Squeeze (6.0.5):

1. Edit /etc/udev/rules.d/70-persistent-net.rules


# vim /etc/udev/rules.d/70-persistent-net.rules

The file content should look something similar to:


# This file was automatically generated by the
/lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.
# PCI device 0x10ec:0x8168 (r8169)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*",
ATTR{address}=="90:f6:C2:3d:76:f5", ATTR{dev_id}=="0x0",
ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x10ec:0x8168 (r8169)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*",

ATTR{address}=="8d:89:a5:c2:e8:f8", ATTR{dev_id}=="0x0",

ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

Swap eth0 and eth1 definitions so eth0 becomes eth1 and vice versa, e.g.:


SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*",

ATTR{address}=="8d:89:a5:c2:e8:f8", ATTR{dev_id}=="0x0",

ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*",
ATTR{address}=="90:f6:C2:3d:76:f5", ATTR{dev_id}=="0x0",
ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

To make udevd, reassign eth0 / eth1 cards orders restart udev daemon:


# /etc/init.d/udev restart
...

or restart the system, i.e.


# restart

That should swap the Lan card order as recognized by Linux. Cheers 😉