LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 10-20-2005, 07:01 AM   #1
johnnybhoy67
Member
 
Registered: Sep 2004
Distribution: Knoppix 4.0.2
Posts: 54

Rep: Reputation: 15
Set up IP on specific eth device?


Hi All,

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?

Many Thanks

J
 
Old 10-20-2005, 08:12 PM   #2
demian
Member
 
Registered: Apr 2001
Location: Bremen, Germany
Distribution: Debian
Posts: 303

Rep: Reputation: 30
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.
 
Old 10-21-2005, 09:01 AM   #3
johnnybhoy67
Member
 
Registered: Sep 2004
Distribution: Knoppix 4.0.2
Posts: 54

Original Poster
Rep: Reputation: 15
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?

Cheers

J
 
Old 10-21-2005, 12:33 PM   #4
demian
Member
 
Registered: Apr 2001
Location: Bremen, Germany
Distribution: Debian
Posts: 303

Rep: Reputation: 30
Sure you can do that. Pseudo code:

ifconfig eth0 up blah bleh

if (! ping -c 1 some.host.thats.up)
then
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.

edit:
just reread your question:
Quote:
Would it be possible to setup all eth devices and then try each for connection
I take it you want to assign a certain ip to whatever interface happens to be connected, right? One thing you have to be careful about is to not assign the same ip to two interfaces. This will lead to routing problems. Also assigning to different ips from the same network will lead to arp flux problems. So you need to deconfigure one interface before the other comes up.

Another possible solution (the proper albeit most difficult one) is to use ethernet bonding (see /usr/src/linux/Documentation/networking/bonding.txt)

Last edited by demian; 10-21-2005 at 02:44 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with shapecfg working with virtual eth device rdmaxx Linux - Networking 1 02-10-2005 04:38 PM
Bind ETH devices to specific NIC/MAC not_an_expert Slackware 8 10-13-2004 11:00 AM
Device 'eth' doesn't exist Moth7 Linux - Networking 2 10-24-2003 04:45 PM
Change Eth Device gamehack Slackware 4 09-01-2003 11:31 AM
Cannot activate eth device kakridge Linux - Networking 4 07-14-2003 08:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 09:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration