Method for obtaining a public IP address in a Linux terminal

  
A public IP is a public address that is assigned by InterNIC and consists of a class-based network ID or a CIDR-based address block (called a CIDR block) and is guaranteed in the global Internet. Uniqueness. When a public address is assigned, its route will be logged to the router on the Internet, so that traffic to the public address can be reached smoothly. Traffic to the target public address is accessible via the internet. For example, when a CIDR block is assigned to an organization in the form of a network ID and a subnet mask, the corresponding [network ID, subnet mask] is also stored as a route in the router on the Internet. The IP packet whose destination is the address in the CIDR block is directed to the corresponding location.

In this article I will cover several ways to view your public IP address in a Linux terminal. This doesn't make sense to the average user, but it's useful for Linux servers (no GUI or as a user who can only use basic tools). In any case, getting public IP from a Linux terminal is meaningful in every way, and maybe one day.
The following are the two commands we mainly use, curl and wget. You can use it instead.
Curl plain text output:
curl icanhazip.com
curl ifconfig.me
curl curlmyip.com
curl ip.appspot.com
curl ipinfo.io/ip
curl ipecho.net/plain
curl www.trackip.net/i
curl JSON format output:
curl ipinfo.io/json
curl ifconfig.me/all.json
curl Www.trackip.net/ip?json (a bit ugly)
curl XML format output:
curl ifconfig.me/all.xml
curl Get all IP details (excavator)
curl ifconfig. Me/all
Use DYDNS (useful when you use the DYDNS 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:].]\\+"
Use Wget instead of Curl
wget http://ipecho.net/plain -O - -q ; echo
wget http: //observebox.com/ip -O - -q ; echo
Use the host and dig commands
If you have one, you can also use the host and dig commands directly.
host -t a dartsclink.com |  Sed 's/.*has address //'
dig +short myip.opendns.com @resolver1.opendns.com
bash script example:
#!/bin/bashPUBLIC_IP=`wget http://ipecho.net/plain -O - -q ; echo`
echo $PUBLIC_IP
Easy to use.

Copyright © Windows knowledge All Rights Reserved