

Linux 查看外网IP地址
source link: https://www.myfreax.com/linux-view-external-network-ip-address/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Linux 查看外网IP地址
在排除网络问题,建立新连接或配置防火墙时,了解计算机的IP地址非常重要

Linux 查看外网IP地址
在排除网络问题,建立新连接或配置防火墙时,了解计算机的IP地址非常重要。
IP地址可以分为两类,公有和私有/专用。公有IP是唯一的IP地址,可以从Internet访问。私有IP地址保留在私有网络内部使用,而不会直接暴露给Internet。
此外,有两种版本的IP地址,即IP版本4 IPv4和IP版本6 IPv6。本教程说明如何在Linux查看公有IP地址和私有IP地址的几种不同方法。
Linux 查看外网IP地址
公有IP地址是全球可路由的IP地址,它允许直接访问Internet。它由ISP分配给网络设备,并且每个设备都有唯一的公有IP地址。
查看公有IP地址可以通过HTTP/HTTPS或DNS协议连接远程服务器,并从远程服务器响应获取IP地址。
如果你的计算机没有桌面环境并想查看分配的外网IP地址,你可以使用命令行工具dig
,curl
和wget
等获得外网IP地址。
大多数DNS提供商,例如OpenDNS和Google都允许您查询其服务器并获取您的公有IP地址。有许多在线HTTP/HTTPS服务可以返回您的公有IP地址。
dig ANY +short @resolver2.opendns.com myip.opendns.com
dig ANY +short @ns1-1.akamaitech.net ANY whoami.akamai.net
curl -s https://checkip.amazonaws.com
curl -s http://tnx.nl/ip
curl -s api.infoip.io/ip
curl -s ip.appspot.com
wget -O - -q https://icanhazip.com/
您不必记住这些命令,您只需创建一个简单的别名,就可以很容易的获取外网IP地址。
例如您可以将别名alias pubip='dig ANY +short @resolver2.opendns.com myip.opendns.com'
添加到~/.bashrc
和~/.zshrc
文件。
运行命令echo "alias pubip='dig ANY +short @resolver2.opendns.com myip.opendns.com'" >> .zshrc
。
echo "alias pubip='dig ANY +short @resolver2.opendns.com myip.opendns.com'" >> ~/.bashrc
现在,您只需要在终端键入pubip
命令即可查找外网IP地址。
我们向您展示了几种不同的命令和在线服务,让您可以使用这些命令或者服务查看外网IP地址。如果您有任何疑问或评论,请在下面发表评论。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK