LinuxQuestions.org
Visit Jeremy's Blog.
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 11-01-2012, 01:45 PM   #1
Brandon9000
Member
 
Registered: Apr 2012
Location: Florida
Distribution: Many
Posts: 111

Rep: Reputation: Disabled
Finding the Default Network Interface Name


I have a C++ program which runs on many Linux operating systems. One of the things it does for initial setup is to try to determine the default network interface name, which is often, but not always, eth0. It accomplishes this by giving the "route" command and looking for the line which contains the word "default." I now face the prospect of it being run on routers (running Linux) which have several NICs. Apparently, on the router on which it was tried, the route command showed neither the word default nor the address 0.0.0.0, making it impossible for my program to determine the default interface name.

Is there a reasonably graceful way to find out which of the interface names listed is connected to the LAN by giving a command or calling a library function? I hasten to add that I am not very familiar with networking.

Any such technique must be something that a program can do, it cannot require any special setup on the machine in question, and it cannot be specific to some 3rd party software which is not widespread.

Thanks.
 
Old 11-05-2012, 02:21 PM   #2
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,854

Rep: Reputation: 161Reputation: 161
If there isn't 0.0.0.0 or default entry in routing table, that means no default route in the system.
Can you upload the routing table?
 
Old 11-05-2012, 04:06 PM   #3
Brandon9000
Member
 
Registered: Apr 2012
Location: Florida
Distribution: Many
Posts: 111

Original Poster
Rep: Reputation: Disabled
Sure, how do I obtain it? I know how to do the route command, etc., but I do not know how to just find the routing table itself.
 
Old 11-06-2012, 02:03 PM   #4
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,854

Rep: Reputation: 161Reputation: 161
Just using route command to dump routing table.
 
Old 11-06-2012, 02:10 PM   #5
Brandon9000
Member
 
Registered: Apr 2012
Location: Florida
Distribution: Many
Posts: 111

Original Poster
Rep: Reputation: Disabled
I've modified a few things so as to protect confidential information, but this is basically it:

route

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
109.33.116.105 * 255.255.255.105 U 0 0 0 hc.eth0
192.168.0.0 * 255.255.255.0 U 0 0 0 eth1
192.0.2.0 * 255.255.255.0 U 0 0 0 dummy0
192.0.2.0 * 255.255.255.0 U 0 0 0 utun

As you can see, neither "deafult" nor a flag of UG occurs.

Last edited by Brandon9000; 11-06-2012 at 02:11 PM.
 
Old 11-07-2012, 02:11 PM   #6
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,854

Rep: Reputation: 161Reputation: 161
All route entry is interface or host route. I think that the system doesn't config default route. To confirm it, you add default route manually and then execute route command.
 
Old 11-07-2012, 02:20 PM   #7
Brandon9000
Member
 
Registered: Apr 2012
Location: Florida
Distribution: Many
Posts: 111

Original Poster
Rep: Reputation: Disabled
The question was how to identify the default interface name from a program.
 
Old 11-08-2012, 02:14 PM   #8
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,854

Rep: Reputation: 161Reputation: 161
If there isn't default route in system, that means no default interface.
 
Old 11-08-2012, 02:17 PM   #9
Brandon9000
Member
 
Registered: Apr 2012
Location: Florida
Distribution: Many
Posts: 111

Original Poster
Rep: Reputation: Disabled
Fair enough, but it's still true that one of the interfaces faces the LAN, and I would like a way for my program to be able tell which one. Short of having the program ping them all and parsing the result to see which ping worked, and assuming that ping will even be active, is there any way to do that?
 
Old 11-08-2012, 04:15 PM   #10
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Code:
arp
Address                  HWtype  HWaddress           Flags Mask            Iface
192.168.1.1              ether   30:46:9a:67:c5:d4   C                     eth0
maybe?

"route -n" here isn't much help, as it lists all my available Ifaces.
arp at least shows which one is being used, no?
 
Old 11-08-2012, 04:24 PM   #11
Brandon9000
Member
 
Registered: Apr 2012
Location: Florida
Distribution: Many
Posts: 111

Original Poster
Rep: Reputation: Disabled
I guess I should stop this. This question arose out of a problem that ocurred when my program was installed on some routers. In the end, having no other answer and needing a solution that would work everywhere, I created a new parameter in a config file to allow a user to write in an interface name for the program to use if it failed to discover a default in any other way. This worked and I no longer have access to that environment. I was keeping this discussion going out of a desire to understand the subject, but I have no further capacity to test suggestions. Would the use of "arp" work everywhere under all (reasonable) conditions, though?
 
  


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
Is there such a thing as a default network interface? gravyface Linux - Networking 1 08-08-2009 11:45 PM
how to specify default network interface? zero79 Debian 2 10-15-2005 03:15 AM
Finding the Best Interface on Linux wjacky Linux - Newbie 7 03-28-2005 08:38 PM
Changing the default network interface at startup frandres Linux - Newbie 1 01-16-2005 06:32 PM
default network interface bhupee Linux - Newbie 1 07-02-2004 04:33 PM

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

All times are GMT -5. The time now is 03:41 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