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:
/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 |
DEVICE=eth0 |
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.
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.)
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.
############################################################################### |
Obviously these are NOT the actual encryption settings I use on my home wireless network...
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...