addresses Command in Linux with Examples
Last Updated :
28 Apr, 2025
Finding a way of finding IP addresses is very important in the Linux system administration and the management of networks. Certainly, you will find a need for using it when troubleshooting problems you have with your network connectivity, or if you're configuring services on a network. The chapter goes over various ways by which an IP address could be found within Linux for you to have a broad toolkit of network management.
Some Common Methods to Find IP Address in Linux
An IP (Internet Protocol) address is a unique number assigned to your device on a network. It’s like a phone number for your computer, router, or phone.
1. Using the `ifconfig` command
It shows the network interfaces (like Wi-Fi or Ethernet) and their details.
Syntax
ifconfig [interface]
Simple Example
ifconfig
- It look for
inet
under your active interface (e.g., eth0
for Ethernet, wlan0
for Wi-Fi).
ifconfig command listing network interfaces and their IP addressesKey Options for ifconfig Command
Option | Explanation |
---|
-a | Show all interfaces even if they are down |
---|
-s | Short list, like netstat -i |
---|
[interface] | Information for specified interface |
---|
2. Using the `ip` command
It scroll to your active interface. IPv4 addresses start with inet
, IPv6 with inet6
.
Syntax
ip [options] [object] [command]
Simple Example
ip addr
Output of ip addr command with detailed network interface informationKey Options for the ip Command
Option | Description | Example |
---|
-4 | Show only IPv4 addresses | ip -4 addr |
---|
-6 | Show only IPv6 addresses | ip -6 addr |
---|
show dev [interface] | Show information of a specific interface | ip addr show dev eth0 |
---|
Other Commands
1. hostname Command
It instantly shows your private IP address.
hostname -I
Output of hostname -I command showing the IP addresses of the system2. nmcli Command
It shows detailed network info, great for Wi-Fi/Ethernet management.
nmcli device show
Output of the nmcli device show command showing network device information3. Public IP Address
It reveals your network’s public IP address.
curl ifconfig.me
Output of curl ifconfig.me command which is showing the public IP addressCase Study: Network Troubleshooting
Assume you need to troubleshoot network connection. It is the script that depends on quite a number of methods for gathering total network summary:
#!/bin/bash
echo "Network Troubleshooting Report"
echo "==============================="
echo "1. IP Addresses (ip command):"
ip -4 addr | grep inet
echo "\n2. Default Gateway:"
ip route | grep default
echo "\n3. DNS Servers:"
cat /etc/resolv.conf | grep nameserver
echo "\n4. Public IP Address:"
curl -s ifconfig.me
echo "\n5. Ping Test to Google DNS:"
ping -c 4 8.8.8.8
This script gives an excellent view of the network setup of the system, which can be very helpful in trying to troubleshoot connectivity problems.
Conclusion
Knowing how to find the IP addresses in Linux is a very basic, elementary skill for system administrators and network professionals. We have discussed different methods-from the old ifconfig command to the new ones like ip and nmcli. Each of these methods has its strength, and knowing when to use it will make you just that little bit more efficient in managing your Linux systems and troubleshooting problems about networks.
Similar Reads
addr2line command in Linux with Examples 'addr2line' command in Linux is used to convert addresses into file names and line numbers. When the executable files/object files are run with the 'objdump' command, the file is de-assembled and the machine code is displayed. These machine instructions for the executable are displayed along with th
4 min read
ip Command in Linux with Examples The ip command in Linux is a powerful utility for network configuration and management. It allows users to interact with various networking components such as network interfaces, routing tables, addresses, and more. Here, we will look into the 'ip' command, covering each aspect with examples, code,
7 min read
apt-get command in Linux with Examples The command-line tool `apt-get` is the most popular package management tool used in our Debian-based Linux operating system. This article provides an overview of `apt-get` and its basic syntax. It will include the most commonly used commands, their syntax, description, and examples. It also gives an
15+ min read
host command in Linux with examples host command in Linux system is used for DNS (Domain Name System) lookup operations. In simple words, this command is used to find the IP address of a particular domain name or if you want to find out the domain name of a particular IP address the host command becomes handy. You can also find more s
2 min read
pmap command in Linux with Examples The pmap command in Linux is a powerful utility used to display the memory map of a process. A memory map provides insight into how memory is allocated and distributed within a running process. This can be incredibly useful for developers and system administrators when debugging memory issues, optim
3 min read