3 Ways to Find IP address in Linux

Table of Contents

How to check IP address on Linux is a commonly asked question during a Linux job interview. Knowing the IP address of our system can be useful in many situations. Here are 3 methods to get the Ip address. These commands are safe to run without changing anything.

The following Linux commands can be used to check ip address.

  • ip addr
  • ip addr show eth0
  • ifconfig -a
  • ifconfig eth0
  • ip route
  • ip route show dev eth0


What is Ip address?

IP address is used in a system for communication. It is a numerical label such as An IP address serves two main functions: network interface identification and location addressing.

An IP address is the identifier that enables our device to send or receive data packets across the internet. It holds information related to our location and therefore making devices available for two-way communication.

Most internet service providers still use IPv4. It’s based on 32 binary bits, consists of four numbers from 0 to 255, and is separated by dots. For example,

Understanding network interface and Ip address

If a system uses several network cards (several network interfaces) and all of them use IP protocol, then every network interface has its own IP address. Several IP addresses may be assigned on one network interface.

The first address is called a primary address while the others are called secondary addresses or aliases. Using secondary IP addresses is common with web servers.

Find public IP address in Linux

The easiest way to get your public IP address is to Google it. Type in “what is my IP address” or “how to find my IP address,” and Google will tell you. Your IP address is public to the internet. We can get it from many online tools. It can be easily tracked by others.  You can also get your public IP address here.

Your Internet service provider tracks all your online activity by your ip and they maintain a record of it for a certain period of time. Thus, any time a law enforcement agency wants to see what you’ve been up to online, all they have to do is get your data from your ISP.

We recommend using VPN service to hide your IP address to prevent misuse of your personal information. When you use a VPN, you don’t connect directly to the internet on your own. Instead, you first connect to your VPN provider. You only visit sites, download files, stream videos, and access your online bank accounts or credit card portals after connecting through your VPN.

Check out NordVPN website to secure your online experience by hiding IP address


Find IP address with ip addr command in Linux

The best way to find IP address in Linux is using ip addr command.  All we need is to open the terminal then type ip addr in the prompt. The number next to inet is our IP address. This command will list IP address, MAC address, MTU size and other information about a network interface.

We can also type ip addr or ip a for short.

  • ip addr – Show information for all addresses
  • ip addr show dev em1 – Display information only for device em1


From the following example. the ip address for eth0 is
# ip addr
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc mq state UP group default qlen 1000
link/ether 02:3f:4d:eb:52:e7 brd ff:ff:ff:ff:ff:ff
inet brd scope global dynamic noprefixroute eth0
valid_lft 3198sec preferred_lft 3198sec

Using Cloud Linux server to practice Linux commands

Cloud Linux server is a great way to experiment with different Linux commands and learn more about the operating system. Even if you run some harmful commands by mistake, you can create a new server immediately. Check with their online support for any Linux questions. This can save you a lot of time in learning Linux.

Is it safe to expose your IP address?

It is not safe to expose your IP address.  Your ISP can track your online movements through your IP address. They can track the websites that you visit, the amount of time you spend there, and the kind of activity you perform when on a particular site.

Just as your ISP, search engines, and governments can follow you around by using your IP address, so can hackers. They can learn your identity and location through the IP address.We recommend using NordVPN to hide your IP.  In this way, you can get around restrictions enforced by your ISP and maintain privacy over your online activity.

They offer fast speeds and strong security protection, and they have 5422 servers in over 60 countries. NordVPN will instantly hide your IP address, secure all of your online activity, and even help protect you against malware.

Get Ip address with ifconfig command in Linux

The “ifconfig” command is another most common command used to view IP related information. To use this command to find the IP address, just type “ifconfig -a” in the shell prompt. If we are only interested in certain interfaces, eth0, etc. then: ifconfig eth0

# ifconfig -a
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 9001
inet netmask broadcast
ether 02:3f:4d:eb:52:e7 txqueuelen 1000 (Ethernet)
RX packets 1142453 bytes 77488923 (73.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5835535 bytes 8505814381 (7.9 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0


Get Ip address with ip route command in Linux

The “ip route” command can also be used to find the IP address of a system. In order to find the IP address of a system, use the command as follows.This command will print out the IP address of our system along with other network details. Once we execute the command we will see an output similar to the text below.

$ ip route
default via dev eth0 proto dhcp metric 100 dev eth0 proto kernel scope link src metric 100

This information shows us the server’s IP routing table, which is essentially a set of rules used to determine where data will be directed.When using this technique to find a server’s IP, we will want to notice the lines containing `src` followed by an IP address.On these lines, the IP address following `src` are the IP(s) configured on the server.

In the example above, we can see the servers routing table, showing that the server has an IP address of ``.

Check IP address with Bash script in Linux

We can get a list of the network interfaces and IPv4 addresses on our server by running the following command:

ip -4 -o a | cut -d ‘ ‘ -f 2,7 | cut -d ‘/’ -f 1
The output lists the interface names on the left and the associated IP addresses on the right.



What is the difference between an ip address and a MAC address in Linux?

The main difference between an ip address and a MAC address in Linux is that an ip address is a network address, while a MAC address is a hardware address. An ip address is used to identify a computer on a network, while a MAC address is used to identify the network interface of a computer. Additionally, the MAC address is permanent, while the ip address can be changed.

How can I troubleshoot problems with my ip address in Linux?

If you are having problems with your ip address in Linux, there are a few things you can do to troubleshoot the issue. First, check the status of your network interfaces with the ifconfig or ip command. If one of your network interfaces is not active, try restarting the interface with the ifdown and ifup commands.

If we are still having problems, try using the netstat or ping command to troubleshoot the issue. The netstat command can be used to display information about all active network connections, the ping command can be used to test connectivity between two computers.

What is a static ip address in Linux?

A static ip address is an IP address that is assigned to a network interface permanently. This means that the IP address will not change, even if the system is rebooted.

Can I change my ip address in Linux?

Yes, we can change our ip address in Linux. To do this, open a terminal and type “sudo ifconfig eth0” This will change the IP address of your eth0 interface to, which is an address that can be assigned to a network interface in Linux.

When we change our ip address in Linux, our system will be assigned a new IP address that can be used to access the Internet. This new IP address will be associated with the network interface that we specify.

3 Ways to Find MAC Address In Linux

Share on facebook
Share on twitter
Share on linkedin

If you meet any issues with Linux, record them with Loom and send the link to us here. We will reply ASAP.

Load WordPress Sites in as fast as 37ms!