[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20220725110742.34650b91@hermes.local>
Date: Mon, 25 Jul 2022 11:07:42 -0700
From: Stephen Hemminger <stephen@...workplumber.org>
To: "Kai Hendry" <hendry@....fi>
Cc: netdev@...r.kernel.org
Subject: Re: Find IP address of active interface
On Mon, 25 Jul 2022 08:48:15 +0800
"Kai Hendry" <hendry@....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.
Powered by blists - more mailing lists