10 Ways to Find Public IP Address in Ubuntu Terminal
Knowing your public IP address is crucial for various networking tasks, including server management, remote access, and security configurations. In Ubuntu, you can easily find your public IP address using the terminal. Here are ten methods to help you achieve that.
1. Using the curl
Command with ifconfig.me
The curl
command is a powerful tool for interacting with web servers. You can use it to fetch your public IP address by querying a web service like ifconfig.me
.
curl ifconfig.me
This command sends a request to ifconfig.me
, which then returns your public IP address. It’s simple, fast, and works without additional configurations.
2. Using wget
with ipinfo.io
wget
is another command-line utility that can retrieve files from the web. You can use it with ipinfo.io
to get your public IP address.
wget -qO- ipinfo.io/ip
This command downloads the content from ipinfo.io/ip
and displays it in the terminal. The -qO-
option ensures that the output is quiet and printed directly.
3. Using the dig
Command
The dig
command is typically used for DNS lookups, but it can also retrieve your public IP address by querying OpenDNS.
dig +short myip.opendns.com @resolver1.opendns.com
This command asks OpenDNS for your IP address using its DNS server. The +short
option ensures that only the IP address is displayed.
4. Using the host
Command
The host
command is another DNS lookup utility that can also be used to find your public IP address.
host myip.opendns.com resolver1.opendns.com
This command works similarly to dig
but with a slightly different syntax. It queries the OpenDNS server and returns your public IP address.
5. Using curl
with icanhazip.com
Similar to ifconfig.me
, icanhazip.com
is another web service that returns your public IP address.
curl icanhazip.com
This command is quick and straightforward. It sends a request to icanhazip.com
, and the service returns your public IP address.
6. Using curl
with ipify.org
ipify.org
is a simple service that provides your public IP address in a lightweight format.
curl https://api.ipify.org
This command requests your IP address from ipify.org
. You can also get the result in JSON format by adding /?format=json
to the URL.
7. Using wget
with ident.me
ident.me
is a minimalist web service that returns your IP address. You can use wget
to fetch this information.
wget -qO- ident.me
This command downloads your IP address directly from ident.me
and prints it in the terminal.
8. Using lynx
Text-based Browser
lynx
is a text-based web browser that can also be used to retrieve your public IP address.
lynx -dump http://ipecho.net/plain
This command uses lynx
to load the webpage at ipecho.net/plain
, which displays only your public IP address.
9. Using nslookup
with OpenDNS
nslookup
is another DNS query tool that can be used to find your public IP address through OpenDNS.
nslookup myip.opendns.com resolver1.opendns.com
This command queries OpenDNS for your IP address, similar to dig
and host
.
10. Using External API with curl
You can also use an external API to find your public IP address. Many services provide this, like ip-api.com
.
curl http://ip-api.com/line/?fields=query
This command fetches your public IP address from ip-api.com
and displays it in the terminal.
Conclusion
Knowing how to find your public IP address in Ubuntu is essential for various networking tasks. Each of these methods is simple and effective, allowing you to choose the one that best fits your needs. Whether you prefer curl
, wget
, or DNS lookup tools, you can easily retrieve your public IP address with these commands.
Thank you for reading the article! If you found the information useful, you can donate using the buttons below:
Donate ☕️ with PayPalDonate 💳 with Revolut