Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Script to find one configured IP address used for communication via default route on Linux using ip command
DEV=$(ip route list | sed -n '/^default/s/.*dev \(\S\+\).*/\1/p')
IP=$(ip route list | sed -n '/^default/s/.*src \(\S\+\).*/\1/p')
ip address list dev $DEV | grep -m1 -o "$IP/[0-9]\+"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.