Reassigning network device names

收藏待读

Reassigning network device names

I recently wanted to experiment with one of my machines by adding a second network card and using it to forward packets from one network to another.

I installed the new network card and rebooted, but found I could not access the system over the network. It worked just now – what』s gone wrong this time? Logging in on the console I discovered that there was a problem with the device names assigned to each network cards.

ip addr

1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default 

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

inet 127.0.0.1/8 scope host lo

valid_lft forever preferred_lft forever

inet6 ::1/128 scope host 

valid_lft forever preferred_lft forever

2: eth0:  mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000

link/ether 00:50:8b:bb:63:51 brd ff:ff:ff:ff:ff:ff

3: eth1:  mtu 1500 qdisc mq state UP group default qlen 1000

link/ether 00:40:ca:75:fe:91 brd ff:ff:ff:ff:ff:ff

It immediately became apparent that the reason I couldn』t connect was that the network isn』t connected (status shows as NO-CARRIER) and so the interface hasn』t been able to obtain an IP address. Since I hadn』t connected the second network card to anything yet it quickly became obvious that when I rebooted after inserting the second network card the device names had been changed. A quick check confirmed that the second network interface had been assigned the 『wrong』 device name.

cat /etc/udev/rules.d/70-persistent-net.rules

# PCI device 0x8086:0x1229 (e100)

SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”00:50:8b:bb:63:51″, ATTR{dev_id}==”0x0″, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth0″

The solution was to change the device name for the second network interface and add a new entry for the original network interface using the MAC addresses for each card shown above.

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

# PCI device 0x14e4:0x1696 (tg3)

# PCI device 0x8086:0x1229 (e100)

SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”00:50:8b:bb:63:51″, ATTR{dev_id}==”0x0″, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth0″

SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”00:50:8b:bb:63:51″, ATTR{dev_id}==”0x0″, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth1″

Remember the MAC addresses used to identify the network cards are unique – yours will be different!

Note – I used the following command to obtain the device IDs.

# lspci -nn

00:00.0 Host bridge [0600]: Intel Corporation 82865G/PE/P DRAM Controller/Host-Hub Interface [8086:2570] (rev 02)

00:02.0 VGA compatible controller [0300]: Intel Corporation 82865G Integrated Graphics Controller [8086:2572] (rev 02)

00:06.0 System peripheral [0880]: Intel Corporation 82865G/PE/P Processor to I/O Memory Interface [8086:2576] (rev 02)

00:1d.0 USB controller [0c03]: Intel Corporation 82801EB/ER (ICH5/ICH5R) USB UHCI Controller #1 [8086:24d2] (rev 02)

00:1d.1 USB controller [0c03]: Intel Corporation 82801EB/ER (ICH5/ICH5R) USB UHCI Controller #2 [8086:24d4] (rev 02)

00:1d.2 USB controller [0c03]: Intel Corporation 82801EB/ER (ICH5/ICH5R) USB UHCI Controller #3 [8086:24d7] (rev 02)

00:1d.7 USB controller [0c03]: Intel Corporation 82801EB/ER (ICH5/ICH5R) USB2 EHCI Controller [8086:24dd] (rev 02)

00:1e.0 PCI bridge [0604]: Intel Corporation 82801 PCI Bridge [8086:244e] (rev c2)

00:1f.0 ISA bridge [0601]: Intel Corporation 82801EB/ER (ICH5/ICH5R) LPC Interface Bridge [8086:24d0] (rev 02)

00:1f.1 IDE interface [0101]: Intel Corporation 82801EB/ER (ICH5/ICH5R) IDE Controller [8086:24db] (rev 02)

00:1f.2 IDE interface [0101]: Intel Corporation 82801EB (ICH5) SATA Controller [8086:24d1] (rev 02)

00:1f.3 SMBus [0c05]: Intel Corporation 82801EB/ER (ICH5/ICH5R) SMBus Controller [8086:24d3] (rev 02)

00:1f.5 Multimedia audio controller [0401]: Intel Corporation 82801EB/ER (ICH5/ICH5R) AC’97 Audio Controller [8086:24d5] (rev 02)

05:02.0 Ethernet controller [0200]: Broadcom Corporation NetXtreme BCM5782 Gigabit Ethernet [14e4:1696] (rev 03)

05:04.0 Ethernet controller [0200]: Intel Corporation 82557/8/9/0/1 Ethernet Pro 100 [8086:1229] (rev 08)

I then configured the new network card and rebooted…

nano /etc/network/interfaces

# This file describes the network interfaces available on your system

# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface

auto lo

iface lo inet loopback

# The primary network interface

allow-hotplug eth0

iface eth0 inet dhcp

# The secondary network interface

allow-hotplug eth1

#iface eth1 inet dhcp

iface eth1 inet static

address 172.16.0.1

netmask 255.255.255.0

reboot

Checking the network addresses after the reboot shows that the changes worked.

ip addr

1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default 

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

inet 127.0.0.1/8 scope host lo

valid_lft forever preferred_lft forever

inet6 ::1/128 scope host 

valid_lft forever preferred_lft forever

2: eth1:  mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000

link/ether 00:50:8b:bb:63:51 brd ff:ff:ff:ff:ff:ff

inet 172.16.0.1/24 brd 172.16.0.255 scope global eth1

valid_lft forever preferred_lft forever

3: eth0:  mtu 1500 qdisc mq state UP group default qlen 1000

link/ether 00:40:ca:75:fe:91 brd ff:ff:ff:ff:ff:ff

inet 192.168.16.162/24 brd 192.168.16.255 scope global eth0

valid_lft forever preferred_lft forever

inet6 fe80::240:caff:fe75:fe91/64 scope link 

valid_lft forever preferred_lft forever

相關閱讀

免责声明:本文内容来源于mike632t,已注明原文出处和链接,文章观点不代表立场,如若侵犯到您的权益,或涉不实谣言,敬请向我们提出检举。