Quote:
Originally Posted by colucix
(Post 3406281)
Unless there is a way to know which is the external interface and which is (are) the internal one(s), other than check the address itself after its extraction, of course. Moreover, there are a lot of different types of network interface. For example having my system at home connected via DSL modem and running OpenSuse I have
Code:
dsl0 Link encap:Point-to-Point Protocol
eth0 Link encap:Ethernet
lo Link encap:Local Loopback
wlan0 Link encap:Ethernet
wmaster0 Link encap:UNSPEC
|
In the absense of an external reference such as dns, the simplest solution I could come up with would be to assume the interface associated with the default route is the correct one,
Code:
ifconfig $(route | grep default | awk '{print $8}')
And then parse that with the sed script you provided in your responses above. It's still not entirely foolproof, but at least you're not hard coding the interface name which is a step in the right direction.
Ofcourse, if the system is configured such that hostname -i returns the correct value, it avoids the need for all this shenanigans, but as you made clear, this cannot be relied upon on all distributions and setups.
This is why I enjoy hanging out on LQ. You can often find interesting insights in threads that you expect to be pretty straightforward on first viewing. Yes... I know, I'm Sad like that. ;)
|