Getting Local Machine IP Address in Shell
IPv4 Address
ifconfig | awk '$1 == "inet" && $2 != "127.0.0.1" { print $2 }'
IPv6 Address
ifconfig | awk '$1 == "inet6" && $2 != "::1" { print $2 }'
Written by Jiangge Zhang
Related protips
2 Responses
'ifconfig' is obsolete (according to its own man page). Since it could be going away in future, the use of 'ip' command is recommended. Therefore something like the following could be better.
ip addr | awk '$1 == "inet" && $2 != "127.0.0.1/8" { split ($2, a, "/"); print a[1] }'
over 1 year ago
·
curl ifconfig.me
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#