Learn Networking CLI Commands
Contents
Basic Networking Commands
- Display Network Interfaces
- Description: Lists detailed information about all network interfaces, including IP addresses and hardware addresses.
- Example:
ifconfig
- Usage:
ifconfig -a
(to list all interfaces, including inactive ones)
- Show IP Addresses
- Description: Displays the IP addresses assigned to each network interface.
- Example:
ip addr show
- Usage:
ip addr show [interface]
(to view details for a specific interface)
- List Network Interfaces
- Description: Lists all available network interfaces on the system.
- Example:
ip link
- Usage:
ip link show [interface]
(to see details for a specific interface)
- View Routing Table
- Description: Shows the current routing table used for directing network traffic.
- Example:
netstat -r
- Usage:
route -n
(alternative command)
- Network Interface Statistics
- Description: Displays statistics for each network interface, including packet counts and errors.
- Example:
netstat -i
- Usage:
ip -s link
(alternative command)
- Ping a Host
- Description: Sends ICMP echo requests to a specified host to test connectivity.
- Example:
ping google.com
- Usage:
ping -c 4 [hostname]
(to send 4 packets)
- Trace Network Path
- Description: Traces the route packets take from your system to a destination host.
- Example:
traceroute example.com
- Usage:
tracepath example.com
(alternative command)
- Resolve DNS Name
- Description: Resolves a domain name into its corresponding IP address.
- Example:
nslookup example.com
- Usage:
dig example.com
(alternative command for more details)
- Perform DNS Query
- Description: Performs a detailed DNS query to retrieve specific information about a domain.
- Example:
dig example.com
- Usage:
dig +short example.com
(for a concise result)
- Get Interface Details
- Description: Retrieves detailed settings and capabilities of a specified network interface.
- Example:
ethtool eth0
- Usage:
ethtool -i eth0
(to show driver information)
Network Configuration Commands
- Assign IP Address
- Description: Configures a network interface with a specific IP address and subnet mask.
- Example:
ifconfig eth0 192.168.1.10 netmask 255.255.255.0
- Usage:
ip addr add 192.168.1.10/24 dev eth0
(alternative command)
- Activate or Deactivate Interface
- Description: Brings a network interface up or down.
- Example:
ifconfig eth0 up
- Usage:
ifconfig eth0 down
(to deactivate)
- Configure IP Address Using
ip
- Description: Adds or removes IP addresses for a network interface.
- Example:
ip addr add 192.168.1.10/24 dev eth0
- Usage:
ip addr del 192.168.1.10/24 dev eth0
(to remove an IP)
- Set Default Gateway
- Description: Adds a default route to the routing table, directing traffic through a specified gateway.
- Example:
ip route add default via 192.168.1.1
- Usage:
route add default gw 192.168.1.1
(alternative command)
- Remove a Route
- Description: Deletes a route from the system’s routing table.
- Example:
ip route del 192.168.1.0/24
- Usage:
route del -net 192.168.1.0 netmask 255.255.255.0
(alternative command)
Testing and Troubleshooting
- List Active Listening Ports
- Description: Shows all ports currently listening for incoming connections.
- Example:
netstat -l
- Usage:
ss -l
(alternative command)
- Display Active Connections
- Description: Lists all active network connections and their statuses.
- Example:
netstat -a
- Usage:
ss -a
(alternative command)
- Show Listening Ports
- Description: Displays all ports that are currently in a listening state.
- Example:
netstat -tuln
- Usage:
ss -tuln
(alternative command)
- Network Connections with Process IDs
- Description: Shows network connections along with the process IDs of applications using them.
- Example:
netstat -tp
- Usage:
ss -tup
(alternative command)
- Check Firewall Rules
- Description: Displays the rules currently applied by the firewall.
- Example:
iptables -L
- Usage:
firewall-cmd --list-all
(forfirewalld
)
- Test Port Connectivity
- Description: Tests whether a specific port on a remote host is open and reachable.
- Example:
nc -zv example.com 80
- Usage:
telnet example.com 80
(alternative command)
- Network Performance Measurement
- Description: Measures network bandwidth and performance using
iperf3
. - Example:
iperf3 -s
(on the server)
iperf3 -c [server IP]
(on the client) - Usage:
iperf -s
andiperf -c [server IP]
(alternative command)
- Description: Measures network bandwidth and performance using
- Monitor Network Traffic
- Description: Captures and displays network packets in real-time.
- Example:
tcpdump -i eth0
- Usage:
tshark -i eth0
(alternative command)
- View Network Statistics
- Description: Provides statistics for network interfaces, including packet counts and errors.
- Example:
sar -n DEV 1
- Usage:
nload
(for real-time bandwidth monitoring)
- Detailed Interface Statistics
- Description: Displays detailed statistics and status for a specific network interface.
- Example:
ip -s link show eth0
- Usage:
ifstat -i eth0
(alternative command)
Advanced Networking Commands
- Edit DNS Resolver Configuration
- Description: Modify the DNS resolver settings file to configure DNS servers.
- Example:
nano /etc/resolv.conf
- Usage:
vi /etc/resolv.conf
(alternative editor)
- Display ARP Cache
- Description: Shows the ARP cache, which maps IP addresses to MAC addresses.
- Example:
arp -a
- Usage:
ip neighbour
(alternative command)
- View Routing Details
- Description: Provides detailed information about the system’s routing table.
- Example:
route -n
- Usage:
ip route show
(alternative command)
- Flush DNS Cache
- Description: Clears the DNS cache to resolve issues with DNS resolution.
- Example:
systemd-resolve --flush-caches
- Usage:
service nscd restart
(if usingnscd
)
- List Network Namespaces
- Description: Lists all network namespaces present on the system.
- Example:
ip netns list
- Usage:
ls /var/run/netns/
(alternative command)
- Run Commands in Network Namespace
- Description: Execute commands within a specific network namespace.
- Example:
ip netns exec mynamespace ping 8.8.8.8
- Usage:
ip netns exec [namespace] [command]
- Configure Network Bonding
- Description: Set up network bonding for combining multiple network interfaces.
- Example:
nano /etc/network/interfaces
(Debian-based)
Add bonding configuration for interfaces. - Usage:
modprobe bonding
and configure/etc/sysconfig/network-scripts/ifcfg-bond0
(Red Hat-based)
- Manage Network Settings with NetworkManager
- Description: View or adjust network connections using NetworkManager.
- Example:
nmcli con show
- Usage:
nmcli con add type ethernet con-name myconnection ifname eth0
(to add a new connection)
- View Device Statistics
- Description: Retrieves statistics for network devices including errors and packet counts.
- Example:
cat /proc/net/dev
- Usage:
dmesg | grep eth0
(to check for device-related messages)
- Monitor Bandwidth Usage
- Description: Analyze and monitor bandwidth usage over time.
- Example:
nload
- Usage:
vnstat
(for historical bandwidth data)
Linux Networking Troubleshooting Commands
- Check Network Configuration
- Description: Displays the current network configuration for interfaces.
- Example:
ip a
- Usage:
ifconfig
(alternative command)
- Inspect Interface Status
- Description: Shows the status and configuration of network interfaces.
- Example:
ip link
- Usage:
ifconfig -a
(alternative command)
- View Interface Errors
- Description: Displays errors and dropped packets on network interfaces.
- Example:
ip -s link
- Usage:
netstat -i
(alternative command)
- Test Port Reachability
- Description: Checks if a specific port on a remote host is accessible.
- Example:
nmap -p 80 example.com
- Usage:
telnet example.com 80
(alternative command)
- List Open Ports and Services
- Description: Lists all open ports and the services associated with them.
- Example:
ss -tuln
- Usage:
netstat -tuln
(alternative command)
- Summarize Network Configuration
- Description: Provides a summary of routing and network configurations.
- Example:
ip route
- Usage:
route -n
(alternative command)
- Test Network Latency
- Description: Measures the time it takes for packets to travel to a remote host.
- Example:
ping -c 5 example.com
- Usage:
traceroute example.com
(for detailed path and latency)
- Check Interface State
- Description: Displays the current operational state of network interfaces.
- Example:
ip link show
- Usage:
ifconfig
(alternative command)
- Trace Network Path
- Description: Traces the route packets take to reach a destination host.
- Example:
tracepath example.com
- Usage:
traceroute example.com
(alternative command)
- Capture Network Packets
- Description: Captures network packets for analysis.
- Example:
tcpdump -i eth0
- Usage:
wireshark
(for graphical packet analysis)
- List Devices in Network Namespace
- Description: Shows network devices within a specific namespace.
- Example:
ip netns exec mynamespace ip link
- Usage:
ip netns exec mynamespace ip addr
(for IP details)
- Move Interface to Namespace
- Description: Assigns a network interface to a specific network namespace.
- Example:
ip link set eth0 netns mynamespace
- Usage:
ip netns exec mynamespace ip link set dev eth0 up
(to activate the interface in the namespace)
- Network Connection Statistics
- Description: Displays statistics about active network connections.
- Example:
ss -s
- Usage:
netstat -s
(alternative command)
- Detailed Interface Error Information
- Description: Shows detailed error information for network interfaces.
- Example:
ip -s link
- Usage:
ifstat
(for interface statistics)
- Device Configuration Information
- Description: Retrieves configuration details for network devices.
- Example:
lshw -C network
- Usage:
lsusb
(for USB network devices)
- Detect IP Conflicts on Network
- Description: Scans the local network for IP address conflicts.
- Example:
arp-scan --interface=eth0 --localnet
- Usage:
ping 192.168.1.1
(to check if another device responds)
- Display Interface Configuration
- Description: Shows configuration details for a specified network interface.
- Example:
ifquery eth0
- Usage:
nmcli device show eth0
(alternative command)
- System-wide Network Statistics
- Description: Provides overall network statistics for the system.
- Example:
netstat -s
- Usage:
sar -n DEV
(for historical network statistics)
- Activate or Deactivate Interfaces
- Description: Enables or disables a network interface.
- Example:
ifup eth0
/ifdown eth0
- Usage:
ip link set eth0 up
/ip link set eth0 down
(alternative commands)
- List Network Devices
- Description: Lists all detected network devices on the system.
- Example:
lspci | grep -i net
- Usage:
ls /sys/class/net/
(for network interfaces)
- Test Local Network Connectivity
- Description: Checks connectivity between devices on the local network.
- Example:
ping -c 4 192.168.1.2
- Usage:
arping 192.168.1.2
(for ARP level testing)
- View Kernel Network Buffers
- Description: Displays information about kernel network buffers.
- Example:
cat /proc/net/dev
- Usage:
cat /proc/net/softnet_stat
(for detailed buffer statistics)
- Analyze Network Traffic Patterns
- Description: Examines network traffic patterns and usage.
- Example:
vnstat
- Usage:
iftop
(for real-time traffic analysis)
- Protocol-specific Network Statistics
- Description: Shows network statistics categorized by protocol types.
- Example:
netstat -p
- Usage:
ss -p
(for protocol-specific connection statistics)
- Test DNS Server Responses
- Description: Checks the responses received from a DNS server.
- Example:
dig @8.8.8.8 example.com
- Usage:
nslookup example.com 8.8.8.8
(alternative command)
- Monitor Network Interface Statistics
- Description: Provides statistics on network interfaces, including bandwidth and error rates.
- Example:
ifstat
- Usage:
sar -n DEV 1
(for periodic statistics collection)
- Check Interface Speed
- Description: Verifies the speed of a network interface.
- Example:
ethtool eth0
- Usage:
ethtool -S eth0
(for statistics and speed information)
- Display ARP Table
- Description: Shows the ARP table, which maps IP addresses to their corresponding MAC addresses.
- Example:
arp -n
- Usage:
ip neighbour
(alternative command)
- Measure Network Throughput
- Description: Tests the network throughput between systems.
- Example:
iperf -c [server IP]
- Usage:
iperf3 -c [server IP]
(for improved version)
- Manage Network Connections with
nmcli
- Description: View and manage network connections using NetworkManager’s command-line interface.
- Example:
nmcli con show
- Usage:
nmcli con add type ethernet con-name myconnection ifname eth0
(to create a new connection)
- Detailed Interface Listing
- Description: Provides a detailed list of network interfaces including additional information.
- Example:
ip -d link
- Usage:
ip link show
(for a simpler output)
- Network Interface Metrics
- Description: Displays metrics related to network interfaces, including traffic and error rates.
- Example:
sar -n DEV 1
- Usage:
nload
(for real-time traffic metrics)
- Display TCP Connection Details
- Description: Shows detailed information about TCP connections.
- Example:
ss -t -a
- Usage:
netstat -tn
(alternative command)
- View Network Interface Configuration
- Description: Retrieves the configuration details of network interfaces.
- Example:
ifconfig eth0
- Usage:
ip addr show eth0
(alternative command)
- Monitor Network Latency
- Description: Observes network latency over time.
- Example:
mtr example.com
- Usage:
ping -i 2 example.com
(for regular interval pings)
- Display Network Configuration Summary
- Description: Provides a summary of the network configuration and status.
- Example:
ifconfig -a
- Usage:
ip addr show
(for more detailed information)
- View Network Connections by Port
- Description: Lists network connections grouped by port number.
- Example:
ss -tnlp
- Usage:
netstat -tulpn
(alternative command)
- Show Interface Driver Information
- Description: Displays driver information for network interfaces.
- Example:
ethtool -i eth0
- Usage:
lsmod | grep [driver_name]
(for module details)
- View Network Traffic Statistics
- Description: Provides statistics on network traffic for interfaces.
- Example:
sar -n DEV 1
- Usage:
vnstat -i eth0
(for interface-specific data)
- Capture Packets with Filters
- Description: Captures network packets using filters to narrow down the data.
- Example:
tcpdump -i eth0 port 80
- Usage:
tshark -f "port 80"
(for filtering specific ports)
- Analyze Network Bandwidth Usage
- Description: Analyzes network bandwidth usage over a specified period.
- Example:
vnstat -d
- Usage:
nload
(for real-time analysis)
- Check System Network Configuration
- Description: Displays the system-wide network configuration.
- Example:
ip a s
- Usage:
ifconfig -a
(alternative command)
- View Interface Packet Errors
- Description: Shows packet errors and dropped packets for interfaces.
- Example:
ip -s link show
- Usage:
netstat -i
(for interface statistics)
- Analyze Network Device Usage
- Description: Provides usage statistics for network devices.
- Example:
dstat -n
- Usage:
sar -n DEV 1
(for historical data)
- Check for Network Interface Issues
- Description: Diagnoses issues with network interfaces and configuration.
- Example:
ip link show eth0
- Usage:
ifconfig eth0
(alternative command)