How to Check Your IP Address in Linux
Whether you're working at home, managing a server, or just curious about your connection, knowing how to check your IP address in Linux is a useful skill. Your IP address serves as your device's “identifier” on a network, whether it's the local network in your home or the global internet.
This is assigned to your device by your Wi-Fi router or your company's internal network. These addresses are not reachable from the internet and are generally in the following ranges:
- 10.x.x.x
- 172.16.x.x to 172.31.x.x
- 192.168.x.x
This is your device's address on the internet, visible to anyone accessing a website or service. Your Wi-Fi router shares this public IP with all devices connected to it. Websites you visit or services you interact with see your public IP.
Additionally, there are two versions of IP addresses:
- IPv4: The older version, using 32-bit addresses, giving us roughly 4 billion possible addresses (formatted as x.x.x.x where each x is a number from 0 to 255).
- IPv6: A newer version, using 128-bit addresses, designed to handle the ever-increasing number of devices on the internet. It has a much larger pool of possible addresses. Now that we've got the basics, let’s dive into how you can check your private and public IP addresses on Linux.
If you're looking for your private IP address, which is assigned to your device within your local network (e.g., your home Wi-Fi or office network), you can use several commands:
This command shows detailed information about all network interfaces on your system, including your IP address. You’ll see output like eth0 (for wired connections) or wlan0 (for wireless connections), and under the inet section, you’ll find your private IP.
A more modern, commonly used command that shows your network interfaces and their associated IP addresses. Look for the line that starts with inet—this will be your private IP address.
This is a quick command to return your primary private IP address. It's simple and to the point.
If you’re on a system using NetworkManager (like most modern Linux distros), this command will display the network devices and their IP addresses.
A clever workaround that shows your local IP by querying a remote IP address (like 1.2.3.4) and using the route info to return your private address.
Finding Your Private IP on a GNOME Desktop (GUI Method) If you're using a GNOME desktop, it’s just as easy to find your IP without using the terminal. Here's how:
- Open the Activities overview and search for Network (for a wired connection) or Wi-Fi (for wireless).
- In the Network Settings window, click the gear icon next to the network you're connected to.
- Your IP address will be listed in the Network Profile.
Your public IP address is the one that the world sees when you browse the internet. It’s the address that websites and services use to communicate with your device. You can check your public IP directly from the command line using a few simple commands:
A quick and straightforward way to find your public IP address.
Another simple tool to return your public IP.
This one also gives you your public IP and can provide additional information if needed.
A reliable way to get your public IP in a single line.
This one returns your public IP along with a bit of HTML formatting, so it’s more suited for quick checks.
-
Private IP Addresses: Used internally within your local network (your router assigns these to devices like your phone, laptop, etc.). They cannot be accessed from the internet, which is why we use NAT (Network Address Translation) to map these private addresses to a single public IP when accessing the internet.
-
Public IP Addresses: This is the address used when communicating with external networks, including websites, apps, and services. Every public IP is unique and globally reachable.
NAT (Network Address Translation) helps manage the use of limited public IP addresses by mapping multiple private IPs to a single public one. For example, when you connect multiple devices to your Wi-Fi router, they all share the same public IP to access the internet, but each device gets its own private IP.
- Private IP Addresses: Used within your local network, not accessible from the outside world. Common ranges: 10.x.x.x, 172.16.x.x to 172.31.x.x, 192.168.x.x.
- Public IP Addresses: Used to connect to external networks and the internet, accessible from anywhere. Each device on the internet has a unique public IP address.
- IPv4: The older, 32-bit addressing scheme, with around 4 billion possible addresses.
- IPv6: The newer, 128-bit scheme, capable of handling an astronomically larger number of addresses. To find your private IP, use commands like ifconfig, ip addr, or hostname -I. For your public IP, you can use curl commands like curl ifconfig.me or curl icanhazip.com.
By understanding both your private and public IP addresses, you gain better control over your network and online presence. Whether you need to troubleshoot your network or just want to know how your device is connected, these commands will help you quickly find what you’re looking for.