Operations 8 min read

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.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Linux Network Interface Management: Essential Commands and Real-World Examples

ifconfig command

ifconfig

is 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.0

ip 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 eth0

route command

route

manages 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.1

netstat command

netstat

displays network connections, routing tables, and interface statistics.

# List all network connections
netstat -a

# Show listening ports only
netstat -l

traceroute command

traceroute

traces the path packets take to a destination.

# Trace route to a host
traceroute www.example.com

ping command

ping

tests reachability of a remote host.

# Ping a host
ping www.example.com

ss command

ss

shows socket statistics, replacing many netstat uses.

# Display all sockets
ss -a

# Show only TCP connections
ss -t

nmcli (NetworkManager CLI)

nmcli

configures 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)

iw

handles 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:YourPassphrase

ethtool command

ethtool

inspects and configures Ethernet adapter parameters.

# Show detailed interface info
ethtool eth0

# Set speed and duplex mode
sudo ethtool -s eth0 speed 100 duplex full

Configuring 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.conf

Policy 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 eth0

Connecting 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-vpn

firewall-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 --reload

iptables 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 MASQUERADE

By 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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

firewallLinuxNetwork ConfigurationVPNShell Commands
Liangxu Linux
Written by

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.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.