Loading...

Linux Networking: ip, ping, traceroute, netstat, ss, dig, curl, and wget

Back to blog
LinuxNetworkingDevOpsSystem Administration

Linux Networking: ip, ping, traceroute, netstat, ss, dig, curl, and wget

Master Linux networking commands including network configuration with ip, connectivity testing, DNS resolution, port analysis, and network debugging tools.

8 min read

Linux Networking: ip, ping, traceroute, netstat, ss, dig, curl, and wget

Networking is fundamental to system administration and DevOps. Understanding how to configure networks, troubleshoot connectivity, and analyze network traffic is essential for modern infrastructure.

Network Interface Configuration

ip Command - Modern Network Config

Replace deprecated ifconfig with modern ip command.

# Show all interfaces
ip addr
ip addr show
 
# Show specific interface
ip addr show eth0
# 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536
#    inet 127.0.0.1/8 scope host lo
#    inet6 ::1/128 scope host
 
# Show IP addresses only
ip -4 addr
ip -6 addr
 
# Add IP address
sudo ip addr add 192.168.1.100/24 dev eth0
 
# Remove IP address
sudo ip addr del 192.168.1.100/24 dev eth0
 
# View routing table
ip route
# default via 192.168.1.1 dev eth0
# 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.10
 
# Add route
sudo ip route add 192.168.2.0/24 via 192.168.1.1
 
# Remove route
sudo ip route del 192.168.2.0/24 via 192.168.1.1
 
# Add default gateway
sudo ip route add default via 192.168.1.1
 
# View interface statistics
ip -s link
# RX: bytes packets errors dropped
# TX: bytes packets errors dropped
 
# Enable/disable interface
sudo ip link set eth0 up
sudo ip link set eth0 down
 
# Change MTU
sudo ip link set eth0 mtu 1500
 
# Show interface details
ip link show eth0

Persistent Network Configuration

# Netplan (Ubuntu 18.04+)
sudo nano /etc/netplan/00-installer-config.yaml
# network:
#   version: 2
#   ethernets:
#     eth0:
#       dhcp4: true
#       dhcp4-overrides:
#         route-metric: 100
#       routes:
#         - to: 192.168.1.0/24
#           via: 192.168.1.1
#       nameservers:
#         addresses: [8.8.8.8, 8.8.4.4]
 
# Apply configuration
sudo netplan apply
 
# Test configuration
sudo netplan try
 
# Legacy: /etc/network/interfaces
sudo nano /etc/network/interfaces
# auto eth0
# iface eth0 inet dhcp
#
# auto eth1
# iface eth1 inet static
#   address 192.168.1.10
#   netmask 255.255.255.0
#   gateway 192.168.1.1
#   dns-nameservers 8.8.8.8 8.8.4.4
 
# Restart networking
sudo systemctl restart networking

Testing Connectivity

ping - ICMP Echo Requests

Test reachability to a host.

# Ping host
ping example.com
# PING example.com (93.184.216.34) 56(84) bytes of data.
# 64 bytes from 93.184.216.34: icmp_seq=1 ttl=56 time=20.1 ms
# 64 bytes from 93.184.216.34: icmp_seq=2 ttl=56 time=19.8 ms
 
# Ping specific number of times
ping -c 4 example.com
 
# Ping until interrupted
ping example.com
# Press Ctrl+C to stop
 
# Set timeout
ping -w 5000 example.com
# 5 second timeout
 
# Set packet size
ping -s 256 example.com
 
# Ping IPv6
ping -6 example.com
ping ::1
 
# Show timestamp
ping -D example.com
# [1000.001] 64 bytes from...
 
# Audible ping
ping -a example.com

traceroute - Trace Network Path

Show hops between your computer and destination.

# Traceroute to host
traceroute example.com
# traceroute to example.com (93.184.216.34), 30 hops max, 60 byte packets
#  1  gateway (192.168.1.1)  1.234 ms  1.456 ms  1.678 ms
#  2  10.0.0.1  5.123 ms  5.234 ms  5.456 ms
#  3  example.com (93.184.216.34)  20.123 ms  20.234 ms  20.456 ms
 
