1 AUTHOR: Richard A Downing FBCS <geek109@yahoo.co.uk>
5 LICENSE: GNU Free Documentation License Version 1.2
7 SYNOPSIS: Naming Network Interfaces.
10 This hint describes how to specify your own names for Network
11 Interface Cards instead of eth0, eth1, etc...
14 In principle the hint applies to all versions of LFS, and probably also
15 to all LINUX distributions. However, the bootscript recommendations are
16 based on LFS-Bootscripts-1.11 (LFS-4.1).
23 When the Linux kernel boots, it assigns names (eth0 etc..) to
24 network devices in the order that it finds them. This means that two
25 different versions of the kernel, say 2.4 and 2.6, might find the network
26 interfaces in a diffent order. When this happens you might have to
27 swap all the cables to get your connections to work the way you want.
28 The proper way to do this is to name the interfaces with the nameif
29 command (part of the net-tools).
31 TAKE CARE: All the commands given in this hint need root priviledges.
36 The nameif command can be driven from the command line, if you want to
37 do that, then read it's man page. Another way is to set up a
38 /etc/mactab file to relate the MAC addresses of the network cards to
41 Every NIC interface in the (known) universe has a unique MAC address
42 (Media Access Control address), which is usually expressed as a 12 digit
43 hexadecimal number, colon-dotted in pairs for readability.
45 You will need to find the MAC addresses of each of your network cards.
46 The easiest way to find these (if you didn't make a note of the MAC
47 label when you installed the card) is to use ifconfig, each interface
48 that is configured will report its MAC address. e.g:
51 eth0 Link encap:Ethernet HWaddr 00:60:97:52:9A:94
52 inet addr:192.168.1.3 Bcast:192.168.1.255 Mask:255.255.255.0
53 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
54 RX packets:6043 errors:0 dropped:0 overruns:0 frame:0
55 TX packets:6039 errors:0 dropped:0 overruns:0 carrier:0
56 collisions:0 txqueuelen:100
57 RX bytes:1439604 (1.3 Mb) TX bytes:509857 (497.9 Kb)
58 Interrupt:10 Base address:0xc800
60 lo Link encap:Local Loopback
61 inet addr:127.0.0.1 Mask:255.0.0.0
62 UP LOOPBACK RUNNING MTU:16436 Metric:1
63 RX packets:7218 errors:0 dropped:0 overruns:0 frame:0
64 TX packets:7218 errors:0 dropped:0 overruns:0 carrier:0
65 collisions:0 txqueuelen:0
66 RX bytes:1085452 (1.0 Mb) TX bytes:1085452 (1.0 Mb)
68 Take note of the HWaddr, this the NIC's MAC address.
70 Now you can decide what you would like the NIC to be called, and set
71 up your /etc/mactab, here's mine as an example:
74 # This file relates MAC addresses to interface names.
75 # We need this so that we can force the name we want
76 # even if the kernel finds the interfaces in the
79 # eth0 under 2.4, eth1 under 2.6
80 beannet 00:60:97:52:9A:94
82 # eth1 under 2.4, eth0 under 2.6
83 sparenet 00:A0:C9:43:8F:77
87 If you run nameif (without parameters) now you will probably get an
88 error message, since nameif must be run when the interfaces are down.
91 cannot change name of eth0 to beannet: Device or resource busy
93 so, first take the interface down, then rename it:
99 beannet Link encap:Ethernet HWaddr 00:60:97:52:9A:94
100 inet addr:192.168.1.3 Bcast:192.168.1.255 Mask:255.255.255.0
101 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
102 RX packets:6617 errors:0 dropped:0 overruns:0 frame:0
103 TX packets:6596 errors:0 dropped:0 overruns:0 carrier:0
104 collisions:0 txqueuelen:100
105 RX bytes:1748349 (1.6 Mb) TX bytes:598513 (584.4 Kb)
106 Interrupt:10 Base address:0xc800
108 lo Link encap:Local Loopback
109 inet addr:127.0.0.1 Mask:255.0.0.0
110 UP LOOPBACK RUNNING MTU:16436 Metric:1
111 RX packets:9097 errors:0 dropped:0 overruns:0 frame:0
112 TX packets:9097 errors:0 dropped:0 overruns:0 carrier:0
113 collisions:0 txqueuelen:0
114 RX bytes:1340480 (1.2 Mb) TX bytes:1340480 (1.2 Mb)
117 LFS Bootscript Changes
118 ======================
120 As we've seen, nameif needs to be run early in the boot cycle, before
121 the network interfaces are brought up. This means adding it to
122 /etc/rc.d/init.d/network.
124 Edit the start of the file as follows:
127 # Begin $rc_base/init.d/network - Network Control Script
129 # Based on ethnet script from LFS-3.1 and earlier.
130 # Rewritten by Gerard Beekmans - gerard@linuxfromscratch.org
132 source /etc/sysconfig/rc
134 source /etc/sysconfig/network
138 if [ -e /etc/mactab ]
140 # if /etc/mactab exists then set up the named interfaces
143 for file in $(grep -il "ONBOOT=yes" $network_devices/ifconfig.*)
147 This ensures that nameif is run with /etc/mactab, if that file exists.
149 Now go to /etc/sysconfig and change the name(s) of the interface(s) wherever
150 it(they) occur(s). I made the following changes:
152 1) edit /etc/sysconfig/network to specify the renamed GATEWAY_IF.
153 2) rename /etc/network-devices/ifconfig.eth0 to ifconfig.yourname and
154 edit it so that DEVICE=yourname.
156 If you use the Beyond Linux From Scratch instructions to use DHCP,
157 then you will need to substitute your new NIC names in the scripts and
158 filenames in the appropriate places.
161 * Kevin Fleming for pointing the nameif command out to me.