Mastering Linux Networking – Essential Commands & Configuration
🔹 Introduction
Mastering Linux Networking: Linux networking is a fundamental aspect of system administration, security, and DevOps operations. Whether you are configuring servers, troubleshooting connectivity problems, or optimizing network performance, having a deep understanding of Linux networking commands is crucial.
In this comprehensive guide, we will explore the core networking commands and configurations that every Linux user, administrator, and network engineer should master.
Topics Covered:
- Understanding Linux network interfaces and IP addresses
- Configuring network settings and managing connections
- Exploring routing tables and adding static routes
- Firewall configurations using
iptables
andfirewalld
- Diagnosing and troubleshooting network connectivity issues
By the end of this article, you will have a strong grasp of Linux networking fundamentals and advanced configurations. Let’s dive in!

🔢 Checking Network Configuration
Before making any changes to a Linux system’s network settings, it is essential to verify the current configuration.
🔹 Check IP Address and Network Interfaces
The primary command for checking IP addresses and network interfaces is:
ip a
Alternatively, you can use the deprecated but still widely available:
ifconfig
Output Breakdown:
inet
displays the assigned IPv4 address.inet6
lists any assigned IPv6 addresses.eth0
orwlan0
denotes the network interface name (Ethernet or Wi-Fi).
To check all network interfaces along with their status, use:
ip link show
🔧 Configuring Network Interfaces
🔹 Setting a Static IP Address (Ubuntu/Debian)
For persistent network configurations, edit the Netplan YAML configuration file:
sudo nano /etc/netplan/50-cloud-init.yaml
Example configuration for a static IP setup:
network:
ethernets:
eth0:
dhcp4: no
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
version: 2
Apply the changes with:
sudo netplan apply
🔹 Configuring Network Interfaces (CentOS/RHEL)
Modify the network configuration file for your interface:
sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0
Example static IP configuration:
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
Restart the network service:
sudo systemctl restart NetworkManager
🚶️ Managing Routing in Linux
🔹 Viewing the Routing Table
To examine the system’s routing table, use:
ip route show
🔹 Adding a Static Route
sudo ip route add 192.168.2.0/24 via 192.168.1.1 dev eth0
🔹 Deleting a Route
sudo ip route del 192.168.2.0/24
🔒 Configuring Linux Firewall (iptables & firewalld)
🔹 Checking Active Firewall Rules
sudo iptables -L -v -n
or
sudo firewall-cmd --list-all
🔹 Allowing Incoming SSH Traffic (Port 22)
For iptables:
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
For firewalld (CentOS/RHEL):
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
🔹 Blocking All Incoming Traffic Except SSH
sudo iptables -P INPUT DROP
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
🔍 Troubleshooting Network Issues in Linux
🔹 Checking Network Connectivity
ping google.com
🔹 Performing a Trace Route to Identify Network Hops
traceroute google.com
🔹 Checking Open Ports
netstat -tulnp
or
ss -tulnp
🔹 Restarting Network Services
For Ubuntu/Debian:
sudo systemctl restart networking
For CentOS/RHEL:
sudo systemctl restart NetworkManager
📝 Summary
- You learned essential Linux networking commands and how to configure network interfaces.
- You now understand routing, firewalls, and troubleshooting techniques for managing Linux networks.
- Mastering Linux networking is key for system administrators, DevOps engineers, and security professionals.
👉 Next Blog (Feb 15, 2025): Understanding Linux Firewall & Security – iptables & firewalld 🚀
Learn More:
💬 Have questions? Drop them in the comments below!