http://www.jms1.net/ifcfg.html

RedHat "ifcfg-eth?" Information

I'm running RedHat 8.0 on my laptop, and I have a wireless network at home. I have an assortment of wired and wireless ethernet cards, and sometimes switch from wired to wireless (or vice-versa) while I'm in the middle of something and don't want to reboot.

I also use static IP addresses for everything, which makes it easy for my machines to access each other.

I was having a problem where, when switching from a wired card to a wireless card, the computer was using the same IP address for the new card (because they are both "eth0") but the other devices on the network (including the AP/router itself) wouldn't recognize the new card because their arp tables had an existing entry which linked the IP address to the old card's MAC address.

There are three ways around this problem:

RedHat's Scripts

When RedHat initializes an interface (as the system boots or when a new PCMCIA card is inserted), it runs a set of scripts to read some configuration files and set the card up. These scripts are located in the /etc/sysconfig/network-scripts directory, and the file containing the configuration for the eth0 interface is called ifcfg-eth0.

These are two samples of what the file would normally look like, one for a machine which is a DHCP client, and one for a machine with a static IP address:

DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes

DEVICE=eth0
BOOTPROTO=static
BROADCAST=192.168.0.255
IPADDR=192.168.0.88
NETMASK=255.255.255.0
NETWORK=192.168.0.0
ONBOOT=yes

At first glance, it looks like just a list of settings... and pretty much that's all it is.

However, what actually happens is that this file is "sourced", or executed as if it were a shell script, which means that these are not just lines of text- these are commands, which set the variables that other scripts use to do the actual work of bringing up the interface.

Why does this matter, you may ask? Because it's actually a bunch of commands, you can do more than just assign values to variables. You can run other programs and return different values in these variables based on certain criteria.

For my purposes, I needed to assign a different static IP address for each card I use.

Differences in the Cards

There are three major differences between the cards that I use: the MAC addresses, the kernel modules which are used by each card, and the obvious "wired or wireless" distinction.

There is no easy way (that I know of) to determine which module is used by a particular interface, but there are two easy ways to get the MAC address of an interface: the ifconfig command, and the ip link show command (which may be a RedHat thing, I'm not sure.)

New Script

I have written a new version of the ifcfg-eth0 script on my laptop, which uses the MAC address of the card to figure out which IP address to assign (or whether to use DHCP, which I do use from time to time.)

While digging through RedHat's scripts I also found a function which can tell if the card is wired or wireless. I'm using this to tell whether or not to add the wireless configuration. For my purposes it's a simple case of "use it" or "don't use it", but I can see a situation where somebody uses different wireless cards at home and at work, and needs different encryption keys for both locations. It would be simple to modify the script to assign different parameters for different cards.

###############################################################################
#
# ifcfg-eth0
# jms1 2002-11-11
#
# configures specific settings for certain cards
# defaults to DHCP for unknown card
#
# also configures wireless security parameters for wireless cards

DEVICE=eth0
ONBOOT=yes
PEERDNS=no

###############################################################################
#
# figure out which card this is

MAC=`ip link show $INTERFACE | egrep ether | awk '{print $2}'`

if echo $MAC | egrep -q '^00:50:04' ; then   # 3COM 3C574

    BOOTPROTO=static
    IPADDR=192.168.0.6
    NETMASK=255.255.255.0
    NETWORK=192.168.0.0
    BROADCAST=192.168.0.255
    GATEWAY=192.168.0.1

elif echo $MAC | egrep -q '^00:04:5a' ; then   # Linksys WPC11

    BOOTPROTO=static
    IPADDR=192.168.0.7
    NETMASK=255.255.255.0
    NETWORK=192.168.0.0
    BROADCAST=192.168.0.255
    GATEWAY=192.168.0.1

elif echo $MAC | egrep -q '^00:05:5d' ; then   # D-Link CDF-650W

    BOOTPROTO=static
    IPADDR=192.168.0.8
    NETMASK=255.255.255.0
    NETWORK=192.168.0.0
    BROADCAST=192.168.0.255
    GATEWAY=192.168.0.1

########################################
# unknown card, default to DHCP

else
    BOOTPROTO=dhcp
fi

###############################################################################
#
# set wireless parameters

if is_wireless_device ${DEVICE} ; then

    MODE=Managed
    ESSID=linksys
    RATE=auto
    KEY=112233445566778899aabbccdd
    SENS=3

fi

Obviously these are NOT the actual encryption settings I use on my home wireless network...

Another Idea

Just before writing the new script I posted a message to my Linux User Group's mailing list asking if anybody there had any idea how to identify the kernel module which handles a particular interface.

Just as I finished testing the new script, a friend on the list suggested that I use "alias" lines in /etc/modules.conf to force each card to "be" a different interface- for example, the wired card would be eth0, the Linksys wireless card would be eth1, and the D-Link card would be eth2. Then, I would use normal ifcfg-eth0 and ifcfg-eth1 files to set things correctly for each card.

This idea makes a lot of sense, especially in that it's a lot easier to configure. However, it wouldn't easily handle a case where I have two cards that happen to use the same module (i.e. one 3com card at home and a different 3com card at work.)

There's probably a way around this, but I think it would involve using the MAC address to tell one card from the other, and the script I just wrote already works based on the MAC address...


[hacker emblem] Copyright 2002-2003 John M. Simpson <jms1@spamcop.net>
Last updated 2003-07-22