Operations 3 min read

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.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Retrieve Your Public IP Address from the Linux Terminal Using curl and wget

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/i

Curl JSON output

curl ipinfo.io/json
curl ifconfig.me/all.json
curl www.trackip.net/ip?json

Curl XML output

curl ifconfig.me/all.xml
curl "得到所有IP细节(挖掘机)"
curl ifconfig.me/all

Using 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 ; echo

Example Bash script

#!/bin/bash

PUBLIC_IP=$(wget http://ipecho.net/plain -O - -q ; echo)
echo $PUBLIC_IP

These 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

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxcURLPublic IPwget
Liangxu Linux
Written by

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.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.