Find Your Public IP on Linux (curl, wget, dig)
Your IPv4 Address
ISP:City:
Country:
Your IPv6 Address
ISP:City:
Country:
Quick answer: get your public IP in one command
If you just need your public IP right now, run one of these:
curl https://api.getpublicip.com/ip
curl ifconfig.me
Both print your public IPv4 address to the terminal. The rest of this guide covers every variation: curl, wget, dig, forcing IPv4/IPv6, quiet mode, alternative services, and finding your local/private IP.
If your public IP doesn't match the WAN address on your router, your ISP is likely using carrier-grade NAT (CGNAT) — which blocks inbound connections and makes self-hosting impossible without a workaround.
Find your public IP with curl
curl is the most common way to fetch your public IP from the command line. It ships with virtually every Linux distribution.
Basic usage
curl https://api.getpublicip.com/ip
Output (structured — includes ISP and location):
IP Address: 203.0.113.42
ISP: Example ISP
City: Auckland
Country: New Zealand
For just the raw IP address with no extra metadata:
curl -s ifconfig.me
Output:
203.0.113.42
Force IPv4 or IPv6
# Force IPv4
curl -4 ifconfig.me
# Force IPv6
curl -6 ifconfig.me
GetPublicIP also has dedicated endpoints for each protocol:
curl https://ipv4.getpublicip.com/ip # IPv4 only
curl https://ipv6.getpublicip.com/ip # IPv6 only
Other services that work with curl
curl ifconfig.me # plain text IP
curl api.ipify.org # plain text IP
curl icanhazip.com # plain text IP
curl ifconfig.co # plain text IP (also supports JSON)
All return your public IP as plain text. Add -s (silent mode) to suppress the progress bar in scripts.
Find your public IP with wget
wget is available on most Linux systems and is often preferred in environments where curl isn't installed (older minimal installs, embedded systems).
Basic usage
wget -qO- https://api.getpublicip.com/ip
The -q flag suppresses progress output. The -O- flag sends the result to stdout (the terminal) instead of saving it to a file.
For just the raw IP address:
wget -qO- ifconfig.me
Output:
203.0.113.42
Force IPv4 or IPv6
# Force IPv4
wget -4 -qO- ifconfig.me
# Force IPv6
wget -6 -qO- ifconfig.me
GetPublicIP dedicated endpoints:
wget -qO- https://ipv4.getpublicip.com/ip # IPv4 only
wget -qO- https://ipv6.getpublicip.com/ip # IPv6 only
Other services that work with wget
wget -qO- ifconfig.me
wget -qO- api.ipify.org
wget -qO- icanhazip.com
wget -qO- ifconfig.co
Find your public IP with dig or host (DNS method)
If you prefer not to make an HTTP request, you can query your public IP via DNS. This uses your DNS resolver's knowledge of your egress IP.
Using dig (OpenDNS)
dig +short myip.opendns.com @resolver1.opendns.com
Output:
203.0.113.42
Using dig (Google DNS)
dig TXT +short o-o.myaddr.l.google.com @ns1.google.com
Output (quoted TXT record):
"203.0.113.42"
Using host
host myip.opendns.com resolver1.opendns.com
The dig and host methods don't require an HTTP request — just a single DNS lookup. Useful in locked-down environments where outbound HTTP is restricted but DNS is allowed.
Force IPv4 or IPv6
On dual-stack connections (where your machine has both IPv4 and IPv6), the default command may return either address depending on your OS and DNS resolution order. Use these flags to force a specific protocol:
| Tool | Force IPv4 | Force IPv6 |
|---|---|---|
| curl | curl -4 ifconfig.me | curl -6 ifconfig.me |
| wget | wget -4 -qO- ifconfig.me | wget -6 -qO- ifconfig.me |
| GetPublicIP endpoint | curl https://ipv4.getpublicip.com/ip | curl https://ipv6.getpublicip.com/ip |
The dedicated GetPublicIP endpoints (ipv4. and ipv6.) are DNS-level IPv4/IPv6 only, so they work even if your tool doesn't support the -4/-6 flags.
Alternative "what's my IP" services
Several free services let you query your public IP from the command line. Here's a quick comparison:
| Service | URL | IPv4-only mode | IPv6-only mode | Output format |
|---|---|---|---|---|
| GetPublicIP | api.getpublicip.com/ip | ipv4.getpublicip.com/ip | ipv6.getpublicip.com/ip | Structured (IP + ISP + location) |
| ifconfig.me | ifconfig.me | Use curl -4 flag | Use curl -6 flag | Plain text IP |
| ipify | api.ipify.org | api.ipify.org | api6.ipify.org | Plain text (or ?format=json) |
| icanhazip.com | icanhazip.com | ipv4.icanhazip.com | ipv6.icanhazip.com | Plain text IP |
| ifconfig.co | ifconfig.co | Use curl -4 flag | Use curl -6 flag | Plain text (or JSON with /json) |
All work with both curl and wget. GetPublicIP returns metadata alongside the IP; the others return a single line with just the address.
If you need a permanent, dedicated public IP for self-hosting (rather than just checking what your current IP is), see our guide on getting a static IP.
Find your local IP address on Linux
Your local (private) IP is the address assigned to your machine on your LAN — not visible to the outside internet. Here are the ways to find it.
Quick one-liner
hostname -I
This prints a space-separated list of all IP addresses assigned to the machine (both IPv4 and IPv6, all interfaces). It's the fastest way to see everything at a glance.
Detailed: ip command (modern)
ip a
You will see output similar to:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host noprefixroute
valid_lft forever preferred_lft forever
2: eno0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 00:94:37:b7:8a:88 brd ff:ff:ff:ff:ff:ff
inet 192.168.66.245/24 brd 192.168.66.255 scope global dynamic noprefixroute wlan0
valid_lft 71625sec preferred_lft 71625sec
inet6 fe80::767e:5882:2cdd:686e/64 scope link noprefixroute
valid_lft forever preferred_lft forever
On the left you'll see interface names: lo (loopback) and eno0 (Ethernet). Wireless adapters are usually named wlan0.
link/ether— the MAC address (hardware identifier assigned by the manufacturer).inet— the IPv4 address. In this example,192.168.66.245.inet6— the IPv6 address. Addresses starting withfe80are link-local (not routable beyond the LAN).
To show only IPv4 or only IPv6 addresses:
ip -4 a # IPv4 only
ip -6 a # IPv6 only
Older Linux systems: ifconfig
If your system doesn't have the ip command, use:
ifconfig
Which outputs similar information:
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
eno0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.66.245 netmask 255.255.255.0 broadcast 192.168.66.255
inet6 fe80::767e:5882:2cdd:686e prefixlen 64 scopeid 0x20<link>
ether 00:94:37:b7:8a:88 txqueuelen 1000 (Ethernet)
The inet line is the IPv4 address. The inet6 line is the IPv6 address.
NetworkManager (nmcli)
On systems using NetworkManager (most desktop distros), you can also use:
nmcli device show | grep IP4.ADDRESS
This shows IP addresses grouped by network interface (Ethernet, Wi-Fi, VPN, etc.).
Frequently Asked Questions
How do I find my public IP address on Linux?
The quickest way is to run curl https://api.getpublicip.com/ip or curl ifconfig.me from a terminal. Both print your public IPv4 address to stdout. For IPv6, use curl -6 https://ipv6.getpublicip.com/ip. You can also use wget, dig, or host to accomplish the same thing.
How do I get my public IP with curl?
Run curl https://api.getpublicip.com/ip to get your public IP. Add -s for silent mode (no progress bar). Force IPv4 with curl -4 or IPv6 with curl -6. Alternative services include curl ifconfig.me, curl api.ipify.org, and curl icanhazip.com.
How do I get my public IP with wget?
Run wget -qO- https://api.getpublicip.com/ip to print your public IP to stdout. The -q flag suppresses progress output and -O- sends the result to stdout instead of a file. Force IPv4 with wget -4 or IPv6 with wget -6.
How do I force IPv4 or IPv6 when fetching my IP?
Both curl and wget support -4 (force IPv4) and -6 (force IPv6) flags. For example, curl -4 ifconfig.me always returns your IPv4 address even on a dual-stack connection, and curl -6 ifconfig.me returns your IPv6 address. GetPublicIP also offers dedicated endpoints: ipv4.getpublicip.com and ipv6.getpublicip.com.
What is the quietest one-liner to print just my IP?
curl -s ifconfig.me prints only your IP with no extra output. With wget, use wget -qO- ifconfig.me. With dig, use dig +short myip.opendns.com @resolver1.opendns.com. All three return a single line containing just your public IPv4 address.
What are the best services for getting my IP from the command line?
Popular free services include api.getpublicip.com (returns IP with ISP and location metadata), ifconfig.me (plain text IP), api.ipify.org (plain text, supports JSON), icanhazip.com (plain text), and ifconfig.co (supports JSON and plain text). All work with curl and wget.
How do I find my public IP using dig?
Run dig +short myip.opendns.com @resolver1.opendns.com to query OpenDNS for your public IP. Or use dig TXT +short o-o.myaddr.l.google.com @ns1.google.com for the Google DNS equivalent. The dig method does not require an HTTP request, just a DNS lookup.
What is the difference between public IP and local IP on Linux?
Your local (private) IP is the address assigned to your machine on the LAN, typically in the 192.168.x.x, 10.x.x.x, or 172.16-31.x.x range. Your public (external) IP is what the rest of the internet sees when you connect. Your router performs NAT to translate between the two. Use ip a or hostname -I for local IPs and curl ifconfig.me for your public IP.
How do I list all local IPs on my machine?
Run hostname -I for a quick space-separated list of all assigned IPs. For detailed interface-by-interface output, use ip a (or ip -4 a for only IPv4, ip -6 a for only IPv6). On older systems without the ip command, use ifconfig. For NetworkManager-managed systems, nmcli device show lists IPs per interface.
Why does my router show a different IP than curl ifconfig.me?
If your router's WAN IP does not match what curl ifconfig.me returns, your ISP is almost certainly using carrier-grade NAT (CGNAT). CGNAT places an extra layer of NAT between your router and the public internet, sharing one public IP across many customers. This blocks inbound connections and makes self-hosting impossible without a workaround. See our full guide on self-hosting behind CGNAT for solutions.
