How to Find Your Public IP Address in the Linux Terminal Using curl

If you are configuring a Linux web server or setting up a dynamic DNS service, you often need to know the public IP address of your machine. This is the IP address assigned by your Internet Service Provider that is visible to the outside world, not the local 192.168.x.x address assigned by your home router.

In a graphical desktop, you would simply open a web browser and search “What is my IP.” In a headless Linux terminal, you cannot open a web browser. Instead, you must use the curl command to query an external API server.

How to Find Your IP Using curl

The curl tool is designed to transfer data from URLs directly into your terminal. We can use it to contact a lightweight website designed specifically to bounce your IP address back to you in plaintext.

  1. Open your Linux terminal.
  2. Type the following exact command:
    curl ifconfig.me
  3. Press Enter.

The terminal will instantly output a string of numbers (e.g., 203.0.113.45) without any HTML formatting or extra text. That is your public IPv4 address.

Alternative Servers (If ifconfig.me is Down)

Because these IP-echoing servers are provided for free by the community, they occasionally go offline or block traffic if they receive too many requests. If the curl ifconfig.me command times out, you can simply query a different server.

All of the following commands perform the exact same function and will output your raw IP address to the terminal:

  • curl icanhazip.com
  • curl ipecho.net/plain
  • curl ifconfig.co

What if curl is not Installed?

If you are using a remarkably barebones Linux container that does not have curl installed, you can use the wget utility instead. By passing the -qO- flags, you instruct wget to run quietly and output the data directly to the screen instead of saving it as a file.

wget -qO- ifconfig.me

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.