Knowing how to pull network information from the terminal is a fundamental Linux skill. Whether you are troubleshooting a connectivity issue, setting up a server, or just curious about your machine’s network identity — this guide covers every command you need, explained clearly so you understand what each one is actually showing you.
The Network Interfaces on Your Machine
Before looking for specific values, it helps to see all your network interfaces at once:
Sample output:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 ...
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ...
link/ether a4:c3:f0:52:1b:3e brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ...
link/ether b8:27:eb:7d:44:9a brd ff:ff:ff:ff:ff:ff
Common interface names you will encounter:
| Interface |
What it is |
lo |
Loopback — the virtual interface the system uses to talk to itself (127.0.0.1) |
eth0 / enp3s0 |
Wired Ethernet |
wlan0 / wlp2s0 |
Wi-Fi |
docker0 / virbr0 |
Virtual interfaces created by Docker, KVM, etc. |
Finding Your IP Address
Method 1 — ip (recommended, modern)
To see a specific interface only:
1
2
|
ip addr show eth0
ip addr show wlan0
|
Reading the output:
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500
inet 192.168.1.105/24 brd 192.168.1.255 scope global dynamic eth0
inet6 fe80::a6c3:f0ff:fe52:1b3e/64 scope link
inet — your IPv4 address (192.168.1.105) and subnet mask (/24)
inet6 — your IPv6 address
scope global — this address is reachable from the network
scope link — only reachable on the local link (not routable)
Compact one-liner — IPv4 only
1
|
ip -4 addr show | grep inet
|
Method 2 — hostname
Prints all IP addresses assigned to the machine, space-separated. Quick and clean.
1
2
|
# Show just the first IP
hostname -I | awk '{print $1}'
|
Method 3 — ifconfig (older systems)
If ifconfig is not installed:
1
2
|
sudo apt install net-tools # Debian / Ubuntu
sudo dnf install net-tools # Fedora / RHEL
|
Finding Your Hostname
The hostname is your machine’s name on the local network.
1
2
3
4
5
6
7
8
|
# Short hostname
hostname
# Fully Qualified Domain Name (FQDN)
hostname -f
# Show hostname set in the OS
hostnamectl
|
hostnamectl is the richest option — it shows the static hostname, icon name, chassis type, kernel version, and OS:
Static hostname: myserver
Icon name: computer-desktop
Chassis: desktop
Machine ID: a1b2c3d4e5f6...
Boot ID: ...
Operating System: Ubuntu 22.04.3 LTS
Kernel: Linux 6.2.0-36-generic
Architecture: x86-64
To change the hostname:
1
|
sudo hostnamectl set-hostname new-hostname
|
Finding Your MAC Address
A MAC (Media Access Control) address is a unique hardware identifier assigned to each network interface card. It is a 12-character hexadecimal value, usually written in pairs: a4:c3:f0:52:1b:3e.
Method 1 — ip link
The MAC address appears on the link/ether line of each interface:
2: eth0: ...
link/ether a4:c3:f0:52:1b:3e brd ff:ff:ff:ff:ff:ff
One-liner — MAC for a specific interface
1
|
ip link show eth0 | awk '/link\/ether/ {print $2}'
|
Method 2 — Read directly from /sys
1
|
cat /sys/class/net/eth0/address
|
Replace eth0 with your interface name. This works on any Linux system regardless of which tools are installed.
Method 3 — ifconfig
1
|
ifconfig eth0 | grep ether
|
Finding Your Default Gateway
The gateway is the router your machine sends traffic through to reach the internet.
Look for the line starting with default:
default via 192.168.1.1 dev eth0 proto dhcp src 192.168.1.105 metric 100
Here 192.168.1.1 is your default gateway (your router’s IP).
One-liner — print only the gateway
1
|
ip route show default | awk '{print $3}'
|
Finding Your DNS Servers
DNS servers are used to resolve domain names (like google.com) into IP addresses.
On systems using systemd-resolved (Ubuntu 18.04+)
Or for a cleaner summary:
Check /etc/resolv.conf
Look for nameserver entries:
nameserver 127.0.0.53
nameserver 8.8.8.8
nameserver 1.1.1.1
Using nmcli (NetworkManager systems)
1
|
nmcli dev show | grep DNS
|
Full Network Summary with nmcli
If your system uses NetworkManager (most desktop distros do), nmcli gives a rich summary:
This shows interface name, MAC address, IP address, gateway, DNS, and connection state all in one output.
For a condensed connection list:
If you are on a wireless connection, these commands reveal the SSID, signal strength, channel, frequency, and link speed.
Check your Wi-Fi connection details
Sample output:
Connected to b8:27:eb:12:34:56 (on wlan0)
SSID: MyHomeNetwork
freq: 5500
RX: 4523049 bytes (18211 packets)
TX: 1031222 bytes (7021 packets)
signal: -52 dBm
rx bitrate: 300.0 MBit/s MCS 15 40MHz short GI
tx bitrate: 300.0 MBit/s MCS 15 40MHz short GI
SSID — the network name you are connected to
signal — signal strength in dBm (closer to 0 is stronger; -50 is excellent, -80 is poor)
freq — channel frequency in MHz (2412–2484 = 2.4 GHz, 5160–5825 = 5 GHz)
List all available nearby Wi-Fi networks
1
|
sudo iw dev wlan0 scan | grep -E "SSID:|signal:|freq:"
|
If not installed:
1
|
sudo apt install wireless-tools
|
Using nmcli for Wi-Fi
1
2
3
4
5
|
# Show the currently connected Wi-Fi network
nmcli -f IN-USE,SSID,SIGNAL,BARS,SECURITY device wifi list
# Show detailed info about current connection
nmcli connection show --active
|
The ARP / Neighbour Table
The ARP (Address Resolution Protocol) table maps IP addresses to MAC addresses for devices on your local network. This is how your machine knows which MAC address belongs to which IP on the same subnet.
Sample output:
192.168.1.1 dev eth0 lladdr a8:9c:ed:44:11:22 REACHABLE
192.168.1.102 dev eth0 lladdr dc:a6:32:7b:55:88 STALE
192.168.1.103 dev eth0 lladdr 00:11:32:5a:bc:ef DELAY
ARP states explained
| State |
Meaning |
REACHABLE |
Entry is confirmed valid and recently used |
STALE |
Entry exists but has not been confirmed recently |
DELAY |
Waiting to confirm the entry is still valid |
FAILED |
Resolution failed — device may be offline |
Legacy arp command
Finding Your Public (External) IP Address
Your local IP (192.168.x.x) is only visible inside your home or office network. To find the public IP your traffic exits through, query an external service:
1
|
curl -s https://ipinfo.io/ip
|
All three print your public IP address. The -s flag on curl suppresses the progress bar.
For a richer response including location and ISP:
1
|
curl -s https://ipinfo.io
|
Checking Network Interface Statistics
See bytes sent, received, and error counts for all interfaces:
Or watch live traffic in real time:
1
2
3
4
5
|
# Install if needed
sudo apt install nload
# Watch traffic on eth0
nload eth0
|
Check detailed per-interface counters directly from the kernel:
Checking Open Ports and Active Connections
1
2
3
4
5
6
7
8
|
# Show all listening ports (TCP and UDP)
ss -tulnp
# Show established connections
ss -tnp
# Legacy alternative
netstat -tulnp
|
Column guide for ss -tulnp:
| Column |
Meaning |
Netid |
Protocol (tcp / udp) |
State |
Connection state (LISTEN, ESTAB) |
Local Address:Port |
IP and port on this machine |
Peer Address:Port |
Remote IP and port |
Process |
PID and name of the owning process |
Testing Connectivity
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
# Basic ping — test if a host is reachable
ping -c 4 google.com
# Trace the route packets take to a destination
traceroute google.com
# Or using the newer combined tool (real-time)
mtr google.com
# Test DNS resolution
nslookup google.com
dig google.com
# Check if a specific port is open on a remote host
nc -zv google.com 443
|
Quick Reference Cheat Sheet
| Task |
Command |
| Show all interfaces |
ip link show |
| Show all IP addresses |
ip addr show |
| Show IPv4 only |
ip -4 addr show |
| Show IP for one interface |
ip addr show eth0 |
| Quick IP list |
hostname -I |
| Show hostname info |
hostnamectl |
| Show MAC address |
ip link show | grep ether |
| Read MAC from sysfs |
cat /sys/class/net/eth0/address |
| Show default gateway |
ip route show default |
| Show DNS servers |
resolvectl dns or cat /etc/resolv.conf |
| Full interface summary |
nmcli device show |
| Wi-Fi details (SSID, signal) |
iw dev wlan0 link |
| Scan nearby Wi-Fi networks |
sudo iw dev wlan0 scan |
| Show ARP / neighbour table |
ip neigh show |
| Find public IP |
curl ifconfig.me |
| Interface traffic stats |
ip -s link |
| Show open ports |
ss -tulnp |
| Test connectivity |
ping -c 4 google.com |
| Trace network path |
traceroute google.com |
| Check if port is open |
nc -zv host port |
A Note on Interface Naming
Older Linux systems used simple names like eth0, eth1, wlan0. Modern systems use Predictable Network Interface Names based on hardware location — for example enp3s0 (Ethernet, PCI bus 3, slot 0) or wlp2s0 (Wi-Fi, PCI bus 2, slot 0). The commands in this guide work the same regardless of naming scheme — just substitute your actual interface name, which you can always find with ip link show.