Update 20150813 How to get Public IP from Linux Terminal.md

This commit is contained in:
Kevin Sicong Jiang 2015-08-21 20:13:54 -05:00
parent f62f6c2ab7
commit 5842e697b1

View File

@ -1,13 +1,13 @@
KevinSJ Translating
How to get Public IP from Linux Terminal?
如何在 Linux 终端中获取公有 IP
================================================================================
![](http://www.blackmoreops.com/wp-content/uploads/2015/06/256x256xHow-to-get-Public-IP-from-Linux-Terminal-blackMORE-Ops.png.pagespeed.ic.GKEAEd4UNr.png)
Public addresses are assigned by InterNIC and consist of class-based network IDs or blocks of CIDR-based addresses (called CIDR blocks) that are guaranteed to be globally unique to the Internet. How to get Public IP from Linux Terminal - blackMORE OpsWhen the public addresses are assigned, routes are programmed into the routers of the Internet so that traffic to the assigned public addresses can reach their locations. Traffic to destination public addresses are reachable on the Internet. For example, when an organization is assigned a CIDR block in the form of a network ID and subnet mask, that [network ID, subnet mask] pair also exists as a route in the routers of the Internet. IP packets destined to an address within the CIDR block are routed to the proper destination. In this post I will show several ways to find your public IP address from Linux terminal. This though seems like a waste for normal users, but when you are in a terminal of a headless Linux server(i.e. no GUI or youre connected as a user with minimal tools). Either way, being able to getHow to get Public IP from Linux Terminal public IP from Linux terminal can be useful in many cases or it could be one of those things that might just come in handy someday.
公有地址由InterNIC分配并由基于类的网络 ID 或基于 CIDR 地址块构成(被称为 CIDR 块)并保证了在全球英特网中的唯一性。当公有地址被分配时,路径将会被记录到互联网中的路由器中,这样访问公有地址的流量就能顺利到达。访问目标公有地址的流量可通过互联网获取。比如,当一个一个 CIDR 块被以网络 ID 和子网掩码的形式分配给一个组织时,对应的 [网络 ID,子网掩码] 也会同时作为路径储存在英特网中的路由器中。访问 CIDR 块中的地址的 IP 封包会被导向对应的位置。在本文中我将会介绍在几种在 Linux 终端中查看你的公有 IP 地址的方法。这对普通用户来说并无意义,但 Linux 服务器(无GUI或者作为只能使用基本工具的用户登录时)会很有用。无论如何,从 Linux 终端中获取公有 IP 在各种方面都很意义,说不定某一天就能用得着。
Theres two main commands we use, curl and wget. You can use them interchangeably.
### Curl output in plain text format: ###
以下是我们主要使用的两个命令curl 和 wget。你可以换着用。
### Curl 纯文本格式输出: ###
curl icanhazip.com
curl ifconfig.me
@ -17,53 +17,53 @@ Theres two main commands we use, curl and wget. You can use them interchangea
curl ipecho.net/plain
curl www.trackip.net/i
### curl output in JSON format: ###
### curl JSON格式输出: ###
curl ipinfo.io/json
curl ifconfig.me/all.json
curl www.trackip.net/ip?json (bit ugly)
### curl output in XML format: ###
### curl XML格式输出: ###
curl ifconfig.me/all.xml
### curl all IP details The motherload ###
### curl 所有IP细节 ###
curl ifconfig.me/all
### Using DYNDNS (Useful when youre using DYNDNS service) ###
### 使用 DYDNS (当你使用 DYDNS 服务时有用)Using DYNDNS (Useful when youre using DYNDNS service) ###
curl -s 'http://checkip.dyndns.org' | sed 's/.*Current IP Address: \([0-9\.]*\).*/\1/g'
curl -s http://checkip.dyndns.org/ | grep -o "[[:digit:].]\+"
### Using wget instead of curl ###
### 使用 Wget 代替 Curl ###
wget http://ipecho.net/plain -O - -q ; echo
wget http://observebox.com/ip -O - -q ; echo
### Using host and dig command (cause we can) ###
### 使用 host 和 dig 命令 ###
You can also use host and dig command assuming they are available or installed
在可用时,你可以直接使用 host 和 dig 命令。
host -t a dartsclink.com | sed 's/.*has address //'
dig +short myip.opendns.com @resolver1.opendns.com
### Sample bash script: ###
### bash 脚本示例: ###
#!/bin/bash
PUBLIC_IP=`wget http://ipecho.net/plain -O - -q ; echo`
echo $PUBLIC_IP
Quite a few to pick from.
已经由不少选项了。
I was actually writing a small script to track all the IP changes of my router each day and save those into a file. I found these nifty commands and sites to use while doing some online research. Hope they help someone else someday too. Thanks for reading, please Share and RT.
我实际上写了一个用于记录每日我的路由器中所有 IP 变化并保存到一个文件的脚本。我在搜索过程中找到了这些很好用的命令。希望某天它能帮到其他人。
--------------------------------------------------------------------------------
via: http://www.blackmoreops.com/2015/06/14/how-to-get-public-ip-from-linux-terminal/
译者:[译者ID](https://github.com/译者ID)
译者:[KevinSJ](https://github.com/KevinSJ)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出