3 Ways to Find Out Your IP address in Linux

The IP (Internet Protocol) address is a global standard for assigning unique 32/128-bit hexadecimal values to network-attached devices for identification on the local/global network.

What is the difference between the IPv4 and IPv6 protocols?

Multiple internet protocols for assigning IP addresses to your system are currently being used, including IPv4 and IPv6.

The main difference between them is the size of the IP address. IPv4 is a 32-bit address, whereas IPv6 is a 128-bit hexadecimal address.

Initially, we were using IPv4, but then the Internet Engineering Task Force (IETF) developed IPv6 to deal with the future problem of IPv4 address exhaustion.

These IPv4 and IPv6 addresses are used while assigning system identification numbers for local and global network communication.

What is the difference between Local and Global IP addresses?

Internally, communicating to other devices with the help of a mediator (routers, switches, etc.) without any connection to the outside world is known as a “local network.

For the local network, the IP address is assigned by the mediator (router, switches, etc.), helping you connect with other devices.

In a global network, this local network joins the internet with the help of an ISP (Internet Service Provider) by assigning you a unique static or dynamic IP address for your internet recognition.

A few ranges of IPv4 addresses are reserved for private networks. These are listed below.

  • 192.168.0.0/16
  • 172.16.0.0/12
  • 10.0.0.0/18

Is There a Difference Between Static and Dynamic IP Addresses?

A device assigned a static IP address will remain the same until it is manually changed. You can request that your ISP provider allocate static IP addresses for a global network, which will cost you a minimum fee.

Most devices use the dynamic IP address, which does not persist and will be changed over time. This addresses is good for the local communication, gaming, and business. At the same time, static is required while hosting a website and assigning a domain to your server IP, which should be a static address.

Display Local IP using ip command

The ip command, an alternative to the ifconfig command, is more versatile and technically more efficient than ifconfig because it uses Netlink sockets rather than IOCTL system calls.

The ip command is present in major Linux distributions and is used to show or manipulate routing, devices, policy routing, and tunnels.

It can scan all network interfaces (Wi-Fi, Ethernet, etc.) and show the data, including inet and inet6, in the output, as shown below.

$ ip addr

Below is the output of the above command.

display ip address using ip command
Display IP address using the IP command

Display Local IP using hostname command

The hostname command is used to display or set the system’s hostname. The same command can be used to show the host’s network addresses, as shown below.

$ hostname -I

This command only shows your network device’s plain inet or IPv4 protocol address, as shown below.

Display IP address using the hostname command
Display IP address using the hostname command

Display Local IP using netstat command

The netstat command is used for troubleshooting and displays network-related information such as open connections, socket ports, etc.

The below command helps you display your network IP address using the netstat command.

$ netstat -ie

Below is the output of the above command.

Display IP address using the netstat command
Display IP address using the netstat command

Display Global IP using the dig and curl commands

There are two ways to find the global IP address, first by resolving the DNS (OpenDNS, Google DNS, etc). This is the fast and persistent method. Another way is by using external services and reading the return data from the body or header.

The Fastest Way to Display Global IP using the dig command

$ dig +short myip.opendns.com @resolver1.opendns.com
##.###.###.###

The Easiest Way to Display Global IP using the curl command

$ curl ipinfo.io
##.###.###.###
$ curl ifconfig.co
##.###.###.###
$ curl ifconfig.me
##.###.###.###
$ curl https://checkip.amazonaws.com
##.###.###.###

TL;DR

Finding the Local IP address of your Linux system.

$ ip addr
OR
$ hostname -I
OR
$ netstat -ie

Finding the Global IP address of your Linux system.

$ dig +short myip.opendns.com @resolver1.opendns.com
OR
$ curl ipinfo.io

That’s all for now!

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments