When configuring firewalls, setting up a VPN, or diagnosing network routing issues on a headless Linux server, you often need to know the server’s public IP address. While commands like ip a or ifconfig will show you your internal, private network IP address (e.g., 192.168.1.10), they cannot show you the public-facing IP address assigned by your ISP or cloud provider.
To find your public IP address from the terminal, you must request it from an external server using the curl command.
Using curl with ifconfig.me
One of the fastest and most reliable ways to get your public IP address is by querying a dedicated IP-echo service. These services simply read the IP address of the incoming request and print it back as plain text.
Open your terminal and type the following command:curl ifconfig.me
The output will be your exact public IP address and nothing else. For example:203.0.113.45
Alternative IP-Echo Services
If ifconfig.me is down or blocked by your corporate firewall, there are several other reliable, plain-text IP services you can query using curl. They all function exactly the same way:
curl icanhazip.comcurl ident.mecurl ipinfo.io/ipcurl api.ipify.org
How to Get Additional IP Information
If you want more detailed information about your connection—such as your ISP name, geographical region, or ASN—you can query ipinfo.io without the /ip suffix. This will return a nicely formatted JSON object containing detailed network data.
curl ipinfo.io
Note: If your Linux distribution does not have curl installed by default, you can install it using your package manager (e.g., sudo apt install curl on Ubuntu/Debian, or sudo dnf install curl on Fedora). Alternatively, you can use the wget -qO- ifconfig.me command to achieve the same result.