LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-16-2008, 11:20 AM   #1
charles.figura
LQ Newbie
 
Registered: May 2007
Posts: 3

Rep: Reputation: 0
How do I find out what my active ethernet interface is?


I'm looking for a one line command that will return the ID of the active ethernet interface - i.e., that will return 'eth0' if I'm on my cabled interface or 'wlan0' if I'm on my wireless. I know that by searching through the output from 'ifconfig' I can figure out which one is active - I'd like to determine that by a command (so I can stick the output in a script where I need it).

I'm guessing I could create something if I were a genius at scripting, but I'm drawing a blank so far (since I'm not the aforementioned genius!)

Any ideas? Thanks!
 
Old 10-16-2008, 01:48 PM   #2
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,414
Blog Entries: 1

Rep: Reputation: 65
Tricky question since you can have more than one interface active at the same time.
For example, my laptop is plugged by wire on my office LAN and to internet by GSM modem.
At same time I can access files on internal lan and browse the internet not using the office infra-structure but the GSM network.

"ifconfig" without any arguments return all active interfaces. So just get the first line and cut out everything else but the id:
Code:
[miguel@babylon5 ~]$ /sbin/ifconfig | grep "Link encap:Ethernet" | cut -d' ' -f1
br0
eth0
vbox0
ppp0
[miguel@babylon5 ~]$
If, by active you mean the interface that connects to external world, you can use the "route" command; get the default gateway line, and return the id in the last field:
Code:
[miguel@babylon5 ~]$ /sbin/route -n | grep "^0.0.0.0" | rev | cut -d' ' -f1 | rev
ppp0
[miguel@babylon5 ~]$
 
Old 10-16-2008, 04:19 PM   #3
charles.figura
LQ Newbie
 
Registered: May 2007
Posts: 3

Original Poster
Rep: Reputation: 0
That's fabulous - the second one looks exactly like what I had in mind. Thanks!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how can i shutdown the PHYSICAL interface of an ethernet interface markraem Linux - Networking 2 04-12-2007 02:29 PM
interface eth0 is not (yet?) active jorcas SUSE / openSUSE 1 11-22-2004 06:53 PM
no active interface (yet?)...no network... breezewax Linux - Networking 17 09-16-2004 09:13 PM
ethernet active, but no access to internet nouwen Linux - Newbie 3 06-14-2004 12:38 PM
Can't Bring Ethernet Up / Can't Active Ethernet / Guigo Linux - Newbie 8 04-03-2004 08:31 AM

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

All times are GMT -5. The time now is 11:06 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration