Linux is an incredibly powerful operating system for both servers and desktops. For the most part, anyone using Linux on a desktop could go their entire life without touching the command line.
However, there are a lot of very handy tools from within the terminal window. Take, for instance, identifying your IP address.
Let's say you're using a desktop version of Linux, complete with a desktop environment and all the features that come with it. If you have that desktop configured for DHCP, your machine will be given an IP address from a server or router on your network.
Even with a GUI, you might find it challenging to locate the server's IP address. If that address is configured as static, or manual, users can view it by opening the distribution's network configuration tool and checking either the IPv4 or IPv6 address.
Those DHCP addresses can be tricky to locate with a GUI. From the command line, however, those IP addresses are easy to discern.
Finding the IP address with the 'ip' command
Previously, the command used to find your IP address was ifconfig, which was part of the net-tools application. The command that replaced ifconfig is ip, which is responsible for showing and manipulating routing and networking devices, as well as interfaces and tunnels.
The ip command has several options, but the only one you need to use is a, which is short for all. You can also substitute either address or addr, which will generate the same information.
To list the IP addresses associated with your network interfaces, the command would be the following.
The output would include something like this.
wlo1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 20:79:18:ab:3f:6a brd ff:ff:ff:ff:ff:ff
inet 192.168.1.62/24 brd 192.168.1.255 scope global noprefixroute wlo1
valid_lft forever preferred_lft forever
As you can see, there's more information to be gleaned from a single entry.
Let's say, however, you want to list the information for only a single interface. We'll stick with our wlo1 example. To do this, we can use two options:
- a for all
- show to display information for a specific device
To view only the information for the wlo1 interface, that command would be the following.
ip a show wlo1
The output of that command might still contain more information than you need, as it will show both IPv4 and IPv6 information. If you only need to see your IPv4 address, the command would be the following.
ip -4 a show wlo1
If you only need to see the IPv6 address, the command would be the following.
ip -6 a show wlo1
The formerly used command, ifconfig, will still work for users, but it is deprecated. Regardless, users can still employ the command to find IP addresses in some cases.
Finding the IP address with the deprecated 'ifconfig' command
This command was used for years, but was eventually deprecated because the authors of the command simply stopped developing it.
However, ifconfig is still available. Some users might find its output easier to read than that of the command that replaced it. But since ifconfig has been deprecated, use it sparingly.
First off, you'll have to install it. If you're using a RHEL-based distribution such as Fedora, the required software is already installed. If you're using an Ubuntu-based distribution, you'll need to install net-tools with the following command.
sudo apt-get install net-tools -y
Once the software has been installed, you can locate your IP address with the following command.
The command will generate quite a bit of information, especially if you have multiple network interfaces or containerized applications deployed. The relevant bits of information for your IP address will be within the following two lines.
wlo1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.62 netmask 255.255.255.0 broadcast 192.168.1.255
As you can see in the output, we have a wireless network interface, wlo1, that has the assigned IP address 192.168.1.62.
If you have numerous network cards or deployed containers, you might want to limit the output of the command to a single interface. For instance, you can list out only the details for the wlo1 interface with the following command.
Private vs. public IP addresses
The ifconfig and ip commands are only good for locating private IP addresses.
Users who need to locate a public IP address -- the address that is seen by the outside world -- must employ a command such as curl in the following example.
This command will only list out the public-facing IP address for the network.