How to Check Your Private & Public IP Addresses in Ubuntu

If you are running a Ubuntu system and need to know both your private and public IP addresses, there are a few simple commands you can use to quickly check them.

First, let’s define what a private and public IP address is. A private IP address is used within a closed network, such as a home or office network, to identify devices and communicate with each other. On the other hand, a public IP address is assigned by your Internet Service Provider (ISP) and is used to connect to the internet.

To check your private IP address in Ubuntu, you can use the following command:

ip addr show

This will display a list of network interfaces on your system along with their corresponding IP addresses. Look for the interface that is connected to your local network (e.g., eth0 or wlan0) and note the IP address listed next to "inet".

To check your public IP address in Ubuntu, you can use the following command:

curl ifconfig.me

This will return your public IP address as seen by external websites. Alternatively, you can use the following command:

dig +short myip.opendns.com @resolver1.opendns.com

This will also return your public IP address by querying the OpenDNS servers.

It’s important to note that your public IP address may change periodically, especially if you have a dynamic IP address assigned by your ISP. If you need to know your public IP address frequently, you may want to consider using a dynamic DNS service that can track changes to your IP address and provide a domain name that always points to your current IP address.

In conclusion, checking your private and public IP addresses in Ubuntu is a simple process that can be done using a few command line tools. Knowing both addresses can be useful for troubleshooting network issues, setting up remote access, or simply understanding how your system is connected to the internet.