shell获取所有ipv4/ipv6地址

需要安装jq

ubuntu@gooderver:~$ ip -j -4 addr show | jq '.[]|.addr_info|.[]|.local'
"127.0.0.1"
"172.24.64.162"
ubuntu@gooderver:~$ ip -j -6 addr show | jq '.[]|.addr_info|.[]|.local'
"::1"
"2403:ac00:xxxx"
"fe80::e654:e8ff:fea3:6a01"
ubuntu@gooderver:~$ ip -j -6 addr show | jq -r '.[]|.addr_info|.[]|.local'
::1
2403:ac00:xxxx
fe80::e654:e8ff:fea3:6a01
posted @ 2023-03-06 22:08  王冰冰  阅读(75)  评论(0编辑  收藏  举报