How to Get IP Address in Linux

How to Get IP Address in Linux
There are many times when you need to know the IP address of your Linux server or workstation. There are many ways to find the private and public IP addresses of your Linux server or workstation depending on whether you’re using a graphical user interface or not.

In this article, I am going to show you some of the common ways to find the IP address of your Linux server or workstation. So, let’s get started.

Finding IP Addresses with ip Command:

The ip command is the most popular command for finding the IP addresses assigned to the network interfaces of your Linux server or workstation. You will very likely find this command preinstalled on every modern Linux distribution out there.

To find the IP addresses of all the network interfaces connected to your Linux server or workstation, run the ip command as follows:

$ ip address show
Or
$ ip addr show

As you can see, I have 2 network interface attached to my CentOS 7 server. One is ens33 and the other one is ens37. The ens33 network interface has the IPv4 address 192.168.21.131 and the ens37 network interface has the IPv4 address 192.168.50.1.

The ip command also prints the IPv6 address attached to the network interfaces of your Linux server or workstation.

As you can see, on my CentOS 7 server, the IPv6 address attached to the ens33 network interface is fe80:fd75:7722:6480:6d8f. The same way, the IPv6 address configured to the ens37 network interface is fe80:20c:29ff:feaa:bd0e.

If you want, you can also find the IPv4 or IPv6 address configured to a specific network interface.

For example, to find the IP (IPv4 or IPv6) address of the network interface ens33, run the ip command as follows:

$ ip address show dev ens33

As you can see, the IP addresses of the network interface ens33 is shown only.

Finding IP Addresses with nmcli:

nmcli is the command line tool for configuring Linux network interfaces via Network Manager. You can use it to find the IP addresses configured on the network interfaces on your Linux server or workstation.

To list all the Network Manager network interface connections you have on your Linux server or workstation, run the following command:

$ sudo nmcli connection show

As you can see, I have 2 Network manager connections Private (for the interface ens37) and ens33 (for the interface ens33). On Network Manager, you can name your network connections. I have named one here (Private) and left the other (ens33) without naming it anything.

Now, to see the IP addresses configured on the network connection Private, run the nmcli command as follows:

$ sudo nmcli connection show Private | grep address

As you can see, the IPv4 (and IPv6 if configured) address is listed. In my case, the IP address is 192.168.50.1.

We can also find the IP addresses of the ens33 (unnamed) network connection with nmcli as follows:

$ sudo nmcli connection show ens33 | grep address

As you can see, the IP address of the ens33 network connection is listed. But something is different here. The network connection ens33 got the IP address via DHCP. That’s why it is in the DHCP4 OPTION.

Finding IP Addresses with ifconfig Command:

ifconfig is a very old command for finding the IP addresses of Linux servers and workstations. It is so old that is it not even installed on any modern Linux distribution by default. I’ve included it here because you might have to maintain very old servers with some old Linux distribution. The command is very simple to use anyway.

To find the IP addresses of all the network interfaces of your Linux server or workstation, run the ifconfig command as follows:

$ ifconfig

As you can see, the IP addresses of all the network interfaces on my CentOS 7 server is listed.

If you want to list the IP address of any single network interface (let’s say ens33), then run the ifconfig command as follows:

$ ifconfig ens33

As you can see, the IP address of the ens33 network interface is printed on the console only.

Finding IP Addresses in GNOME Desktop Environment:

If you’re using a graphical desktop environment on your Linux workstation such as GNOME 2 or GNOME 3, then you can find the IP address of you network interface graphically.

On GNOME desktop environment, open the Settings app and click on Network as marked in the screenshot below.

Now, select the network interface which you want to find the IP address of and you should be able to find the IP address of that network interface as you can see in the screenshot below.

Finding the Public IP Address of your Server:

You can use a third party website ifconfig.me to find the public IP address of your Linux server very easily. For this to work, you need to have curl installed on your server.

To find the public IP address of your Linux server, run the following command:

$ curl ifconfig.me && echo

So, that’s how you find the IP address in Linux servers and workstations. Thanks for reading this article.

Related Posts
Leave a Reply

Your email address will not be published.Required fields are marked *