Set up IP on specific eth device?
I'd like to be able to set up IP on eth? depending on which device the cable is plugged into.
I have more than one network card in my machine for various reasons and need to script the commands to configure whichever device is currently plugged in?
Is this possible and if so how can I do this?
If your network card supports MII queries you can use mii-tool to find out if a link could be negotiated. Example output for an established link is something like:
[demian@dirac]# mii-tool eth0
eth0: negotiated 100baseTx-FD, link ok
without a cable it's this:
[demian@dirac]# mii-tool eth3
eth3: Link down, cable problem?
Then you can just grep for "link ok" or something and start an appropriate ifconfig command.
what if it doesn't support these queries?
Would it be possible to setup all eth devices and then try each for connection or is that just silly?
Sure you can do that. Pseudo code:
ifconfig eth0 up blah bleh
if (! ping -c 1 some.host.thats.up)
ifconfig eth0 down
ifconfig eth1 up blah bleh
You might want to send more than on ping packet if there's a chance for packet loss. However, I don't know what the return code of ping on partial packet loss is. But it's probably still 0.
just reread your question:
Another possible solution (the proper albeit most difficult one) is to use ethernet bonding (see /usr/src/linux/Documentation/networking/bonding.txt)
|All times are GMT -5. The time now is 12:00 PM.|