To check the IP address in Linux, you can use ip addr, ifconfig, or ip route commands. Open up a terminal and type in any of the above commands. Press enter. It will display all of your network interfaces and their associated IP addresses.
The ip addr and ifconfig commands will list all available network interfaces on the Linux system, including their IP addresses and status. IP route command displays the kernel’s routing table. This command also lists the IP address of each interface.
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 192.0.2.1. 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, 103.86.98.1.
Understanding network interface and Ip address
Can a Linux server have more than one network interface?
Yes, a Linux server can have more than one network interface. This is often the case with web servers and other portable devices that need to be able to connect to different networks.
Can a network interface have more than one 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.
In the following example, there are two IP addresses on the physical interface eth0.
eth0 Link encap:Ethernet HWaddr 00:50:56:8F:44:C7
inet addr:10.252.10.51 Bcast:10.252.10.255 Mask:255.255.255.0
eth0:0 Link encap:Ethernet HWaddr 00:50:56:8F:44:C7
inet addr:10.252.10.52 Bcast:10.252.10.255 Mask:255.255.255.0
Find IP address with ip addr command in Linux
The most efficient 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 the IP address. This command will list IP address, MAC address, MTU size and other information about a network interface.
We can also type ip address or ip a for short. Here are the commands we can use to check ip address with ip addr command in Linux.
- ip addr – Show IP address for all interfaces
- ip addr show dev em1 – Display information only for device em1
- ip addr show up – Show IP address for the running interfaces
By default, the ip addr command will display information for all of the network interfaces on the Linux system.
From the following example, there are three network interfaces l0, eth0 and eth1. The ip address for eth0 is 10.1.0.143 and the ip address for eth1 is 10.254.222.37.
# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
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 10.1.0.143/24 brd 10.1.0.255 scope global dynamic noprefixroute eth0
valid_lft 3198sec preferred_lft 3198sec
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether fa:16:3e:18:3a:76 brd ff:ff:ff:ff:ff:ff
inet 10.254.222.37/23 brd 10.254.223.255 scope global dynamic eth0
valid_lft 70000sec preferred_lft 70000sec
In the following example, there are two IP addresses on the physical interface eth0.
# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
link/ether 00:50:56:8f:44:c7 brd ff:ff:ff:ff:ff:ff
inet 10.252.10.51/24 brd 10.252.10.255 scope global eth0
inet 10.252.10.52/24 brd 10.252.10.255 scope global secondary eth0:0
Find IP address with ip addr show dev command in Linux
The ip addr show dev command is used to view the IP address for a specific network interface. The syntax for the command is:
ip addr show dev interface_name
This will display the IP address for the specified interface. So if you want to display information only for specific device like eth1, you can use this command ip addr show dev eth1.
$ ip addr show dev eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether fa:16:3e:18:3a:76 brd ff:ff:ff:ff:ff:ff
inet 10.254.222.37/23 brd 10.254.223.255 scope global dynamic eth0
valid_lft 69786sec preferred_lft 69786sec
The ip addr show up command is used to list the running interface. This command will show all of the IP addresses that are currently up on the system.
So if you want to display information only for the running interfaces, you can use ip addr show up.
The ip address command can also be used to add or delete the IP addresses for a network interface.
- Add an address – ip addr add 192.168.1.1dev em1 – Add address 192.168.1.1 to device em1
- Delete an address – ip addr del 192.168.1.1 dev em1 – Remove address 192.168.1.1 from device em1
There are a number of other options that you can use with the ip addr command. For more information, you can type command ip addr help.
Related article: 3 ip commands you need to know about Linux networking
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 10.1.0.143 netmask 255.255.255.0 broadcast 10.1.0.255
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
The ifconfig command is a very power tool. It is a network configuration utility that can be used to configure a network interface. The ifconfig command can be used to set an IP address, netmask, and gateway for a network interface. The ifconfig command can also be used to troubleshoot network issues.
If a network interface is not working, the ifconfig command can be used to check the status of the network interface.
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 10.1.0.1 dev eth0 proto dhcp metric 100
10.1.0.0/24 dev eth0 proto kernel scope link src 10.1.0.143 metric 100
This information shows us the server’s IP routing table and network gateway, which are 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 `10.1.0.143`.
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.
lo 127.0.0.1
eth0 10.1.0.79
Let’s break down the command:
- ip -4 -o a : output each record on a single line, replacing line feeds with the ‘\’ character. This is convenient when you want to get ip address in bash script.
- The cut command is used to extract a subset of the lines from a file, or to extract a subset of the columns from a file. The “-d” parameter specifies the delimiter that is used to separate the fields. The “-f” parameter specifies the field number(s) that you want to extract. Here’s an example: cut -d’,’ -f1,3 filename.txt This command will extract the first and third column from the lines in the file filename.txt, using commas as the delimiter.
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.
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.
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. You can check this post about how to get the MAC address in Linux.
troubleshoot problems with 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 network 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.
change my ip address in Linux
We can change our ip address in Linux. To do this, open a terminal and type “sudo ifconfig eth0 192.168.1.5.” This will change the IP address of your eth0 interface to 192.168.1.5., 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. This new IP address will be associated with the network interface that we specify.
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 the online support for any Linux questions. You can save a lot of time when learn Linux.