From: Stephen Hemminger <stephen@networkplumber.org>
To: "Kai Hendry" <hendry@iki.fi>
Cc: netdev@vger.kernel.org
Subject: Re: Find IP address of active interface
Date: Mon, 25 Jul 2022 11:07:42 -0700 [thread overview]
Message-ID: <20220725110742.34650b91@hermes.local> (raw)
In-Reply-To: <c7aa5278-5c8d-4d76-96d7-bb52244786e9@www.fastmail.com>
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.
prev parent reply other threads:[~2022-07-25 18:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-25 0:48 Find IP address of active interface Kai Hendry
2022-07-25 18:07 ` Stephen Hemminger [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220725110742.34650b91@hermes.local \
--to=stephen@networkplumber.org \
--cc=hendry@iki.fi \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).