Skip to content

Instantly share code, notes, and snippets.

@pkunc
Last active March 16, 2022 09:35
Show Gist options
  • Save pkunc/8ea2b031ca642ee01fb9acdecf75e32c to your computer and use it in GitHub Desktop.
Save pkunc/8ea2b031ca642ee01fb9acdecf75e32c to your computer and use it in GitHub Desktop.
Get IP address in Linux

Get IP address in Linux

Several ways how to get an IP address only, using a Linux command.

ip -f inet addr show eth0 | grep -Po 'inet \K[\d.]+'
ip -4 addr show eth0 | grep -Po 'inet \K[\d.]+'
ip -4 addr show eth0 | grep -oP "(?<=inet ).*(?=/)"
ip -4 addr show eth0 | grep -oP "(?<=inet )[\d\.]+(?=/)"
ip addr show eth0 | awk '$1 == "inet" {gsub(/\/.*$/, "", $2); print $2}'
ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment