如何从Linux上的命令行找到公共IP地址
时间:2020-03-21 11:44:26 来源:igfitidea点击:
在图形用户模式下有许多方法/应用程序可用于执行此操作。
打开Web浏览器并转到Whatismyip.com。
在那里,我们可以看到公共IP。
无论任何操作系统如何,它都是找出公共IP地址的最受欢迎的方法之一。
我们所需要的只是一个互联网连接和Web浏览器。
但是,如何从命令行查找公共IP地址?
这就是我们在本教程中看到的。
从Linux上的命令行查找公共IP地址
有许多命令来查找公共IP地址。
在这里我列出了一些。
我们可以使用"dig"和"host"命令找到公共IP地址。
如果系统中不可用DIG和HOST命令,请安装DNSUTILS包。
关于Arch Linux:
$sudo pacman -S dnsutils
关于Rhel,Centos,Fedora:
$sudo yum install dnsutils
或者,
$sudo dnf install dnsutils
在Debian,Ubuntu及其衍生品:
$sudo apt-get install dnsutils
现在,让我们找到公共IP。
方法1:
使用DIG命令,让我们使用Google解析器查找公共IP:
$dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | sed 's/"//g'
或者,使用此命令查找公共IP:
$dig TXT +short o-o.myaddr.l.google.com @ns1.google.com
我可以通过Opendns Resolvers获得相同的信息吗?
是的你可以!
$dig +short myip.opendns.com @resolver1.opendns.com
方法2:
我们可以使用host命令获取相同的信息。
$host myip.opendns.com resolver1.opendns.com
示例输出:
Using domain server: Name: resolver1.opendns.com Address: 208.67.222.222#53 Aliases: myip.opendns.com has address 122.178.32.233 Host myip.opendns.com not found: 3(NXDOMAIN) Host myip.opendns.com not found: 3(NXDOMAIN)
方法3:
我们可以使用curl命令从第三方查找系统的公共IP。
由于安全原因,我不建议使用第三方查找IP地址。
要小心!
这里展示一些例子。
$curl ipinfo.io
示例输出:
{ "ip": "122.178.32.233", "hostname": "abts-tn-dynamic-233.32.178.122.airtelbroadband.in", "city": "Coimbatore", "region": "Tamil Nadu", "country": "IN", "loc": "10.9925,76.9614", "org": "AS24560 Bharti Airtel Ltd., Telemedia Services", "postal": "641001"
这是另一个:
$curl ifconfig.me
一个命令......
$curl ip.sb
默认安装curl。
如果没有任何机会安装,请运行以下命令以安装它。
关于Arch Linux:
$sudo pacman -S curl
关于Rhel,Centos,Fedora:
$sudo yum install curl
或者,
$sudo dnf install curl
在Debian,Ubuntu及其衍生品:
$sudo apt-get install curl
这里是一个找到公共IP的另一种方法。
$curl https://wtfismyip.com/text
示例输出:
122.178.32.233
下面给出了其他有用的方法来查找公共IP地址。
$curl api.ipify.org
$curl https://ipinfo.io/ip
$curl ipecho.net/plain
$curl ifconfig.co
$curl ident.me
$curl icanhazip.com
$curl ip.appspot.com