Question: How do I find out the IP address of my system in Linux command line?
Answer: a Few years back, ifconfig was the favorite way to know IP address in Linux. Unfortunately, ifconfig command has been deprecated. If you try to use this command today, you are most likely to see the following error:
command not found: ifconfig
So, how do you find the IP address then? Well, you can use the ip command for this purpose. ip command is versatile and can be used for several other things related to networking.
But just to show the IP address, use the command with addr option in the following manner:
And you will see an output like this:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1 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 inet6 ::1/128 scope host valid_lft forever preferred_lft forever
2: wlp58s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 9c:b6:d0:d0:fc:b5 brd ff:ff:ff:ff:ff:ff inet 192.168.1.20/24 brd 192.168.1.255 scope global dynamic wlp58s0 valid_lft 81675sec preferred_lft 81675sec inet6 2a01:cb1d:19b:6600:9f97:614b:a4b7:1b83/64 scope global noprefixroute dynamic valid_lft 1768sec preferred_lft 568sec inet6 fe80::673d:dc47:edb2:57ae/64 scope link valid_lft forever preferred_lft forever
In the above output, you can ignore the first one called lo (loopback). You can see that the IP address is displayed 192.168.1.20. The 24 that follows it is the subnet mask.
That’s it. That’s how you display IP address of host system in Linux command line.
P.S. Actually, you can still use ifconfig command. It is present in net-tools package. You can install it using the package manager of your system. However, use of net-tools is not encouraged so I suggest sticking with the ip command.