# Set number of hops
traceroute -m 15 example.com
 
# Use UDP instead of ICMP
traceroute -U example.com
 
# Use TCP
traceroute -T example.com
 
# DNS name resolution
traceroute -n example.com  # IP addresses only
traceroute example.com     # With DNS names
 
# Don't wait for response
traceroute -z example.com
 
# MTR - Better traceroute
mtr example.com
 
# Non-interactive MTR
mtr -r -c 10 example.com

DNS Resolution

dig - Domain Information Groper

Query DNS records.

# Simple DNS query
dig example.com
# QUERY SECTION
# example.com.            3600 IN  A 93.184.216.34
 
# Query specific record type
dig example.com A       # IPv4 address
dig example.com AAAA    # IPv6 address
dig example.com MX      # Mail server
dig example.com NS      # Name server
dig example.com CNAME   # Alias
dig example.com TXT     # Text record
dig example.com SOA     # Authority
 
# Short output
dig example.com +short
# 93.184.216.34
 
# Query specific nameserver
dig @8.8.8.8 example.com
 
# Reverse DNS lookup
dig -x 93.184.216.34
# Returns domain name
 
# Show trace
dig example.com +trace
# Shows full resolution path
 
# Verbose output
dig example.com +verbose

nslookup - Name Server Lookup

Simple DNS query tool.

# Query domain
nslookup example.com
# Server: 8.8.8.8
# Address: 8.8.8.8#53
# Name: example.com
# Address: 93.184.216.34
 
# Query specific nameserver
nslookup example.com 8.8.8.8
 
# Query specific record type
nslookup -type=MX example.com
nslookup -type=NS example.com
 
# Reverse lookup
nslookup 93.184.216.34

host - DNS Lookup Tool

Simple DNS resolution.

# Lookup host
host example.com
# example.com has address 93.184.216.34
# example.com has IPv6 address 2606:2800:220:1:248:1893:25c8:1946
 
# Query specific nameserver
host example.com 8.8.8.8
 
# Query specific record type
host -t A example.com
host -t MX example.com
host -t NS example.com

Network Debugging

netstat - Network Statistics

Display network connections (deprecated, use ss instead).

# Show all connections
sudo netstat -an
 
# Show listening ports
sudo netstat -tlnp
# -t: TCP
# -l: listening
# -n: numeric
# -p: program name/PID
 
# UDP ports
sudo netstat -ulnp
 
# All connections with program names
sudo netstat -tulnp
 
# Show statistics
netstat -s
 
# Show interface statistics
netstat -i
 
# Monitor specific port
sudo netstat -tlnp | grep :8080
 
# View routing table
netstat -r
 
# Active connections only
sudo netstat -tan | grep ESTABLISHED

ss - Socket Statistics

Modern replacement for netstat.

# Show all sockets
ss -a
 
# Show TCP sockets
ss -t
ss -ta   # All TCP states
ss -tan  # Numeric, all states
 
# Show listening ports
ss -tlnp
# -t: TCP
# -l: listening
# -n: numeric
# -p: process
 
# Show UDP
ss -ulnp
 
# Show IPv4 only
ss -4
 
# Show IPv6 only
ss -6
 
# View specific port
ss -tlnp | grep :8080
 
# View connections to specific host
ss -tan | grep 192.168.1.1
 
# Show socket statistics
ss -s
 
# Monitor specific connection
ss -tpn src :22

File Transfer and Web Requests

curl - Transfer Data

Transfer data using URLs.

# Simple GET request
curl https://example.com
 
# Save to file
curl https://example.com -o filename.html
curl https://example.com > filename.html
 
# Follow redirects
curl -L https://example.com
 
# POST request
curl -X POST https://example.com/api -d "data=value"
 
# JSON POST
curl -X POST https://example.com/api \
  -H "Content-Type: application/json" \
  -d '{"key":"value"}'
 
# Add headers
curl -H "Authorization: Bearer token" https://example.com
 
