Master the Linux networking essentials with proper command usage, flag explanations, and common troubleshooting tips. Perfect for SysAdmins, DevOps engineers, and Linux learners.


🖧 Getting Network Interface Information

  1. ifconfig – Interface Configuration (Deprecated but still useful)
ifconfig                   # Show info about active interfaces
ifconfig -a               # Show info about all interfaces (active/inactive)
ifconfig enp0s3           # Show info for specific interface
  • -a: Show all interfaces

  • Displays IPv4, MAC address, TX/RX packets, etc.


  • ip – Modern replacement for ifconfig
ip address show                  # Show all addresses
ip addr show dev enp0s3          # Show specific device
ip -4 address                    # IPv4 only
ip -6 address                    # IPv6 only
ip link show                     # Show MAC and Layer 2 info
ip link show dev enp0s3
  • address or addr: Shows IP info

  • link: Layer 2 (MAC level) info

  • -4: IPv4 only

  • -6: IPv6 only


🧭 Displaying and Setting Routing Information
route – Legacy command

route                    # Show routing table
route -n                 # Show numerical IPs only
  • -n: Don't resolve IP to hostnames

ip route – Modern replacement

ip route show                   # Show routing table
ip route add default via 192.168.0.1
ip route del default

🧰 Network Interface Control

# Bringing interfaces up/down
ifconfig enp0s3 down
ifconfig enp0s3 up

ip link set enp0s3 down
ip link set enp0s3 up

# Assigning IP addresses
ifconfig enp0s3 192.168.0.222/24 up
ip addr add 192.168.0.112/24 dev enp0s3
ip addr del 192.168.0.111/24 dev enp0s3

# Secondary IP using sub-interface
ifconfig enp0s3:1 10.0.0.1/24

# Gateway changes
route del default gw 192.168.0.1
route add default gw 192.168.0.2

ip route del default
ip route add default via 192.168.0.1

# MAC address change
ip link set dev enp0s3 address 08:00:27:51:05:a3

⚙️ Netplan – Static Network Config (Ubuntu)

# /etc/netplan/01-netcfg.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: false
      addresses:
        - 192.168.0.20/24
      gateway4: "192.168.0.1"
      nameservers:
        addresses:
          - "8.8.8.8"
          - "8.8.4.4"
sudo systemctl stop NetworkManager
sudo systemctl disable NetworkManager
sudo netplan apply

🛠️ Network Troubleshooting
Using ping

ping 8.8.8.8                  # Ping Google DNS
ping -c 5 192.168.0.1         # Send 5 packets
ping -i 0.5 google.com        # Interval of 0.5s
  • -c: Count

  • -i: Interval


🛠️ Troubleshooting Network Issues in Linux
When you're facing network issues, here's a step-by-step checklist to diagnose and fix them.
1️⃣ No Internet?

  • ✅ Check Internet connectivity
ping 8.8.8.8
  • 🛠️ If ping fails, check your gateway configuration.

2️⃣ DNS Not Resolving?

  • ✅ Test DNS resolution
ping google.com
  • 🔍 If this fails but 8.8.8.8 works, check DNS settings:
resolvectl status

3️⃣ Interface Down?

  • 🔎 Check interface status
ip link show
  • 🧰 Bring interface up (example: enp0s3)
ip link set enp0s3 up

🔐 SSH – Secure Shell

ssh -p 22 user@host                # Connect to host
ssh -l user -p 22 host
ssh -v -p 22 user@host             # Verbose mode
  • -p, --port

  • -l, --login-name

  • -v, --verbose

SSH Daemon Control:

sudo systemctl status sshd
sudo systemctl restart sshd
sudo systemctl enable sshd

📤 SCP – Secure Copy

scp a.txt user@host:~               # Upload file
scp -P 2222 file.txt user@host:~/   # With custom port
scp -r dir/ user@host:~/            # Recursive directory copy
scp -P 2222 user@host:~/a.txt .     # Download file
  • -P: Port

  • -r: Recursive


🔁 RSYNC – File Synchronization

rsync -av /src/ /dest/                       # Archive & verbose
rsync -av --delete /src/ /dest/              # Mirror
rsync -av -e ssh /src/ user@host:/dest/      # Over SSH
rsync -av --exclude '*.mp4' /src/ /dest/     # Exclude files
  • -a, --archive

  • -v, --verbose

  • --delete: Mirror deletions

  • -e ssh: Use SSH


🌐 WGET – Web Download Tool

wget https://file.com/sample.iso
wget -c https://file.com/sample.iso             # Resume
wget -P ~/Downloads/ https://file.com/sample    # Set dir
wget --limit-rate=100k -P dir/ URL              # Limit rate
wget -i urls.txt                                # Batch download
wget -b URL && tail -f wget-log                 # Background
wget --mirror --convert-links http://site.com   # Full site

  • -c, --continue

  • -P, --directory-prefix

  • --limit-rate=

  • -b, --background

  • -i, --input-file


📊 NETSTAT, SS, and LSOF

netstat -tupan          # TCP/UDP active ports
ss -tupan               # Faster alternative
lsof                    # List open files
lsof -u user            # By user
lsof -c sshd            # By command
lsof -iTCP -sTCP:LISTEN # TCP listening ports
  • -t, --tcp

  • -u, --udp

  • -a, --all

  • -p, --program


🔍 NMAP – Network Scanner

nmap -sS 192.168.0.1               # SYN scan
nmap -sT 192.168.0.1               # TCP connect
nmap -p- 192.168.0.1               # All ports
nmap -sV -p 22,80 192.168.0.1      # Version scan
nmap -O 192.168.0.1                # OS detection
nmap -A 192.168.0.1                # Full scan
nmap -iL hosts.txt -oN report.txt  # Input file + save
  • -sS: SYN scan

  • -sT: TCP connect

  • -sV: Version detection

  • -O: OS detection

  • -A: Aggressive scan

  • -iL: Input from file

  • -oN: Normal output file