Changes

Jump to navigation Jump to search
1,600 bytes added ,  16:46, 20 July 2016
summary of commands to show ip address
Oftentimes people want to know what their Internet Protocol address is.

On a linux host, you can type <code>hostname -i</code> 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 <code>ip</code> command itself '''is''' the tool you want to use to show this information. Still <code>grep</code> is useful as a means to filter output if you want the numbers exclusively (in order to sort) as in <code>ip -4 addr show | grep inet | awk '{print $2}' | sort -n</code>. Removing the grep and sort, you get not only the IP addresses, but the interfaces they are assigned to. Or, you can use the <code>-o</code> option to list one record per line which also makes grepping easier.

{| class="wikitable sortable"
|-
! Protocol !! using <code>ip</code> options !! "dumb" grep (no options to <code>ip</code>)
|-
| IPv4 || <source lang="bash">ip -4 addr show | awk '{ print $2 }'</source> || <source lang="bash">ip addr show | grep 'inet ' | awk '{ print $2 }'</source>
|-
| IPv4 and IPv6 || || <source lang="bash">ip addr show | grep 'inet' | awk '{ print $2 }'</source>
|-
| IPv6 || <source lang="bash">ip -6 addr show | awk '{ print $2 }'</source> || <source lang="bash">ip addr show | grep 'inet6' | awk '{ print $2 }'</source>
|}


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

edits

Navigation menu