Networking is a core aspect of Linux system administration, enabling systems to communicate, transfer data, and connect to the internet or other networks. Whether you're configuring a server, troubleshooting network issues, or managing containers, a solid understanding of networking commands is essential. This guide covers the most important networking commands in Linux, providing the tools you need to monitor, configure, and troubleshoot network connections.
Basic Networking Commands
ifconfig - Interface Configuration
The ifconfig command displays or configures a network interface. While it has largely been replaced by ip, it's still useful for basic network management.
ifconfig- Common Uses:
- Display network interfaces and their IP addresses.
- Bring an interface up or down:
ifconfig eth0 upifconfig eth0 down
Want to learn more about configuring network interfaces on Linux?
ip - Show/Manipulate Routing, Devices, and Addresses
The ip command is the modern replacement for ifconfig, offering more functionality and flexibility.
ip a- Common Options:
Brush up on IP addresses.
ping - Test Network Connectivity
The ping command tests connectivity between your system and a remote host by sending ICMP echo requests and listening for replies.
ping example.com- Options:
traceroute - Trace the Route to a Host
The traceroute command shows the path that packets take to reach a remote host, helping diagnose network routing issues.
traceroute example.com- Options:
netstat - Network Statistics
The netstat command provides detailed statistics about network connections, routing tables, and interface statistics.
netstat- Options:
ss - Socket Statistics
The ss command is a modern replacement for netstat, offering more detailed information about sockets.
ss -tuln- Common Options:
Read about more network diagnostic tools.
Network Configuration Commands
hostname - Show or Set the System's Hostname
The hostname command displays or sets the system's hostname.
hostname- Options:
nmcli - NetworkManager Command Line Interface
nmcli is a command-line tool for managing NetworkManager, used to configure network interfaces and connections.
nmcli device status- Common Uses:
- Show the status of all network interfaces:
nmcli device status- Show the status of all network interfaces:
- Connect to a Wi-Fi network:
nmcli device wifi connect "SSID" password "PASSWORD"- Connect to a Wi-Fi network:
iwconfig - Configure Wireless Interfaces
The iwconfig command is used to configure wireless network interfaces and view wireless information.
iwconfig- Common Uses:
route - Show/Manipulate the IP Routing Table
The route command displays or modifies the system's routing table.
route -n- Options:
Troubleshooting and Diagnostics Commands
dig - DNS Lookup
The dig command queries DNS servers and retrieves information about DNS records. It's a powerful tool for troubleshooting DNS issues.
dig example.com- Common Options:
nslookup - Query Internet Name Servers
The nslookup command queries DNS servers to find IP addresses associated with a domain name.
nslookup example.com- Usage:
curl - Transfer Data from or to a Server
The curl command transfers data to or from a server, supporting a wide range of protocols including HTTP, FTP, and more.
curl http://example.com- Options:
wget - Download Files from the Web
wget is a command-line utility to download files from the web, particularly useful for automated downloads.
wget http://example.com/file.zip- Options:
nc (Netcat) - Network Utility
Netcat (nc) is a versatile networking tool used for reading from and writing to network connections using TCP or UDP.
nc -zv example.com 80- Common Uses:
tcpdump - Network Packet Analyzer
The tcpdump command captures and analyzes network traffic on an interface. It's an essential tool for network diagnostics and security monitoring.
tcpdump -i eth0- Options:
ethtool - Display or Change Ethernet Device Settings
The ethtool command allows you to view and change settings for network interfaces.
ethtool eth0- Common Uses:
Go deeper by learning nmap.