Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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?
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?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.