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 set up a Ruby project structure on Ubuntu 16.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:  Make GRUB the default Boot Manager on an HP 250 G5

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

Subscribe to LinuxBSDos.com

Subscribe to receive the latest articles in your Inbox

Trust me, you'll not be spammed...

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 *

*