Open main menu

IP address

Revision as of 15:46, 20 July 2016 by Freephile (talk | contribs) (summary of commands to show ip address)

(diff) ← Older revision | Approved revision (diff) | Latest revision (diff) | Newer revision → (diff)

Oftentimes people want to know what their Internet Protocol address is.

On a linux host, you can type hostname -i to get the IP, but it won't show all network interfaces, so really it's just a quick answer to "What's my primary IP?"

Something a little more elaborate will give you all the IPv4 addresses assigned to all NICs (note the space after inet in the grep). What's silly about the internet sites that list these grep variants is that the ip command itself is the tool you want to use to show this information. Still grep is useful as a means to filter output if you want the numbers exclusively (in order to sort) as in ip -4 addr show | grep inet | awk '{print $2}' | sort -n. Removing the grep and sort, you get not only the IP addresses, but the interfaces they are assigned to. Or, you can use the -o option to list one record per line which also makes grepping easier.

Protocol using ip options "dumb" grep (no options to ip)
IPv4
ip -4 addr show | awk '{ print $2 }'
ip addr show | grep 'inet ' | awk '{ print $2 }'
IPv4 and IPv6
ip addr show | grep 'inet' | awk '{ print $2 }'
IPv6
ip -6 addr show | awk '{ print $2 }'
ip addr show | grep 'inet6' | awk '{ print $2 }'


If you're looking for your external IP address instead, simply google "what is my ip?"