[email protected]Office hours: Mon – Fri 9:00AM – 5:00PMLinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Getting startedMarch 23, 2023

How to Find/Get your IP Address

How To Find/Get Your IP Address

This article explains several different methods of determining the public and private IP Addresses of a Linux system.

Knowing the IP address of your device is important when troubleshooting network issues, setting up a new connection, or configuring a firewall.

IP Addresses can be classified into two categories, public and private. A public IP is an IP Address that is unique and can be accessed from the Internet. Private IP addresses are reserved for internal use within your private network without being directly exposed to the Internet. Furthermore, there are two types of IP addresses, IP version 4 (IPv4), and IP version 6 (IPv6).

 

Find Your Private IP Address

Private IP addresses are not routable over the Internet and are meant to work within the local network only. Typically, a private IP address is assigned to each device inside your local network by your router. This provides a unique IP address for all devices within the local network, such as your phone, laptop, smart TV, printer, media center, etc.

Devices on the local network are connecting to the Internet through NAT (network address translation).

The following IPv4 address ranges are reserved for the private networks:

You can determine your system private IP address by querying the network stack with commands such as ip, ifconfig or hostname.

In Linux, the standard tool for displaying and configuring network interfaces is ip .

To display a list of all network interfaces and the associated IP address type the following command:

ip addr

The output will look something like below. The private IP address is highlighted.

You can also use the following commands to display the private IP address:

hostname -I
ifconfig

 

Find Your Public IP Address

A Public IP address is a globally routable IP address that is assigned to a network device, allowing it direct access to the Internet. They are assigned to the device by its ISP, and each device has a unique public IP address.

The public IP addresses are used by home routers, web servers, mail servers, and so on.

Determining the public IP address involves contacting a remote server over the HTTP/HTTPS or DNS protocol and obtaining the IP address from the remote server response.

On Desktop machines, the easiest way to find out your public IP address is to type “what is my ip” in your browser:

If you are on a headless Linux server or you want to assign the IP address to a shell script variable you can use command-line tools such as dig , curl and wget .

Most of the DNS providers, such as OpenDNS and Google allows you to query their servers and obtain your public IP address.

You can use any of the commands below to get your IP:

  • dig ANY +short @resolver2.opendns.com myip.opendns.com
  • dig ANY +short @resolver2.opendns.com myip.opendns.com
  • dig ANY +short @ns1-1.akamaitech.net ANY whoami.akamai.net

There are many online HTTP/HTTPS services that respond with your public IP address. Here are some of them:

  • curl -s http://tnx.nl/ip
  • curl -s https://checkip.amazonaws.com
  • curl -s api.infoip.io/ip
  • curl -s ip.appspot.com
  • wget -O - -q https://icanhazip.com/

If any of the commands above is not working, there may be a problem with the online service.

You can even create an alias in your ~/.bashrc or ~/.zshrc file, so you don’t have to type and remember a long command. For example, you can add the following alias:

alias pubip='dig ANY +short @resolver2.opendns.com myip.opendns.com'

Now, whenever you need to find your public IP just type pubip in your terminal.

 

Conclusion

We have shown you several different commands and online services that you can use to find out your private and public IP address.

Keep reading
How to Implement Network Segmentation and Resource Isolation in Linux.
February 6, 2024

How to Implement Network Segmentation and Resource Isolation in Linux.

How to Implement Network Segmentation and Resource Isolation in Linux. Securing and managing networks in a Linux environment involves advanced practices like network segmentation and resource isolation. This guide explores these concepts, providing detailed instructions and examples for…

Read article
How to open or close ports in Linux.
February 6, 2024

How to open or close ports in Linux.

How to open or close ports in Linux. Effectively managing ports on your Linux system is crucial for both security and service accessibility. This comprehensive guide will provide a detailed walkthrough on opening and closing ports using the robust tools iptables and ufw. Understanding these…

Read article
How to use ypdomainname command.
January 23, 2024

How to use ypdomainname command.

How to use ypdomainname command. In the realm of Linux networking, the ypdomainname command plays a crucial role in the context of the Network Information Service (NIS). NIS, formerly known as Yellow Pages, is a distributed database service that facilitates the sharing of network configuration and…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, colocation, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Office hours: Mon – Fri 9:00AM – 5:00PM