Linux获取ip的几种方法

一.下面几种获取外网ip地址

1. curl ifconfig.me
2. curl -4/-6 icanhazip.com
3. curl ipinfo.io/ip
4. curl api.ipify.org
5. curl checkip.dyndns.org
6. dig +short myip.opendns.com @resolver1.opendns.com
7. host myip.opendns.com resolver1.opendns.com
8. curl ident.me
9. curl bot.whatismyipaddress.com
10. curl ipecho.net/plain

二.下面几种获取内网ip地址

1. ifconfig -a
2. ip addr (ip a)
3. hostname -I | awk '{print $1}'
4. ip route get 1.2.3.4 | awk '{print $7}'
5. nmcli -p device show

你可能感兴趣的:(Linux获取ip的几种方法)