Every device connected to a network needs an IP address to communicate with other computers. Finding this address in Linux is essential for troubleshooting network problems, setting up servers, or managing your firewall settings.
Linux provides multiple ways to retrieve your network address, from simple terminal commands to graphical tools. You might need your private address for local network tasks like file sharing, or your public address when configuring remote access.
Understanding how to get your IP address in Linux helps you manage your system more effectively. Whether you prefer command-line utilities or desktop interfaces, several reliable methods exist to display your network information quickly.
How To Get Your IP Address in Linux?
Use the ip Command
Open your terminal and run ip addr show or simply ip a. This displays all network interfaces on your system.
Look for interfaces named eth0 for wired connections or wlan0 for wireless. The ip address command shows your IPv4 address next to the inet field. Ignore the lo interface since it only displays the loopback address.
For cleaner output, try ip -br -c a to see a brief, color-coded display of active connections.
Check with hostname Command
Type hostname -I in your terminal for the fastest results. This command shows all active IPv4 addresses without extra details.
You’ll see multiple addresses if you’re connected to several networks or running VPN connections. The hostname utility automatically excludes loopback addresses, giving you only the relevant information.
Run the ifconfig Command
Execute ifconfig in your terminal. If the command isn’t available, install the net-tools package first using your distribution’s package manager.
Ubuntu and Debian users should run sudo apt install net-tools. Fedora users need sudo dnf install net-tools.
The ifconfig tool displays detailed statistics for each interface. Find the inet entry beside your active adapter name to see your address.
Find Your External Address
To see the address visible to websites, run curl icanhazip.com in your terminal. This queries an external service to return your public-facing address.
Alternative services include api.ipify.org or ifconfig.me. These addresses come from your internet service provider and identify your connection on the internet.
Use Desktop Settings
Desktop users can access network settings through their graphical environment. Click the network icon in your system tray and select connection details.
GNOME users find this under network preferences, while KDE users navigate to system settings. Most desktop environments display the address information directly in the connection properties.
Troubleshoot Connection Issues
If commands return errors, verify your network package installation. Empty address fields mean your interface might be inactive.
Enable inactive connections with sudo ip link set eth0 up. Renew DHCP leases by running sudo dhclient eth0 to obtain a fresh address from your router.
FAQs
What’s the difference between private and public addresses?
Private addresses work only within your local network and typically start with 192.168, 10, or 172.16. Public addresses come from your ISP and are visible on the internet.
Why does hostname -I show multiple addresses?
Multiple addresses appear when you’re connected to different networks simultaneously, running virtual machines, or using VPN connections. Each active network interface gets its own address.
Can I change my IP address in Linux?
Yes, you can manually assign a static address using the ip command or by editing network configuration files. Changes require root privileges and proper subnet configuration.
Which command works on all Linux distributions?
The ip command comes pre-installed on most modern distributions and works universally. It replaced older tools and provides the most reliable way to get network information.
How do I know which network interface to check?
Run ip a to see all interfaces. Wired connections usually appear as eth0 or enp0s3, while wireless connections show as wlan0 or wlp2s0. Active interfaces display an UP status.