IP addresses can be divided into two categories, public and private (dedicated). IP is the only public IP addresses can be accessed from the Internet. Private IP addresses are reserved for internal use your private network, but will not directly exposed to the Internet.
This article describes the different ways the public IP address of the Linux system and several private IP addresses to determine. (Of course, some of the windows are possible)
Find your private IP address
Dedicated IP addresses are not routed over the Internet, and can only work within the local network. Typically, private IP address is assigned by the router to each local network device. This is the local network devices (such as phones, laptops, smart TVs, printers, media center, etc.) provides a unique IP address. Devices on the local network to the Internet via NAT (Network Address Translation).
The following IPv4 address ranges are reserved for private networks:
10.0.0.0/8 172.16.0.0/12 192.168.0.0/16
You can use as ip
, ifconfig
or hostname
command to query the network stack to determine the private IP address of the system.
In Linux, display and network interface configuration standard tools used for ip
.
To display all network interfaces and associated list of IP addresses, type the following command:
ip addr
You can also use the following command to display the private IP address:
$ hostname -I $ ifconfig
Find your public IP address
Determine the public IP address can HTTP/HTTPS
or DNS
protocol contacts the remote server and obtain an IP address from a remote server response.
If you are assigned to get your public IP address on the Linux server without a GUI, you can use the command-line tools dig
, curl
and wget
so on to get.
Most DNS provider (for example: OpenDNS and Google) that allow you to query the server and get your public IP address. You can use any of the following command to get the public IP:
$ dig ANY +short @resolver2.opendns.com myip.opendns.com $ dig ANY +short @resolver2.opendns.com myip.opendns.com $ dig ANY +short @ns1-1.akamaitech.net ANY whoami.akamai.net
In addition, there are many online HTTP/HTTPS
services can return to your public IP address. Here are some of them:
$ curl -s http://tnx.nl/ip $ curl -s https://checkip.amazonaws.com $ curl -s api.infoip.io/ip $ curl -s ip.appspot.com $ wget -O - -q https://icanhazip.com/
$ curl ip.sb
For ease of use, you can also create an alias to facilitate the inquiry.
alias pubip='dig ANY +short @resolver2.opendns.com myip.opendns.com'
Now, when you want to find public IP, just type the pubip
command.
Reference Links: https://mp.weixin.qq.com/s/dkVd0eQfzGHxM3SQ6picuQ