In the vast world of Linux, having a reliable way to identify your public IP address is crucial for various networking tasks. Whether you’re troubleshooting connectivity issues, configuring a server, or setting up remote access, knowing your public IP address can be a lifesaver.
In this blog post, we’ll explore several simple and effective methods to find your public IP address from the command line in a Linux environment. So, let’s dive in!
Method 1: Find Public IP address using Curl Command
One of the easiest and most popular ways to retrieve your public IP address is by leveraging external web services like “ifconfig.me” or “ifcongif.io.” or “ipinfo.io.” These services provide your public IP address in response to a simple HTTP request. Here’s how to use “curl” to fetch your public IP:
First, open your terminal application. You can do this by searching for “Terminal” in the application launcher or by pressing “Ctrl + Alt + T” (depending on your Linux distribution).
Type the following command and hit Enter:
$ curl ifconfig.me or $ curl ifconfig.io or $ curl ipinfo.io.
This will send a request to the “ifconfig.me” service, and you will receive your public IP address as a response.
Method 2: Get Public IP Address via ‘dig’ Command
The ‘dig’ command is another valuable tool for querying DNS-related information, including your public IP address. To use ‘dig’ for this purpose, follow these steps:
Open the terminal and run following dig command
$ dig +short myip.opendns.com @resolver1.opendns.com
The ‘dig’ command queries the ‘myip.opendns.com’ domain at the ‘resolver1.opendns.com’ DNS server, which responds with your public IP address.
Method 3: Download Public IP Address via ‘wget’ & ‘ipinfo.io’
In this method, we’ll use the ‘wget command‘ to download our IP address information from the ‘ipinfo.io’ service. Here’s how:
Type the following command and hit Enter:
$ wget -qO - https://ipinfo.io/ip --timeout=20 or $ publicip=$(wget http://ipinfo.io/ip -qO - --timeout=20) $ echo $publicip
The ‘-qO’ flag ensures a quiet output, and ‘ipinfo.io/ip’ provides your public IP address as plain text.
Conclusion
Knowing how to find your public IP address in Linux using the command line is an essential skill for any Linux user. Whether you’re a system administrator, developer, or just an everyday user, these methods will help you quickly and effortlessly retrieve your public IP address. From troubleshooting network issues to securing your connections, this information will prove valuable in various scenarios. So, the next time you need to access your public IP address, remember these command-line techniques to get the job done swiftly!