Created
August 24, 2016 16:24
-
-
Save jsarenik/db04283eab68893eb2529257d0590cf5 to your computer and use it in GitHub Desktop.
Script to find one configured IP address used for communication via default route on Linux using ip command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
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