Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
VGSOURCES
Get listed

CGNATPATCH 2026.10.27

How to Find Your External IP Address on Linux (IPv4, IPv6, curl, wget, and dig)

By VGSources Team 8 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

To see the public IP address that internet services observe from a Linux machine, run curl -4 https://api.getpublicip.com/ip. Use -6 instead of -4 to check IPv6. These commands query an external service, so they report the address after your router, carrier-grade NAT, VPN, proxy, or other gateway has processed the connection—not necessarily an address shown by your local network tools.

What is an external IP address on Linux?

An external, public, or internet-facing IP address is the address a remote service sees as the source of your connection. It can be different from every address configured on your Linux interfaces because network address translation (NAT), a VPN, a proxy, a container network, or an upstream gateway may change the egress address.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

There may be two valid answers on a dual-stack host: one public IPv4 address and one public IPv6 address. Always state which address family you checked. A lookup over IPv4 does not prove what an IPv6-only destination would see.

How do I find my public IPv4 address with curl?

The quickest interactive check is a plain-text HTTPS request:

Popular on Amazon
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter | 4Pack Type C Female to A Male Cable Converter for Apple Duo 17 16 15 14 Plus,iWatch Watch 12 11 10,iPad 9 8 Air,Airpods 5 4
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
curl -4 https://api.getpublicip.com/ip

The response should be a single IPv4 address. For quieter output with errors still displayed, use:

curl -4 -sS https://api.getpublicip.com/ip

The -4 option forces IPv4, while -sS hides the progress meter but keeps useful error messages. HTTPS protects the request in transit and makes the endpoint dependency explicit.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Which plain-text services can curl query?

These alternatives are useful when one endpoint is unavailable or filtered. Their response formats and availability can change, so use the documented plain-text response rather than assuming every service returns identical metadata.

Endpoint Example command Typical use
api.getpublicip.com/ip curl -4 -sS https://api.getpublicip.com/ip HTTPS, forced IPv4, one-line result
ifconfig.me curl -s https://ifconfig.me Simple curl fallback
api.ipify.org curl https://api.ipify.org Plain-text lookup
icanhazip.com curl https://icanhazip.com Plain-text lookup
ifconfig.co curl https://ifconfig.co Alternative lookup service

Third-party lookup services are dependencies: the command fails if DNS, routing, firewall policy, TLS validation, or the service itself is unavailable. For a diagnostic, compare two independent endpoints instead of treating one response as infallible.

How do I check my public IPv6 address?

Force the IPv6 path with:

curl -6 https://api.getpublicip.com/ip

If the host has working IPv6, the response should be an IPv6 address. A dual-stack machine can return different addresses for -4 and -6; that is expected because they use separate protocol stacks and may follow different gateways.

The same family selection is available with Wget:

wget -6 -qO- https://api.getpublicip.com/ip

If IPv6 fails while IPv4 succeeds, check local IPv6 configuration, the default IPv6 route, firewall rules, and whether the network actually provides IPv6 service. Do not “fix” an IPv6 result by replacing it with IPv4 when the application specifically requires IPv6.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Also popular on Amazon
Sale
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter | USB C Dongle with 90W Max Power Delivery, 3×5Gbps USB A Data Ports, for MacBook, Dell, and More (Charger Not Included)
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

How can I find the external IP without curl?

GNU Wget can print the response directly when curl is not installed:

wget -qO- https://api.getpublicip.com/ip

-q suppresses progress output and -O- writes the downloaded data to standard output. Add -4 or -6 when the address family matters:

wget -4 -qO- https://api.getpublicip.com/ip
wget -6 -qO- https://api.getpublicip.com/ip

This is particularly convenient in a minimal recovery shell or a server image that includes Wget but not curl. As with curl, validate that the returned content is the documented address format before feeding it to another program.

How do I find my public IP with dig when HTTP is blocked?

DNS-only methods work when outbound DNS is available but HTTP requests are restricted. OpenDNS provides a resolver query that returns the caller’s address:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
dig +short myip.opendns.com @resolver1.opendns.com

A Google Public DNS variant is:

dig TXT +short o-o.myaddr.l.google.com @ns1.google.com

The first command normally prints an address directly. The TXT query may include quotation marks because DNS represents the answer as a text record; remove only presentation characters if a script needs a bare value.

These commands avoid an HTTP request, but they still depend on DNS reachability, the selected resolver, and network policy. Resolver-based answers can also describe the DNS path rather than the path used by a separate application. When diagnosing an unusual result, compare a DNS answer with an HTTPS lookup.

Also popular on Amazon
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter | 85W Max PD, 2 USB 3.0 & 1 USBC Data Ports, SD/TF Card Reader, for Laptops/Mac and Other Type C Devices (Charger Not Included)
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

What is the difference between a public IP and a local IP on Linux?

Local commands show addresses assigned to interfaces on the machine. They do not, by themselves, reveal the address a remote internet service sees.

hostname -I       # space-separated local addresses
ip -4 addr show   # local IPv4 addresses
ip -6 addr show   # local IPv6 addresses

hostname -I may list several addresses, including loopback exclusions, private LAN addresses, virtual interfaces, and container-related addresses. The ip utility exposes the addresses on each interface, along with enough context to identify which device owns them.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Question Command or method What it tells you
What addresses are configured locally? ip -4 addr show, ip -6 addr show, or hostname -I Interface assignments on this Linux host
What public IPv4 does an internet service see? curl -4 ... or wget -4 ... IPv4 egress address after gateways and NAT
What public IPv6 does an internet service see? curl -6 ... or wget -6 ... IPv6 egress address for that path
What address does a DNS resolver infer? dig ... Address observed through the chosen DNS method

