netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Find IP address of active interface
@ 2022-07-25  0:48 Kai Hendry
  2022-07-25 18:07 ` Stephen Hemminger
  0 siblings, 1 reply; 2+ messages in thread
From: Kai Hendry @ 2022-07-25  0:48 UTC (permalink / raw)
  To: netdev

Is there an easier way than:

ip route get 8.8.8.8 2>/dev/null|grep -Eo 'src [0-9.]+'|grep -Eo '[0-9.]+'

To figure out the active, Internet routing interface?

Thank you,

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Find IP address of active interface
  2022-07-25  0:48 Find IP address of active interface Kai Hendry
@ 2022-07-25 18:07 ` Stephen Hemminger
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2022-07-25 18:07 UTC (permalink / raw)
  To: Kai Hendry; +Cc: netdev

On Mon, 25 Jul 2022 08:48:15 +0800
"Kai Hendry" <hendry@iki.fi> wrote:

> Is there an easier way than:
> 
> ip route get 8.8.8.8 2>/dev/null|grep -Eo 'src [0-9.]+'|grep -Eo '[0-9.]+'
> 
> To figure out the active, Internet routing interface?
> 
> Thank you,

Alternate:

$ ip -j route get 8.8.8.8 | \
  python3 -c 'import json,sys;obj=json.load(sys.stdin);print(obj[0]["dev"]);'
enp2s0

But both options won't do what you want if there is ECMP routes.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-25 18:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-25  0:48 Find IP address of active interface Kai Hendry
2022-07-25 18:07 ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).