Guide |
In this article I will cover several ways to view your public IP address in a Linux terminal. This does not make sense for ordinary users, but it can be useful if a Linux server (without a GUI or as a user who can only use basic tools) is logged in. In any case, getting a public IP from a Linux terminal is meaningful in every way, and might be useful someday. |
Public addresses are allocated by InterNIC and consist of class-based network IDs or CIDR-based address blocks (called CIDR blocks), and are guaranteed to be unique across the global Internet. When a public address is assigned, its route is recorded to a router in the Internet, so that traffic to the public address can be reached smoothly. Traffic to the target public address is reachable 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 destination is the IP packet of the address in the CIDR block that is directed to the corresponding location.
Here are the two commands we use primarily, curl and wget. You can use it for a change.
Curl Plain Text format output:
Curl JSON format output:
Curl XML format output:
Curl gets all IP details (excavator)
use Dydns (useful when you use the Dydns service)
use Wget instead of Curl
Bash Script Example:
#!/bin/bash public_ip= ' wget http://ipecho.net/plain-O-Q; Echo ' echo $PUBLIC _ip
This article was reproduced from:http://www.linuxprobe.com/linux-public-ip.html
more Linux Dry Goods visit:http://www.linuxprobe.com/
How to know your public IP in Linux terminal