- How to Check IP Address on Linux using Command Line
- Understanding IP Addresses
- The ifconfig Command
- The ip Command
- The hostname Command
- Getting the Public IP Address
- Using dig with OpenDNS
- Using wget or curl with ifconfig.me service
- Conclusion
- How to Find What IP Addresses are Connected to Linux
- Check What IP’s are Connected to Linux Server
- How to Find or Check Your IP Address in Linux
- Find Your IP Address From the Command Line
- Using the hostname Command
- Using the ip addr Command
- Using the ifconfig Command
- Finding Your IP Address in Linux With a GUI
- How to Find Public IP Address
- What is a Public/Private IP Address?
How to Check IP Address on Linux using Command Line
As a Linux user, it’s often necessary to check your computer’s IP address, either for system troubleshooting or network configuration. The IP address, or Internet Protocol address, is a numerical label assigned to each device participating in a computer network. It serves two main functions: identifying the host or network interface and providing the location of the host in the network.
In Linux, there are various methods to retrieve this information, but this article will focus on using the command line interface (CLI), the most powerful and versatile tool at your disposal. By the end of this article, you’ll have learned how to use commands like ifconfig, ip, and hostname to reveal your computer’s IP address.
Understanding IP Addresses
Before we delve into the practical aspect, let’s understand what an IP address is. There are two versions of IP addresses in use today – IPv4 and IPv6. IPv4 is a numerical address like 192.168.0.1, and IPv6 is a more complex alphanumeric address like 2001:0db8:85a3:0000:0000:8a2e:0370:7334. Both serve the same purpose, to uniquely identify a device on a network, but IPv6 was introduced to deal with the long-anticipated problem of IPv4 address exhaustion.
The ifconfig Command
The ifconfig (interface configuration) command in Linux is used to display or configure a network interface. Although this command has been deprecated in favor of the ip command, it is still widely used and you’ll find it present in most systems.
To display your IP address using ifconfig, open your terminal and type the following:
This command will display the details of all network interfaces on your system. The ‘inet’ entry refers to your IPv4 address, and ‘inet6’ refers to your IPv6 address.
- Read: bash ifconfig: command not found on CentOS/RHEL 7
The ip Command
The ip command is a more powerful and modern replacement for ifconfig. It can perform several other tasks that ifconfig can’t.
To display your IP address using the ip command, type the following in your terminal:
Again, ‘inet’ refers to the IPv4 address and ‘inet6’ to the IPv6 address.
The hostname Command
The hostname command is used to display the system’s DNS name, and the -I option will display the IP address of your network interfaces.
To use this command, type the following in your terminal:
This command will display all the network IP addresses assigned to your system.
Getting the Public IP Address
While the aforementioned commands provide information about your private IP address, which is used within your local network, there may be occasions where you need to know your public IP address. This is the address that your Internet Service Provider (ISP) assigns to you, and it’s what the outside world sees when you’re connecting to websites and services on the internet.
In Linux, there’s no built-in command to retrieve the public IP address directly from the command line interface, but you can leverage some external services like dig command with OpenDNS, wget or curl with ifconfig.me service.
Using dig with OpenDNS
The dig command is a tool for querying DNS nameservers for information about host addresses, mail exchanges, nameservers, and related information. To use dig to find your public IP address, type the following in your terminal:
dig +short myip.opendns.com @resolver1.opendns.com
This command tells dig to query the special address myip.opendns.com on the DNS server resolver1.opendns.com. The DNS server will return your public IP address.
Using wget or curl with ifconfig.me service
ifconfig.me is a web service that returns your public IP address. You can access it using either wget or curl.
Both commands will retrieve your public IP address from the ifconfig.me web service.
Conclusion
Understanding how to find your IP address in Linux is a crucial skill for managing and troubleshooting your system and network. Whether you’re a system administrator, a developer, or an enthusiastic Linux user, the command line offers powerful tools for you to unlock the full potential of your Linux system.
Remember, the Linux command line is a powerful tool, but with great power comes great responsibility. Always ensure you understand the commands you are running and the potential impact they may have on your system.
These are just a few of the commands available in Linux for working with IP addresses. As you delve deeper into the world of Linux, you’ll discover many more commands and options that can help you master your system and network.
How to Find What IP Addresses are Connected to Linux
A server is application software that listens to requests over a network and returns the requested files, data, etc. Linux machines have servers installed for many different protocols: Eg. HTTP Server, SSH Server, FTP Server, etc.
The computers which request data from a server (client machines) using either a web browser for HTTP requests or an SSH or FTP Client and are obviously identified by an IP address.
In this article, we will learn how to find out what IP addresses are connected to your Linux server.
Check What IP’s are Connected to Linux Server
The netstat utility used to be a very commonly used command for checking network traffic, routing tables, etc., and in Linux this command is mostly obsolete now and is replaced by the utility ss (socket statistics), which is by default available in most Linux distributions.
To get the list of IP addresses connected to your Linux server, run the following command.
The ‘t’ implies TCP connections, ‘u’ implies UDP connections and the ‘n’ implies that the command should display IP addresses in a numerical format, without name resolution.
If ‘n’ is not specified, the command will display the protocol name instead of its port number (read: find and close ports in Linux).
The column ‘Peer Address: Port are the fields that contain the IP addresses of connected computers to your Linux servers. Thus we have found that these addresses are connected to my server: 10.0.2.2 connected on the service Bootstrap Protocol, 127.0.0.1 (i.e., localhost) connected on SSH and FTP, and 91.189.88.152 connected on HTTP.
Another interesting column in the output is the last column: State, which obviously, means the state of the connection, whether it is timed out or established, etc. We have added something called a ‘state filter’ with the statement ‘state connected’. This will only show the ports which have IPs connected to them.
The state TIME_WAIT signifies that the server has initiated the closing of the connection; it is just kept around to gather and handle some packets of data that arrive late. Similarly, CLOSE_WAIT signifies that the client has initiated the closing, and the connection will be closed once all data packets are dealt with.
Similarly, ESTABLISHED signifies that the connection is currently established and the client computer can access the public files on the server.
Conclusion
Today we learned about the command ss and how to use it to see which IP Addresses are connected to your Linux server. Which command do you use to check traffic on your server? Do let us know in the comments below!
How to Find or Check Your IP Address in Linux
An IP address is a codename assigned to a computer on a network. It works as a postal address, ensuring that network traffic is sent to the correct computer.
In this tutorial you will learn how to find your IP address using a Linux operating system.
Find Your IP Address From the Command Line
There are a few different commands you can use to check your IP address. To run these commands, start by opening a terminal window/command line.
Using the hostname Command
One way to check your IP address from the command-line is by using the following command:
The system will display your internal IP address.
Using the ip addr Command
Check your ip address with the ip addr command:
The system will scan your hardware, and display the status for each network adapter you have. Look for an entry that says link/ether. Below it, you should see one of the following:
inet6 fe80::a00:27ff:fe76:1e71/64
The entries will include one for a wired (Ethernet) adapter and a wireless (Wi-Fi) adapter. You may also have an entry for a virtual adapter. Generally, only one entry will have an IP address listed – that is the one you will want.
Note: The number after the slash – /24 and /64 – specifies the size of the network, and it helps with scanning and mapping network size.
Using the ifconfig Command
The third method to find your IP address involves using the ifconfig command. In the command line, enter the following:
The system will display all network connections – including connected, disconnected, and virtual. Look for the one labeled UP, BROADCAST, RUNNING, MULTICAST to find your IP address. This lists both IPv4 and IPv6 addresses.
Note: When you check your IP address, you may notice the term loopback. This refers to an IP address that returns traffic to the same computer. Usually, the loopback address is 127.0.0.1 . If you see that address listed, either you are looking at the wrong line, or you are not connected to the network.
Read phoenixNAP’s ultimate Linux IP command tutorial with 31 examples to learn more!
Finding Your IP Address in Linux With a GUI
If you are using a point-and-click interface to run your Linux system, you can check your IP address by following these steps:
1. Go to the Application menu and type Settings into the search bar.
2. Click on the Settings icon that appears among the results, as in the image below:
3. Next, find the Network tab in the Settings Menu and click on the Advanced Wired Settings icon.
4. This opens a new pop-up window with details on wired settings. Here you can find both your IPv4 address and your IPv6 address.
How to Find Public IP Address
To find your public IP address, reach out to an external website.
If you are using a browser, navigate to:
If you are using a command-line or terminal, use a retrieval command like curl or wget to display the external IP address:
wget -O - -q https://checkip.amazonaws.com
Note: Did you know that when you use curl to connect to an insecure website, the output responds with an error? To resolve it, visit our guide on making curl ignore certificates.
What is a Public/Private IP Address?
Each computer in a network is required to have its own IP address. If two systems have the same IP address, it will generate errors on the network. Most modern networks will detect the problem and prompt you to fix it. However, older networks might get confused, trying to route traffic to both computers.
Most systems will have two different IP addresses:
- Private IP address: This is the address used on the network. Also, it is the one you will want to use for configuring routing tools. On smaller networks, the internal IP address typically starts with 192.168.x.x. It is dynamically assigned to your computer whenever you connect.
- Public IP address: This is the IP address that registers on a website when you visit it. When you connect to a small network, your computer connects to a router using an internal IP address. That router, in turn, connects to a bigger network (like an Internet Service Provider), which has its own IP address system.
Note: Learn everything you need to know about public and private IP addresses in our article Public vs. Private IP Address.
Now you know how to find a private and public IP address in Linux using multiple methods.
Each option strikes a balance between speed and complexity. Now you have the flexibility to choose, if you only need your internal IP address, you can use the hostname method. If you need more detailed information, view our article on 31 Linux IP Commands with examples.