While most PC users can go through the day without ever wondering how things are done “under the hood” of their machines, there can be many cases in which one would need to know their IP address. Today we will discuss how to find your IP address if you are using Linux, however, let us first dive into what exactly an IP address is and how does it work.
What is an IP Address?
The IP in IP address stands for Internet Protocol and refers to a unique that gets linked to all the online activities you perform. It is a numerical label assigned to each device connected to a network that uses the Internet Protocol. Think of it as your physical address for sending and receiving mail, without it the post office would not know where to send your incoming letters. In the same way, your IP address allows the router or switch to know to which device to send incoming packets to.
How to find IP address on Linux?
There are multiple ways to find your Linux IP address, here are some of them:
- IP command:
Open the terminal and type in the following command
ip addr show
- Ifconfig command:
Type the following command into the terminal
- Hostname command:
Another command you can use to find the IP address on Linux is
All of the aforementioned methods are used to find your private IP address but what if you want to find the Public IP address? First, let us explain the differences between the two.
Private IP address vs. Public IP address: What’s the difference?
Private IP addresses work only within a local network, meaning they are not routed on the internet and no traffic can be sent to them from the internet. These addresses are intended for use in closed LAN (i.e. Local Area Networks), and their allocation is not globally controlled by anyone. This makes private IP addresses impossible to use for direct access to the internet, requiring NAT (i.e. Network Address Translation, a process of replacing a private IP address with a public one) to allow internet access.
Public IP addresses, on the other hand, are used to access the internet. Unlike the private IP addresses, public ones are routed on the internet, meaning only a registered ISP (i.e. Internet Service Provider) can assign you one. Typically, when you get internet for your home, your ISP will provide you with only one public IP address which the installed router uses to connect to the internet.
How to find Public IP address on Linux?
If you are using a Linux version with a GUI (i.e. Graphical User Interface), the steps are very much the same as you would do it on your daily-use Windows machine. Simply open a browser, type www.whatismyip.com into the address bar, and the opened website will display your IP address.
If you prefer the command-line interface for Linux, it is as simple as using wget to display the public IP.
Please note that you should have curl or wget installed on your system, if you do not, here’s how to do it. Type in the following code in the terminal
sudo yum install wget -y
sudo apt-get install wget
Once you have wget installed, type in the following command:
sudo wget -O - -p https://checkip.amazonaws.com
You could also use the curl command:
sudo curl -s https://icanhazip.com