Jeffimgcls Hi, I'm Jeff! Resume Linkedin Mail

How To Find Your Public IP Address From Linux CLI

A public IP address is an address that can be accessed over the Internet. Public IP addresses are provided by Internet Service Providers (ISPs) and are globally unique. These addresses are used to identify and locate devices on the Internet.

On the other hand, a private IP address is an address assigned to devices within a private network, such as a home or business network. Private IP addresses are not accessible from the Internet. Instead, they are used for communication within the private network and are typically assigned by a router.

For example, in a typical home network setup, the devices connected to the local network (like smartphones, computers, printers) are assigned private IP addresses (e.g., 192.168.x.x). The router in the home network then uses its public IP address, provided by the ISP, to communicate with devices on the Internet.

There are instances where you may need to determine what the public IP address is that your machine is using and you can use these commands from the CLI to figure it out.

dig +short
dig TXT +short
dig +short txt ch whoami.cloudflare @
dig TXT +short | awk -F'"' '{ print $2}'
printf "Server public ip4 %s\n" $server_ip