Internet Protocol (IP) address is one of the most significant components of the modern IT infrastructure. An IP address is a unique machine address that is used for internal network communication as well as to open a website on a web browser. To initiate communication with a system, you must know its IP address.
In this tutorial, we will learn how to get the IP address of a Linux computer using command-line as well as GUI methods.
- A computer with Linux operating system.
- Access and familiarity with Linux command-line interface.
- Eagerness to learn about IP addresses and new Linux commands.
What is an IP Address
An IP address is a unique IP address or codename assigned to your Linux computer on either a local or public network. The IP address is used to identify your computer to send and receive data. It serves as an identifier for communication to send network traffic to the correct address.
An IP address is a numeric string, such as 192.168.2.1, which also contains location information to enable two-way communication on your Linux computer. There are two types of IP addresses:
- Private IP address, which is local to your computer and is used for inter-network communication. For example, connecting to a printer or another computer in the network.
- Public IP address, which is assigned by your Internet Service Provider (ISP) to communicate outside the local network. For example, browsing a website or sending emails.
You must not share your private IP addresses with anyone outside your organization or network.
Get IP address in Linux Using Command Line
Linux provides several commands to help you check the IP address of your computer. These commands are used for different operations, but they all can show the IP address. Open a terminal window or command-line interface to run these commands.
1. Using the ip addr Command
The easiest and the most used command to check your private IP address is the ip addr command. Type the ip command followed by addr to find IP address:
The ip command scans your computer and shows the status of all the configured network adaptors. The IP addresses are shown below link/ether. The output displays only one entry for an Ethernet adaptor and only one entry for a Wi-Fi adaptor.
If you have configured a virtual adaptor, you will also see an entry for that. In most cases, you will see only one private IP address and that is the one you need for connecting to your computer.
2. Using the ifconfig Command
Another command to check your Linux computer’s IP address is to use the ifconfig command. Enter the following ifconfig command without any options:
This output shows information about all connections on your computer. Check the name of your adaptor and information after this, such as UP, BROADCAST, RUNNING, and MULTICAST to identify the private IP address. Both IPv4 and IPv6 IP addresses are displayed here.
If you see the term loopback with your IP address, it means that the IP address redirects traffic to the same computer. In the above example, the LOOPBACK address is 127.0.0.1.
3. Using the hostname Command
You can also use the hostname command with the -I option to check your IP address as shown in the following example:
You can also use the hostname command to check the loopback or internal IP address using the -i option:
4. Using the nmcli Command
The nmcli command is generally used for network management. However, you can also use this command to check your private IP address. The following command shows the general output of the nmcli command when used without any options:
To check the IP address along with the hardware device, use the following command:
nmcli -p device show
Check IP address in Linux Using GUI
You can also use the Linux GUI to check the IP address of your computer. The following steps will guide you on how to find the wired connection and wireless IP addresses of your Ubuntu Linux computer:
1. Open the Application menu and search for Settings in the search bar:
2. Select Network from the left navigation and click Settings for your wired connection:
3. This will show you the IPv4 and IPv6 IP addresses of your computer:
Get Public IP Addresses Linux Command Line
The public IP addresses are used to communicate with the computers outside your local network. When you connect to the Internet, this IP address is used.
If you prefer to use the command-line, then use the following curl command to find your public IP address:
curl -s https://icanhazip.com
You can also use the this command to find your public IP address:
wget -O - -q https://checkip.amazonaws.com
Using an Internet browser, you can get your public IP address by simply searching for “my ip address” on Google. You can also find out your public IP address by using the following websites:
The public IP address is visible on the Internet and your ISP uses it to track your browsing activity and keep a record of it for a given period. This is required by law enforcement to keep this record.
In this tutorial, we learned how to find the private IP addresses and public IP addresses on your Linux computer. We have covered both command-line options and GUI options to find IP addresses. Each option provides different additional information, and you can choose the one that suits your requirements.