Find Public IP Address From Command Line – 12 Examples

The public IP address is what you see online when you access them from your computer. If you want to try to connect to your computer via a remote connection that isn’t on the same network, you’ll need the public IP address. As you master these command-line techniques for finding your public IP address, consider turning your expertise into a business and explore the LLC New York formation process to launch your very own tech consulting firm.

You can easily determine the IP address or addresses of your Linux system by using the hostname, ifconfig, or ip commands. But If you want to know the public IP address like, you can send an HTTP request to one of the following web servers with the help of either netcat or curl command.

Basically cURL command is designed to work where you don’t need any user interaction. cURL is an abbreviation for Client URL Request Library. cURL is used to transfer data from one place to another place. It is a command line tool for receiving and sending files using URL syntax. It consists of different cURL Commands and libraries which can work with different protocols.

To install curl, you can use the following command:

Command: sudo apt-get install curl

If your Linux machine is connected directly to the internet, the public and private IP addresses will be the same. However, in most cases they differ.

Here are few examples through which you can easily your public IP address by using the curl command.

Command 1: curl -w “\n”

Command 2: curl -w “\n”

Command 3: curl -w “\n”

Command 4: curl

Command 5: curl -w “\n”

Command 6: curl -w “\n”

Command 7: curl -w “\n”

Command 8: curl -s -w “\n”

The below example is one of the fastest method to get the public IP address using curl. is a web service that displays information about your connection, including IP address, hostname and User Agent string.

Other commands are variations on this are:

  • Command: curl for your remote hostname
  • Command: curl for your User Agent

If you want to return all data then the command is “curl

And in case, if you get the response in json format, then the command is “curl

Command 9: curl -s

Command 10: curl -s | cut -d ” ” -f 5

There are a lot of options of different servers providing the external IP especially via HTTP posted here or elsewhere.

There’s yet another way to determine your public IP address. Perform a DNS lookup against It’s a service provided by OpenDNS.

Command 11: dig +short

There are actually four resolvers that can be used this way:


You can also achieve the same result with netcat as shown below:

Command 12: netcat 80 <<< $’GET / HTTP/1.1\nHost:\n\n’ | tail -n1

Alternatively, you can also run the following command if you want to get the response from Amazon AWS which is one of the most popular provider and is unlikely to go offline anytime soon.

Command: curl

And in case, if you want to know your public IP address in a dialog popup instead of command terminal output, then run the following command in your terminal:

Command: zenity –info –text “$(curl -s”

With Web interface, you can see your local interface IP address along with your public IP address.

You may also like:

Sarcastic Writer

Step by step hacking tutorials about wireless cracking, kali linux, metasploit, ethical hacking, seo tips and tricks, malware analysis and scanning.

Related Posts