Private RFC 1918-style addresses such as 192.168.x.x, 10.x.x.x, and 172.16.x.x are normally LAN addresses. They are not routable as your public identity on the open internet.

Why does the address differ from my router or another website?

Different tests can legitimately use different egress paths. A VPN may supply its own public address; a proxy reports the proxy’s address; a container may exit through a host or orchestration gateway; and a multi-homed server may select different interfaces according to routing policy.

Carrier-grade NAT

If the address returned by an external service does not match your router’s WAN address, your ISP may be using carrier-grade NAT (CGNAT). CGNAT adds another translation layer, can share one public address among multiple customers, and prevents unsolicited inbound connections according to Jeremy Branson, a Network Engineer at GetPublicIP, in information updated September 29, 2026: “If your public IP doesn’t match your router’s WAN address, your ISP is using carrier-grade NAT (CGNAT), which blocks inbound connections.”

CGNAT is different from ordinary home NAT because you may not control the upstream translation. Port forwarding on your own router cannot create an inbound path through an ISP-managed NAT layer.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Also popular on Amazon
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray | Data transfer & Fast charging for MacBook, iPhone 17/16/15, iPad, Samsung Galaxy, Apple Watch
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Routing and interface selection

On a host with several interfaces, inspect routes when results seem inconsistent:

ip route
ip -6 route

The route chosen for the lookup determines which interface, gateway, VPN tunnel, or namespace supplies the source path. Run the test in the same network namespace and service context as the application you are troubleshooting; a host shell and a container shell can have different egress addresses.

How do I automate a public-IP lookup safely?

For a shell script that needs one IPv4 value, capture the plain-text response and check the command status before using it:

public_ip=$(curl -4 -sS https://api.getpublicip.com/ip) || {
  printf 'Public IP lookup failedn' >&2
  exit 1
}
printf 'Public IPv4: %sn' "$public_ip"

Use -6 when the script’s contract is IPv6. Keep the endpoint’s response format documented; if a service returns metadata or multiple lines, parse its documented field rather than assuming the first line is an address.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Keep the endpoint on HTTPS when supported.
  • Set a timeout in unattended jobs so a hung network request cannot stall the whole script.
  • Validate the result before inserting it into firewall rules, DNS records, or configuration files.
  • Avoid writing the address to public logs; it identifies the network egress point even though it is not usually a secret credential.
  • Cache only when your use case tolerates stale data. Residential and mobile addresses can change.

Which Linux method should I choose?

Situation Recommended method Reason and limitation
One-time IPv4 check curl -4 -sS https://api.getpublicip.com/ip Short, readable HTTPS command; requires curl and HTTP access
One-time IPv6 check curl -6 -sS https://api.getpublicip.com/ip Forces IPv6; fails if the host has no usable IPv6 path
curl unavailable wget -qO- ... Uses Wget’s standard-output mode
HTTP blocked but DNS works dig +short myip.opendns.com @resolver1.opendns.com DNS-only; depends on resolver policy and DNS reachability
Need to inspect local interfaces ip -4 addr show or ip -6 addr show Shows local assignments, not the public egress address
Diagnosing VPN, NAT, or routing Run forced-family HTTPS and DNS checks, then inspect routes Reveals whether path and resolver observations disagree
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What should I check when every lookup fails?

  1. Confirm the binary exists with command -v curl, command -v wget, or command -v dig.
  2. Check name resolution separately. If hostnames do not resolve, inspect the system resolver configuration and DNS reachability.
  3. Test the address family explicitly. A failed default request may be trying IPv6 when only IPv4 works, or the reverse.
  4. Check the default routes with ip route and ip -6 route.
  5. Review firewall, proxy, captive-portal, and egress-filter rules. Corporate and cloud networks often permit DNS while blocking arbitrary HTTPS.
  6. Compare two endpoints or an HTTPS result with a DNS result. A single service outage should not be mistaken for a missing public address.

If the machine is intentionally offline, there is no reliable local command that can discover the internet-facing address without an observation point outside the machine. In that case, inspect the upstream router or network provider’s management interface, recognizing that CGNAT can make the router’s WAN value differ from the address seen by websites.

What does finding the address prove—and what does it not prove?

A lookup proves the source address observed by that particular service over that particular protocol and route at that moment. It does not prove that the address is static, that inbound connections are possible, that every website will see the same value, or that IPv4 and IPv6 use the same gateway.

Also popular on Amazon
Sale
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display | 85W Max PD, 1 Powered USB-C 5Gbps & 2 Powered USB-A 3.0 5Gbps Data Ports, for MacBook Pro, MacBook Air, Dell and More (Black)
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

For a server-access problem, pair the lookup with route inspection and an inbound test from an independent network. For an allowlist, record the address family, timestamp, and network path so a later address change is not confused with a firewall regression.

Frequently Asked Questions

Can I find my external IP address with no internet connection?

Not reliably from the Linux host alone. An external address is defined by what an outside service or upstream gateway observes, so an offline machine can only show configured local addresses or information supplied by its router or provider.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Is my public IP address permanent?

That depends on the connection and provider. Dynamic residential, cellular, and many cloud egress addresses can change after reconnects or policy changes; a static assignment is a separate service and should be verified with the provider rather than inferred from one lookup.

Why does a browser show a different IP than my terminal?

The browser may use a VPN, proxy, secure DNS setup, split tunnel, or a different address family from the shell command. Compare the browser’s network path with forced curl -4 and curl -6 tests, and check whether the browser is running inside a separate container or profile.

Can I host a game server behind CGNAT?

Direct inbound port forwarding generally will not work through an ISP-managed CGNAT layer. Ask the provider for a public or static address, use an approved relay or tunnel, or host the service on a network where inbound routing is available.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

CGNATcurlDIGIP AddressIPv4IPv6LinuxNATNetworkingwget

Leave a reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.