有多種方法可以查看Linux系統的公網IP地址,以下是其中一些常用的方法:
curl ifconfig.me
dig +short myip.opendns.com @resolver1.opendns.com
wget -qO- icanhazip.com
nslookup myip.opendns.com resolver1.opendns.com
ip addr show eth0 | grep inet | awk '{print $2}' | cut -d/ -f1
以上方法中,eth0是網絡接口的名稱,你可以根據自己的網絡配置修改為實際使用的網絡接口名稱。