I suppose the first thing that comes to mind is Why? For one, if you have a lot of network adaptors, it's easier to manage. You can name an adaptor related to the task it performs: this way, if you need to stop it for whatever reason, you can simply stop eth_database instead of eth2 - you don't need to remember which is which. Second, if something changes in the kernel, such as the loading order of the modules, or you add a new adaptor, your existing interfaces will not get renumbered on you. That can save some headaches as well.
I've created this thread in response to this thread.
The example will be based on what I was trying to do: set up a new server that has 3 network adaptors doing various things:
NIC 0: LAN (Static IP)
NIC 1: WAN (Dynamic IP, this always retrieves me my 'public' IP address for the server.)
NIC 2: DBMS (Static IP, crossover cabled to a database server - figured this was the best way... less points of failure [i.e. a switch])
Keep in mind that you can name these devices however you want, just remember to change the names in this example to suit your needs.
Step 1: Identify your network devices
First, you need figure out what physical port is which MAC address. In my case, I unplugged all the cables, and plugged each interface in one at a time to figure out what exactly udev has done with the mapping. What I did after plugging in and starting/stopping the net.eth* scripts was I made myself a little chart:
Code: Select all
Current
udev Physical Location
Device MAC ADDRESS (back of PC) New Mapping
-------- ----------------- ------------------- ---------------
eth0 00:30:BD:BB:25:E8 Bottom eth_dbms
eth1 00:20:ED:68:45:EC Top eth_lan
eth2 00:50:BF:AE:E9:DC Middle eth_wan
Code: Select all
# udevinfo -a -p /sys/class/net/eth0 | grep address
SYSFS{address}=="00:30:bd:bb:25:e8"
# udevinfo -a -p /sys/class/net/eth1 | grep address
SYSFS{address}=="00:20:ed:68:45:ec"
# udevinfo -a -p /sys/class/net/eth2 | grep address
SYSFS{address}=="00:50:bf:ae:e9:dc"
Step 2: Setting up udev for static / custom name mapping
Now that we have the MAC addresses, and what I want to name them in the nifty chart I made for myself earlier, time to go set up a rules file:
/etc/udev/rules.d/10-local.rules:
Code: Select all
SUBSYSTEM=="net", ATTR{address}=="00:20:ed:68:45:ec", NAME="eth_lan"
SUBSYSTEM=="net", ATTR{address}=="00:50:bf:ae:e9:dc", NAME="eth_wan"
SUBSYSTEM=="net", ATTR{address}=="00:30:bd:bb:25:e8", NAME="eth_dbms"
Now, udev knows how we want to map devices.
Step 3: Changing initscripts to reflect device name changes
Next we need to tell the gentoo initscripts to follow suit:
/etc/conf.d/net:
Code: Select all
# This blank configuration will automatically use DHCP for any net.*
# scripts in /etc/init.d. To create a more complete configuration,
# please review /etc/conf.d/net.example and save your configuration
# in /etc/conf.d/net (this file :]!).
config_eth_wan=( "dhcp" )
config_eth_lan=( "192.168.247.80/24" )
routes_eth_lan=( "default via 192.168.247.1" )
config_eth_dbms=( "192.168.240.100/24" )
Code: Select all
# /etc/init.d/net.eth0 stop
# /etc/init.d/net.eth0 zap
# /etc/init.d/net.eth1 stop
# /etc/init.d/net.eth1 zap
# /etc/init.d/net.eth2 stop
# /etc/init.d/net.eth2 zap
# rc-update del net.eth0 default
# rc-update del net.eth1 default
# rc-update del net.eth2 default
# rm /etc/init.d/net.eth0
# rm /etc/init.d/net.eth1
# rm /etc/init.d/net.eth2
# cd /etc/init.d
# ln -s net.lo net.eth_lan
# ln -s net.lo net.eth_wan
# ln -s net.lo net.eth_dbms
After this, the system is now reconfigured! Reboot to test the new udev mapping. Once the system is back up, run ifconfig to see if everything was moved over:
Code: Select all
# ifconfig -a
eth_dbms Link encap:Ethernet HWaddr 00:30:BD:BB:25:E8
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Interrupt:12 Base address:0xe800
eth_lan Link encap:Ethernet HWaddr 00:20:ED:68:45:EC
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Interrupt:10 Base address:0xd400
eth_wan Link encap:Ethernet HWaddr 00:50:BF:AE:E9:DC
BROADCAST NOTRAILERS RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1898 errors:0 dropped:0 overruns:0 frame:0
TX packets:711 errors:1 dropped:0 overruns:0 carrier:2
collisions:0 txqueuelen:1000
RX bytes:134086 (130.9 Kb) TX bytes:79642 (77.7 Kb)
Interrupt:10 Base address:0xec00
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Code: Select all
# /etc/init.d/net.eth_wan start
* Starting eth_wan
* Bringing up eth_wan
* dhcp
* Running dhcpcd ...
* eth_wan received address 192.168.247.12
# /etc/init.d/net.eth_lan start
* Starting eth_lan
* Bringing up eth_lan
* 192.168.247.80/24
* Adding routes
* default gw 192.168.247.1 ...
# /etc/init.d/net.dbms start
* Starting eth_dbms
* Bringing up eth_dbms
* 192.168.240.100/24
Step 5: Adding the new scripts to the appropriate runlevel[s]
If your configuration is working correctly, all you need to do is add the initscripts to the appropriate runlevel so they start at boot time (this step is optional if you are using netplug/ifplug/a daemon to run scripts when a cord is plugged in):
Code: Select all
# rc-update add net.eth_wan default
# rc-update add net.eth_lan default
# rc-update add net.eth_dbms default
Now you should be able to use the new device names with other tools:
Code: Select all
# ifconfig eth_wan
eth_wan Link encap:Ethernet HWaddr 00:50:BF:AE:E9:DC
inet addr:192.168.247.12 Bcast:192.168.247.255 Mask:255.255.255.0
UP BROADCAST NOTRAILERS RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2494 errors:0 dropped:0 overruns:0 frame:0
TX packets:966 errors:1 dropped:0 overruns:0 carrier:2
collisions:0 txqueuelen:1000
RX bytes:180146 (175.9 Kb) TX bytes:114621 (111.9 Kb)
Interrupt:10 Base address:0xec00
Step 7: Conclusion
There you have it, a nifty little guide that details what you need to statically map (or rename) your ethernet devices. Hopefully people will find this useful; I know I sure did!





