Skip to content

Instantly share code, notes, and snippets.

@lee-pai-long
Last active February 11, 2016 09:33
Show Gist options
  • Save lee-pai-long/eb50c0dfce92bb2e4cdf to your computer and use it in GitHub Desktop.
Save lee-pai-long/eb50c0dfce92bb2e4cdf to your computer and use it in GitHub Desktop.

[LINUX] get stripped IP

Get only private IP address from an interface

$ ip a | grep <interface> | grep inet | cut -f1 -d/ | awk '{print $2}'

or if your locale is set to english

$ ifconfig <interface> | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'

replace addr by adr may work in other languages like french

Get only public IP address

$ wget -qO - checkip.dyndns.org | sed -e 's/[^0-9^.]//g'

You can also use ifconfig.co service

$ wget -qO - ifconfig.co
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment