How to Retrieve Your Public IP Address from the Linux Terminal Using curl and wget
This guide explains several methods to obtain your public IP address directly from a Linux terminal—using curl, wget, or DYNDNS services—and provides example commands, JSON/XML outputs, and a simple Bash script for automation, useful for headless servers and command‑line users.
In this article we introduce multiple ways to view your public IP address from a Linux terminal. While ordinary desktop users may not need it, the technique is valuable for headless Linux servers or situations where only basic command‑line tools are available.
Public IP addresses are allocated by InterNIC and are unique on the global Internet. They are represented as CIDR blocks, and routing information for these addresses is stored in Internet routers so that traffic can reach the correct destination.
Curl plain‑text output
curl icanhazip.com
curl ifconfig.me
curl curlmyip.com
curl ip.appspot.com
curl ipinfo.io/ip
curl ipecho.net/plain
curl www.trackip.net/iCurl JSON output
curl ipinfo.io/json
curl ifconfig.me/all.json
curl www.trackip.net/ip?jsonCurl XML output
curl ifconfig.me/all.xml
curl "得到所有IP细节(挖掘机)"
curl ifconfig.me/allUsing DYNDNS services
curl -s 'http://checkip.dyndns.org' | sed 's/.*Current IP Address: \([0-9\.]*\).*/\1/g'
curl -s http://checkip.dyndns.org/ | grep -o "[[:digit:].]\+"Using wget instead of curl
wget http://ipecho.net/plain -O - -q ; echo
wget http://observebox.com/ip -O - -q ; echoExample Bash script
#!/bin/bash
PUBLIC_IP=$(wget http://ipecho.net/plain -O - -q ; echo)
echo $PUBLIC_IPThese commands can be incorporated into scripts or run manually to quickly discover the external IP address of a Linux machine without a graphical interface.
Source: https://developer.aliyun.com/article/198785
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