# Set timeout
curl --max-time 10 https://example.com
 
# Show headers
curl -i https://example.com  # Full response
curl -I https://example.com  # Headers only
 
# Basic authentication
curl -u username:password https://example.com
 
# Verbose output
curl -v https://example.com
 
# Custom user agent
curl -A "Mozilla/5.0" https://example.com
 
# Upload file
curl -F "file=@filename" https://example.com/upload
 
# Download with progress
curl --progress-bar https://example.com/file -o file

wget - Non-interactive Download

Download files from web.

# Simple download
wget https://example.com/file.zip
 
# Save with different name
wget -O newname.zip https://example.com/file.zip
 
# Continue interrupted download
wget -c https://example.com/largefile.iso
 
# Download in background
wget -b https://example.com/file.zip
tail -f wget-log
 
# Set timeout
wget --timeout=10 https://example.com
 
# Mirror website
wget -m -k -K https://example.com
 
# Download to directory
wget -P /path/to/dir https://example.com/file
 
# Limit bandwidth
wget --limit-rate=100k https://example.com/file.zip
 
# Create directories
wget -x https://example.com/path/to/file
 
# Follow links
wget -r https://example.com

Network Performance Testing

iperf - Bandwidth Measurement

Test network throughput.

# Start server (receiver)
iperf3 -s
 
# Run client (sender)
iperf3 -c server_ip
 
# Test with specific duration
iperf3 -c server_ip -t 30
# 30 second test
 
# Test UDP bandwidth
iperf3 -c server_ip -u
 
# Increase parallel streams
iperf3 -c server_ip -P 4
 
# Reverse test (server sends)
iperf3 -c server_ip -R
 
# Set window size
iperf3 -c server_ip -w 512K
 
# Bi-directional test
iperf3 -c server_ip --bidir

Network Configuration Files

# DNS configuration
cat /etc/resolv.conf
# nameserver 8.8.8.8
# nameserver 8.8.4.4
 
# Hosts file
cat /etc/hosts
# 127.0.0.1  localhost
# 192.168.1.10 myserver
 
# Network interfaces (legacy)
cat /etc/network/interfaces
 
# Netplan config (modern)
cat /etc/netplan/*.yaml
 
# Hostname
cat /etc/hostname
sudo hostnamectl set-hostname newname
 
# View routing table
route -n
ip route
 
# View ARP table
arp
ip neigh

Practical Networking Tasks

Diagnose Connectivity Issues

# Check local interface
ip addr show
 
# Check routing
ip route
 
# Ping gateway
ping 192.168.1.1
 
# Trace route to destination
traceroute example.com
 
# Check DNS
dig example.com
 
# Test specific port
ss -tlnp | grep :8080
nc -zv server.com 8080
 
# Check firewall
sudo ufw status
sudo firewall-cmd --list-all

Monitor Network Traffic

# Real-time traffic
watch -n 1 'ss -tpn'
 
# Monitor bandwidth per interface
watch -n 1 'ip -s link'
 
# Dump traffic
sudo tcpdump -i eth0
sudo tcpdump -i eth0 -n port 80
 
# Analyze with wireshark
sudo wireshark

Best Practices

  1. Understand DNS - Many issues are DNS-related
  2. Test Connectivity - Use ping and traceroute first
  3. Monitor Ports - Use ss/netstat to verify services
  4. Optimize Throughput - Use appropriate MTU settings
  5. Secure by Default - Use HTTPS when possible
  6. Document Networks - Keep network documentation current
  7. Monitor Regularly - Set up alerting for network issues
  8. Use Proper Tools - Prefer modern tools (ip, ss, dig)
  9. Understand Protocols - Know TCP/UDP differences
  10. Test Remotely - Verify external connectivity

Summary

Networking is critical for system administration:

  • ip command configures network interfaces
  • ping/traceroute test connectivity
  • dig/nslookup/host resolve DNS
  • ss/netstat analyze network connections
  • curl/wget transfer data
  • Network expertise enables effective infrastructure management

Master these tools for professional Linux networking.