Pages

Friday, February 13, 2015

Show your local ipv4 IP

$ ip -o -4 addr show eth0 | grep -v ": lo " | sed 's/ \+/\t/g' | cut -f 4 | cut -d\/ -f1

To show ipv6 instead, use [[ -6 ]] instead of [[ -4 ]]


ip -o -6 addr show eth0 | grep -v ": lo " | sed 's/ \+/\t/g' | cut -f 4 | cut -d\/ -f1

Command to use when on Wi-Fi connection: use [[ wlan0 ]] instead of [[ eth0 ]]


ip -o -4 addr show wlan0 | grep -v ": lo " | sed 's/ \+/\t/g' | cut -f 4 | cut -d\/ -f1

Show all interfaces' IPs: just remove [[ eth0 ]]


ip -o -4 addr show | grep -v ": lo " | sed 's/ \+/\t/g' | cut -f 4 | cut -d\/ -f1

* You may want to change [[ eth0 ]] for whatever interface you want to get the IP .


* If you want to show the loopback too (127.0.0.1), remove [[ grep -v ": lo " ]] .


eth0 and wlan0 were used as examples because it applies to most cases. To list all interfaces and IPs do:


ip -4 -o a s


commandlinefu.com


by David Winterbottom (codeinthehole.com)






from All commands http://ift.tt/1vq5r8W

No comments:

Post a Comment