How To Find IP Address In Linux Using Terminal?

How To Find IP Address In Linux Using Terminal?

 

An IP address is a unique identifier that is assigned to each device connected to a computer network and uses Internet protocol for communication.

A computer uses this address to send data to a specific computer. IPv4 and IPv6 are two versions of IP addresses available nowadays. Every computer with an IP address has an IPv4 address and many of them are starting to use IPv6.

While troubleshooting network issues, setting up a new connection, configuring the firewall, etc you need to know the IP address of your system. So this article describes different methods for finding the IP address on a Linux system.

Classification of IP address

Generally, the IP addresses both IPv4  and IPv6 can be classified into two categories –

  • Public IP
  • Private IP

Public IP address –

The public IP address can be used anywhere on the internet for example every website that is accessible to everyone on the internet, has a unique IP address which is considered as public IP.

Private IP address

Private IP addresses are commonly used for local area networks such as home networks, offices, etc. Each device connected to a private network is assigned with unique IP addresses known as private IP.

Finding public IP address

You can find the public IP in your terminal by using tools such as curl, dig, wget, etc. There are many online services that provide public IP addresses. Now to find the IP address of your system use one of the given commands in your terminal –

curl ident.me
curl ifconfig.me
dig ANY +short @resolver2.opendns.com myip.opendns.com
curl bot.whatismyipaddress.com
curl -4/-6 icanhazip.com
wget -O - -q https://icanhazip.com/

OR if you are working on a system that has GUI then type ‘what is my ip’ in your browser to see your public IP address.

The IP address displayed here is an IPv4 public IP address.

Finding private IP address

To find the private IP address of a system you can use one of the commands that are given below –

hostname -I | awk '{print $1}'
ifconfig -a

This command will display the information of all the network interfaces that are currently up including the loopback interface. The highlighted part in the image is the private IP of the system which is a version 4 IP address.

nmcli -p device show

This command also displays information of different network interfaces on a system. The IP address highlighted in the image is the private IP which is also a version 4 of the IP addresses. You can also find the private IP version 6 in this information –

ip addr
ip route get 1.2.3.4 | awk '{print $7}'

Conclusion

By using the above commands you can find the public and private IP addresses of a system. If you want to say anything on this topic then write us in the comments below.

Previous How To Use apt-mark Command In Linux?
Next How to enable desktop sharing through terminal
 

About author

You might also like

Networking 0 Comments

Manual NIC Setup

This post was last updated on June 3rd, 2020 at 04:16 pmManually setting up a network interface. This can come in handy if you need networking but don’t have any

Networking 0 Comments

How to Use ifconfig to set MAC address in Linux, Unix, FreeBSD etc.

This post was last updated on November 10th, 2020 at 08:11 pmLinux has a built-in command ifconfig that is used to configure wired network interfaces. In this article I am

Networking 0 Comments

DHCPD Quick Setup Instructions

This post was last updated on May 27th, 2020 at 04:44 pmSample of how to set up DHCPD server on Red Hat 7.0 Copy over the sample dhcpd.conf file cp

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply