Tutorials/Tips

2 methods to get your router’s external, or public IP address

Your router, that device that makes it possible to connect to the Internet, has two IP addresses by default – an internal one where it can be reached by computers behind it, that’s those in your internal network, and an external one that makes it possible for it to talk to other routers on the Internet.

In this article, you’ll learn two tricks to get your router’s public, or external IP address. For most people, finding out what their router’s IP address involves logging into the router’s management dashboard or using one of many websites that provide that service.

If you’re using a Linux computer, you have two more options.

Use Curl to query icanhazip

icanhazip (I-can-haz-IP) is an ad-free service maintained by a well-known Linux user. Visiting http://icanhazip.com will return your IP address, but you can get the same information from the command line using the curl command, a tool used to transfer data from or to a server with the aid of one of several supported protocols, like HTTP, FTP, etc. The following shows how to use curl to query icanhazip.com:

Related Post:  How to disable fast startup in Windows 10

Use Ansible’s ipify_facts module

Ansible is an open source, SSH-based automation, configuration management and deployment tool from Red Hat (via acquisition). Even on Fedora Ansible is not installed by default, so you need to first install it. There’s a package for it in the official repository of every Linux distribution, so use your distribution’s package manager to install it. This article shows how to install it on your favorite Linux distribution.

Related Post:  Disk encryption with Calamares, the Linux installer

The aspect of Ansible that makes it possible to retrieve your router’s public, or external IP address is a module called ipify_facts. The following shows how to use it:

Unlike the icanhazip service, Ansible only returns the IPv4 address, so if you need to know your router’s IPv6 address, use curl to query icanhazip.

Ansible

LinuxBSDos needs your donation to continue!

I hope this article has saved you valuable time and effort to fix a problem that would have taken more time than is necessary. That makes me happy, and why I love doing this. But because more people than ever are reading articles like this with an adblocker, ad revenues have fallen to a level that's not enough to cover my operating costs. That's why I want to ask you a favor: To make a one-time or recurring donation to support this site and keep it going. It's a small favor, but every one counts. And you can make your donation using Patreon or directly via Paypal. Thank you for whatever donation you're able to make.

Donate via Patreon. Donate via Paypal.

Aside from donation, you may also signup to receive an email once I publish new content. Your email will not be shared or traded to anyone. And you can unsubscribe at any time.

Please share:

We Recommend These Vendors and Free Offers

Launch an SSD VPS in Europe, USA, Asia & Australia on Vultr's KVM-based Cloud platform starting at $5:00/month (15 GB SSD, 768 MB of RAM).

Deploy an SSD Cloud server in 55 seconds on DigitalOcean. Built for developers and starting at $5:00/month (20 GB SSD, 512 MB of RAM).

Want to become an expert ethical hacker and penetration tester? Request your free video training course of Online Penetration Testing and Ethical Hacking

Whether you're new to Linux or are a Linux guru, you can learn a lot more about the Linux kernel by requesting your free ebook of Linux Kernel In A Nutshell.


Leave a Comment

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

*