[email protected]Support 24/7 · Billing 09:00 – 00:00LinkedInXFacebook
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 use Python if..else statement.
July 24, 2023

How to use Python if..else statement.

How To Use Python If..Else Statement. Python if Statement The most basic form of the if statement in Python is as follows: if EXPRESSION: STATEMENT The if statement starts with the if keyword followed by the conditional expression. The EXPRESSION must be followed by (:) colon. If the EXPRESSION…

Read article
How to understand to  Extract tar.xz File.
July 21, 2023

How to understand to Extract tar.xz File.

How To Understand To Extract Tar.Xz File. This article explains how to use the tar command to extract (or unzip) .tar.xz or .txz archives. Xz is a popular algorithm for compressing files based on the LZMA algorithm. By convention, the name of a tar archive compressed with xz ends with either…

Read article
How to use case Bash break and continue.
July 21, 2023

How to use case Bash break and continue.

How To Use Case Bash Break And Continue. Bash break Statement In Bash, break and continue statements allows you to control the loop execution. The break statement terminates the current loop and passes program control to the command that follows the terminated loop. It is used to exit from a for,…

Read article
Get in Touch

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

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

Get Started →Contact Us
[email protected]Support 24/7 · Billing 09:00 – 00:00