Introduction
As a developer, sysadmin, or security professional, your workspace is centered around the terminal. When writing deployment playbooks, diagnosing VPN configurations, configuring secure SSH access, or debugging remote network firewalls, opening a desktop browser to find your public IP address is slow and breaks your command line focus.
Fortunately, querying your public IP directly from the shell is incredibly fast, simple, and customizable.
In this guide, we will cover the most efficient terminal commands to check your public IP on macOS, Linux, and Windows using standard tools like curl, wget, httpie, and PowerShell. We will also show you how to save these endpoints as aliases to save keystrokes.
The Concept of Raw IP Endpoints
Most IP lookups return rich HTML or graphical dashboards. While this is great for human visual inspection, it is painful for command line scripts. Running curl https://example.com on a standard site yields hundreds of lines of HTML code that you would have to parse using utilities like grep, awk, or sed to find the IP address.
To solve this, APIs offer raw plain-text endpoints (sometimes called dynamic text endpoints). These routes strip away all wrappers, headers, and scripts, returning nothing but the raw IP string (e.g., 203.0.113.10).
This makes terminal integrations seamless because the command output can be instantly saved into environment variables or piped into downstream configuration files.
Our dedicated raw plain-text endpoint returns your public IP as a clean, plain text string ready for your terminal commands.
Finding Your IP via Command Line
Here are the most common CLI methods to fetch your public IP, categorized by shell tool and operating system:
1. Using cURL (Most Popular)
curl is the industry-standard command-line tool for transferring data with URLs. It is pre-installed on macOS, almost all Linux distributions, and modern versions of Windows 10/11.
To fetch your raw public IP silently (without standard progress meters), run:
curl -s https://tracethatip.com/raw
Flags explained:
-s(or--silent): Hides progress bars and error output, leaving only the clean returned text.
If your network setup is using IPv4 but you want to force curl to resolve via a specific version (assuming your network has dual-stack capability), you can add version flags:
# Force IPv4 resolution
curl -4 -s https://tracethatip.com/raw
# Force IPv6 resolution
curl -6 -s https://tracethatip.com/raw
2. Using wget (Linux Standard)
wget is another popular utility for non-interactive downloads. It is found by default on many Linux systems (like Debian, Ubuntu, and Red Hat).
By default, wget outputs connection logs to standard error. To print only the IP address to your console, redirect the log output to /dev/null:
wget -qO- https://tracethatip.com/raw
Flags explained:
-q(or--quiet): Silences the logger output.-O-(or--output-document=-): Pipes the downloaded file content directly to standard output (your terminal screen) rather than writing it to a disk file.
3. Using HTTPie (Modern Developer Choice)
httpie is a modern, user-friendly command-line HTTP client that has become popular among API developers for its clean syntax and colorful outputs.
If you have httpie installed, retrieve your IP with:
http -b GET https://tracethatip.com/raw
Flags explained:
-b(or--body): Prints only the response body (your IP string) and suppresses the HTTP response headers.
4. Using PowerShell (Windows CLI)
For Windows administrators working inside PowerShell, native command utilities like Invoke-RestMethod or Invoke-WebRequest allow you to make clean HTTP queries without installing third-party tools.
Open PowerShell and run:
Invoke-RestMethod -Uri "https://tracethatip.com/raw"
If you are using legacy Windows Command Prompt (cmd.exe), curl is supported by default in Windows 10 (Build 17063 and later). Simply run:
curl -s https://tracethatip.com/raw
Saving Time: Creating Terminal Aliases
If you check your public IP frequently, typing out the full URL gets tedious. You can configure a short terminal shortcut—known as an alias—to execute the command in one word (e.g., myip).
On macOS and Linux (Bash/Zsh):
- Open your shell configuration file in your editor:
# If you use Zsh (default on macOS): nano ~/.zshrc # If you use Bash: nano ~/.bashrc - Scroll to the bottom of the file and add your alias definition:
alias myip="curl -s https://tracethatip.com/raw" - Save the file (in nano, press
Ctrl+OthenEnterto save, andCtrl+Xto exit). - Reload your terminal configuration to apply the new alias immediately:
source ~/.zshrc # or source ~/.bashrc - Now, simply type
myipin your shell, and your public IP will display instantly!
On Windows (PowerShell):
- Find your PowerShell profile path by typing
$PROFILEin PowerShell. - Open it or create it if it doesn't exist:
if (!(Test-Path -Path $PROFILE)) { New-Item -ItemType File -Path $PROFILE -Force } notepad $PROFILE - Add a helper function definition to the file:
function Get-MyIP { Invoke-RestMethod -Uri "https://tracethatip.com/raw" } Set-Alias myip Get-MyIP - Save the file and restart PowerShell. You can now run
myipdirectly.
Integrating CLI IP Checks into Automation Scripts
A major benefit of raw plain-text endpoints is the ability to easily capture the response inside shell script variables. Here is a practical Bash example that checks your IP and writes it to a dynamic configuration file:
#!/bin/bash
# Fetch current public IP and store it in a variable
CURRENT_IP=$(curl -s https://tracethatip.com/raw)
# Check if we successfully fetched the IP
if [ -z "$CURRENT_IP" ]; then
echo "Error: Could not retrieve public IP." >&2
exit 1
fi
echo "Your server IP is: $CURRENT_IP"
# Example: Write dynamic host record to hosts file
# echo "$CURRENT_IP api.myserver.internal" >> /etc/hosts
If you are writing scripts that require structured data parsing, you can query our JSON formatter directly by specifying format queries. Learn more on our IP Formatter guide.
Summary
Command line tools like curl and wget combined with raw plain-text routes provide developers with a fast, lightweight, and script-friendly way to fetch public IP addresses. Whether you use terminal aliases for quick debugging or write automated bash scripts, bypassing HTML interfaces is the standard workflow.
Explore more resources:
- Review developer formatting integrations on our IP Formatter dashboard.
- Trace geographic profiles of any IP address on our IP Lookup search tool.
