Master Linux Network Interface Management: Essential Commands and Real-World Examples
This guide walks Linux system administrators through essential network interface commands—such as ifconfig, ip, route, netstat, traceroute, ping, ss, nmcli, iw, ethtool, firewall-cmd, and iptables—providing clear syntax, practical examples, and tips for configuring IP addresses, routes, DNS, VPNs, and firewall rules.
ifconfig command
ifconfigis a basic utility for displaying and configuring network interfaces.
# Example: view all interfaces
ifconfig -a
# Enable or disable an interface
sudo ifconfig eth0 up
sudo ifconfig eth0 down
# Set IP address and netmask
sudo ifconfig eth0 192.168.1.2 netmask 255.255.255.0ip command
The ip suite replaces ifconfig with more powerful and flexible syntax.
# Example: list all interfaces
ip link show
# Enable or disable an interface
sudo ip link set eth0 up
sudo ip link set eth0 down
# Configure IP address and netmask (CIDR notation)
sudo ip address add 192.168.1.2/24 dev eth0route command
routemanages static routing tables.
# Show current routing table
route -n
# Add a static route
sudo route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.1netstat command
netstatdisplays network connections, routing tables, and interface statistics.
# List all network connections
netstat -a
# Show listening ports only
netstat -ltraceroute command
traceroutetraces the path packets take to a destination.
# Trace route to a host
traceroute www.example.comping command
pingtests reachability of a remote host.
# Ping a host
ping www.example.comss command
ssshows socket statistics, replacing many netstat uses.
# Display all sockets
ss -a
# Show only TCP connections
ss -tnmcli (NetworkManager CLI)
nmcliconfigures network connections via NetworkManager.
# List all connections
nmcli connection show
# Modify IPv4 address of eth0
sudo nmcli connection modify eth0 ipv4.addresses "192.168.1.2/24"iw command (wireless management)
iwhandles wireless interfaces.
# Show wireless devices
iw dev
# Scan for available networks
sudo iw dev wlan0 scan
# Connect to a Wi‑Fi network
sudo iw dev wlan0 connect "YourSSID" key 0:YourPassphraseethtool command
ethtoolinspects and configures Ethernet adapter parameters.
# Show detailed interface info
ethtool eth0
# Set speed and duplex mode
sudo ethtool -s eth0 speed 100 duplex fullConfiguring DNS
Two common methods are editing /etc/resolv.conf directly or using systemd-resolved.
# Edit resolv.conf manually
sudo nano /etc/resolv.conf
# Enable systemd-resolved and link stub resolver
sudo systemctl start systemd-resolved
sudo systemctl enable systemd-resolved
sudo ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.confPolicy routing with iproute2
The ip route command can create advanced routing rules.
# Add a policy route
sudo ip route add 192.168.3.0/24 via 192.168.1.1 dev eth0Connecting VPN via NetworkManager
# Import an OpenVPN configuration file
sudo nmcli connection import type openvpn file example.ovpn
# Activate the VPN connection
sudo nmcli connection up my-vpnfirewall-cmd (firewalld management)
# Start and enable firewalld service
sudo systemctl start firewalld
sudo systemctl enable firewalld
# Open TCP port 80 permanently and reload
sudo firewall-cmd --add-port=80/tcp --permanent
sudo firewall-cmd --reloadiptables for advanced network settings
# Port forwarding (DNAT) from host port 80 to internal server
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.1.2:80
# Enable masquerading for outbound traffic
sudo iptables -t nat -A POSTROUTING -j MASQUERADEBy mastering these commands, Linux administrators gain a comprehensive toolbox for configuring interfaces, managing IP addressing, routing, DNS, wireless networks, VPNs, firewalls, and packet filtering, ultimately ensuring stable, secure, and efficient network operation.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
