Your IP address on Ubuntu Linux appears when you run `ip addr show` or `hostname -I` in the terminal. Knowing how to check ip address in linux ubuntu is a fundamental skill for anyone managing a system, setting up a network, or troubleshooting connections. Whether you need your private IP for local networking or your public IP for internet-facing services, Ubuntu provides several straightforward commands to get the information quickly. This guide covers every method, from the simplest one-liners to advanced network diagnostics, ensuring you can find any IP address on your Ubuntu machine.
How To Check Ip Address In Linux Ubuntu
Checking your IP address in Ubuntu is easy once you know the right commands. The terminal is your best friend here, but you can also use graphical tools if you prefer. Below, we break down the most common and reliable methods, starting with the quickest.
Using The Ip Command (Modern And Recommended)
The `ip` command is the modern replacement for the older `ifconfig`. It’s installed by default on all Ubuntu systems and gives you detailed network interface information.
- Open your terminal (Ctrl+Alt+T).
- Type the following command and press Enter:
ip addr show - Look for your active network interface (usually `eth0`, `ens33`, or `wlp2s0` for Wi-Fi). Your IPv4 address will appear after `inet`, like `192.168.1.10/24`.
You can also use a shorter version: ip a. This does the same thing with less typing. The output shows all interfaces, including loopback (`lo`). Ignore that one unless you’re testing local services.
Understanding The Output
The `ip addr show` output can look confusing at first. Here’s what the key parts mean:
- Interface name: Like `eth0` (Ethernet) or `wlan0` (Wi-Fi).
- inet: Your IPv4 address (e.g., `192.168.1.5/24`). The `/24` is the subnet mask.
- inet6: Your IPv6 address (if enabled).
- state UP: Means the interface is active and connected.
Using The Hostname Command (Quick And Simple)
If you just want your IP address without all the extra details, `hostname -I` is the fastest method. Note the capital `I`.
- Open the terminal.
- Type:
hostname -I - Press Enter. You’ll see your IP address(es) listed, separated by spaces.
This command only shows IP addresses, no interface names. It’s perfect for scripts or when you need the number quickly. One small tip: if you have multiple interfaces, it shows all of them.
Using The Ifconfig Command (Older But Still Works)
While `ifconfig` is deprecated on modern Ubuntu, many users still prefer it. You may need to install it first.
- Install net-tools:
sudo apt install net-tools - Then run:
ifconfig - Look for your active interface. The IP address is listed after `inet addr:`.
Note: `ifconfig` is not installed by default on newer Ubuntu versions (18.04+). The `ip` command is the recommended alternative.
Checking Your Public IP Address
Your public IP is the one visible to the internet. It’s different from your private IP (like `192.168.x.x`). To find it, you need to query an external service.
- Using curl:
curl ifconfig.meorcurl icanhazip.com - Using wget:
wget -qO- ifconfig.me - Using dig:
dig +short myip.opendns.com @resolver1.opendns.com
These commands fetch your public IP from a remote server. They work even if you’re behind a router or NAT.
Using The Graphical User Interface (GUI)
If you prefer not to use the terminal, Ubuntu’s settings app shows your IP address.
- Open Settings from the system menu.
- Go to Network (or Wi-Fi if connected wirelessly).
- Click the gear icon next to your active connection.
- Your IP address appears under the Details tab.
This method is great for beginners. It also shows your DNS, MAC address, and default route.
Checking IP Address For Specific Interfaces
Sometimes you only want the IP for a particular interface, like your Wi-Fi or Ethernet.
- For Ethernet:
ip addr show eth0(replace `eth0` with your interface name) - For Wi-Fi:
ip addr show wlan0 - For all interfaces:
ip addr show
You can find your interface names by running ip link show. Common names include `ens33`, `enp0s3`, or `wlp2s0`.
Using The Nmcli Command (NetworkManager)
If your Ubuntu uses NetworkManager (which it likely does), `nmcli` is a powerful tool.
- Run:
nmcli device show - Look for your active connection. The IP address is listed under IP4.ADDRESS[1].
You can also get a concise view with: nmcli -p device show. This command is especially useful for scripting and automation.
Using The Route Command To Find Default Gateway
Your default gateway is the IP address of your router. Knowing it helps with network troubleshooting.
ip route show default– Shows your default gateway.route -n– Older method, shows routing table.
The gateway IP is usually something like `192.168.1.1` or `10.0.0.1`. You can ping it to test connectivity.
Using Python To Get IP Address
For advanced users or automation, Python can retrieve your IP address.
- Open Python in terminal:
python3 - Run these commands:
import socket
hostname = socket.gethostname()
ip_address = socket.gethostbyname(hostname)
print(ip_address)
This returns your primary IP address. For more control, use the `netifaces` library.
Common Issues And Fixes
Sometimes you might not see an IP address. Here are common problems:
- No IP address: Your interface might be down. Check with
ip link set eth0 up. - Multiple IPs: You might have virtual interfaces or Docker containers. Use
hostname -Ito see all. - Wrong interface: Make sure you’re looking at the active interface (state UP).
- Permission denied: Some commands need `sudo`, like
sudo ifconfig.
Using The Hostnamectl Command
While `hostnamectl` is mainly for changing the hostname, it also shows some network info.
- Run:
hostnamectl - Look for Static hostname and Icon name. This command doesn’t show the IP directly but gives context.
It’s more useful for system identification than IP lookup.
Using The Arp Command For Local Network
To see other devices on your network (and their IPs), use `arp`.
arp -a– Shows all ARP entries, including IP and MAC addresses.arp -n– Shows numeric IPs without hostnames.
This helps you find other machines on your local subnet.
Using The Ping Command To Verify IP
Once you have an IP, you can test connectivity.
- Ping your own IP:
ping 192.168.1.10 - Ping the gateway:
ping 192.168.1.1 - Ping an external site:
ping google.com
If you get replies, your IP is working correctly.
Using The Dig Command For DNS And IP
`dig` is a DNS lookup tool that can also show your public IP.
- Run:
dig +short myip.opendns.com @resolver1.opendns.com - This returns your public IP as seen by OpenDNS.
It’s reliable and doesn’t require external websites.
Using The Nslookup Command
Similar to `dig`, `nslookup` can resolve hostnames to IPs.
nslookup google.com– Shows Google’s IP.nslookup your-hostname– Shows your local IP if DNS is configured.
It’s less common now but still available.
Using The Systemd-Networkd Tools
If your system uses systemd-networkd, you can use `networkctl`.
- Run:
networkctl status - Look for your interface and its IP address.
This is a modern alternative to `nmcli` for systems without NetworkManager.
Using The Iwd Command (For Wi-Fi)
If you use iwd instead of wpa_supplicant for Wi-Fi, you can check IP with `iwctl`.
- Run:
iwctl station wlan0 show - Look for IPv4 address.
This is less common but good to know.
Using The Netstat Command
`netstat` shows network connections, routing tables, and interface statistics.
netstat -i– Shows interface statistics, including IP.netstat -rn– Shows routing table.
It’s another deprecated tool but still widely used.
Using The Ss Command
`ss` is the modern replacement for `netstat`. It shows socket statistics.
ss -tuln– Shows listening ports and their IPs.ss -i– Shows interface information.
It’s faster and more detailed than `netstat`.
Using The Lshw Command
`lshw` lists hardware details, including network interfaces.
- Run:
sudo lshw -class network - Look for ip address under each interface.
This gives a comprehensive view of your network hardware.
Using The Hwinfo Command
Similar to `lshw`, `hwinfo` shows hardware info.
hwinfo --network– Shows network interfaces and their IPs.
Install with sudo apt install hwinfo if needed.
Using The Inxi Command
`inxi` is a system information tool that includes network details.
- Run:
inxi -N– Shows network interfaces. - Run:
inxi -i– Shows IP addresses.
It’s not installed by default but is very handy.
Using The Neofetch Command
`neofetch` displays system info in a colorful way, including your IP.
neofetch– Shows IP under Network.
It’s more for show than serious work, but it works.
Using The Screenfetch Command
Similar to `neofetch`, `screenfetch` shows your IP.
screenfetch– Look for IP in the output.
Both are fun but not essential.
Using The Ufw Command For Firewall IP
If you use UFW (Uncomplicated Firewall), you can check its status.
sudo ufw status verbose– Shows firewall rules, not your IP.sudo ufw show listening– Shows listening services and their IPs.
This helps you see which services are bound to which IPs.
Using The Iptables Command
`iptables` shows firewall rules, which can include IP addresses.
sudo iptables -L -n– Lists rules with numeric IPs.
It’s complex but powerful.
Using The Nmap Command For Network Scanning
`nmap` can scan your network and show IPs of other devices.
- Install:
sudo apt install nmap - Run:
nmap -sn 192.168.1.0/24(replace with your subnet).
This lists all active IPs on your network.
Using The Tcpdump Command
`tcpdump` captures network traffic and shows IP addresses.
sudo tcpdump -i eth0 -n– Shows packets with IPs.
It’s advanced but useful for deep troubleshooting.
Using The Wireshark Tool
Wireshark is a graphical packet analyzer. It shows all IP traffic.
- Install:
sudo apt install wireshark - Open it and select your interface.
- Look for IP addresses in the capture.
It’s overkill for just checking your IP but excellent for network analysis.
Using The Ettercap Tool
`ettercap` is for man-in-the-middle attacks but can also show IPs.
sudo ettercap -T -M arp– Shows active IPs.
Use with caution.
Using The Arp-Scan Tool
`arp-scan` is a fast way to find all IPs on your local network.
- Install:
sudo apt install arp-scan - Run:
sudo arp-scan --local
It shows IP, MAC, and vendor info.
Using The Fping Command
`fping` is like ping but for multiple hosts.
fping -g 192.168.1.0/24– Pings all IPs in the subnet.
It’s fast and efficient.
Using The Netdiscover Tool
`netdiscover` is another ARP scanner.
sudo netdiscover -r 192.168.1.0/24– Scans and shows IPs.
It’s simple and works well.
Using The Whois Command
`whois` shows information about a public IP or domain.
whois 8.8.8.8– Shows info about Google’s DNS.
It’s