shell获取eth0 地址

2020-03-30  本文已影响0人  小黑佬

This will give you all IPv4 interfaces, including the loopback 127.0.0.1:

ip -4 addr | grep -oP '(?<=inet\s)\d+(\.\d+){3}'

This will only show eth0:

ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'

And this way you can get IPv6 addresses:

ip -6 addr | grep -oP '(?<=inet6\s)[\da-f:]+'

Only eth0 IPv6:

ip -6 addr show eth0 | grep -oP '(?<=inet6\s)[\da-f:]+'

附加:
Getting the external IP

dig @ns1-1.akamaitech.net ANY whoami.akamai.net +short
上一篇 下一篇

猜你喜欢

热点阅读