如何用命令获取公共IP地址

本文介绍如何从命令行检测被NAT路由器分配的公共IP地址。通过安装curl并使用特定网站服务,可以轻松获取到该地址。

Last updated on April 24, 2013 Authored by Dan Nanni6 Comments

Suppose your Linux machine is behind a NAT router. Then what's visible to your machine is only a LAN IP address assigned to its LAN interface. Then how can you detect the public (or WAN) IP address assigned to the NAT router, preferably from command line?

 

Here is how to find the public IP address from command line.

 

You first need to install curl as you need to rely on an external web server to get the public IP address.

 

On Debian, Ubuntu or Linux Mint:

 

$ sudo apt-get install curl

 

 

On Fedora, CentOS or RHEL:

 

$ sudo yum install curl

The following is a list of commands that you can run to determine the public IP address. You can define an alias using one of these commands, or use them in a shell script.

 

$ curl ifconfig.me

$ curl icanhazip.com

$ curl ident.me

$ curl ipecho.net/plain

$ curl whatismyip.akamai.com

$ curl tnx.nl/ip

$ curl myip.dnsomatic.com

$ curl ip.appspot.com

$ curl ip.telize.com

$ curl curlmyip.com

$ curl -s checkip.dyndns.org | sed 's/.*IP Address: \([0-9\.]*\).*/\1/g'

If there is any command in the above that no longer works, or any new site that is command-line friendly, let me know.

 

来源:http://xmodulo.com/how-to-find-the-public-ip-address-from-command-line.html

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值