Learn Networking CLI Commands

Basic Networking Commands

  1. 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)
  2. 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)
  3. 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)
  4. View Routing Table
    • Description: Shows the current routing table used for directing network traffic.
    • Example: netstat -r
    • Usage: route -n (alternative command)
  5. Network Interface Statistics
    • Description: Displays statistics for each network interface, including packet counts and errors.
    • Example: netstat -i
    • Usage: ip -s link (alternative command)
  6. 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)
  7. 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)
  8. 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)
  9. 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)
  10. 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

  1. 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)
  2. Activate or Deactivate Interface
    • Description: Brings a network interface up or down.
    • Example: ifconfig eth0 up
    • Usage: ifconfig eth0 down (to deactivate)
  3. 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)
  4. 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)
  5. 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

  1. List Active Listening Ports
    • Description: Shows all ports currently listening for incoming connections.
    • Example: netstat -l
    • Usage: ss -l (alternative command)
  2. Display Active Connections
    • Description: Lists all active network connections and their statuses.
    • Example: netstat -a
    • Usage: ss -a (alternative command)
  3. Show Listening Ports
    • Description: Displays all ports that are currently in a listening state.
    • Example: netstat -tuln
    • Usage: ss -tuln (alternative command)
  4. 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)
  5. Check Firewall Rules
    • Description: Displays the rules currently applied by the firewall.
    • Example: iptables -L
    • Usage: firewall-cmd --list-all (for firewalld)
  6. 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)
  7. 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 and iperf -c [server IP] (alternative command)
  8. Monitor Network Traffic
    • Description: Captures and displays network packets in real-time.
    • Example: tcpdump -i eth0
    • Usage: tshark -i eth0 (alternative command)
  9. 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)
  10. 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

  1. 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)
  2. Display ARP Cache
    • Description: Shows the ARP cache, which maps IP addresses to MAC addresses.
    • Example: arp -a
    • Usage: ip neighbour (alternative command)
  3. View Routing Details
    • Description: Provides detailed information about the system’s routing table.
    • Example: route -n
    • Usage: ip route show (alternative command)
  4. Flush DNS Cache
    • Description: Clears the DNS cache to resolve issues with DNS resolution.
    • Example: systemd-resolve --flush-caches
    • Usage: service nscd restart (if using nscd)
  5. List Network Namespaces
    • Description: Lists all network namespaces present on the system.
    • Example: ip netns list
    • Usage: ls /var/run/netns/ (alternative command)
  6. 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]
  7. 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)
  8. 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)
  9. 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)
  10. Monitor Bandwidth Usage
    • Description: Analyze and monitor bandwidth usage over time.
    • Example: nload
    • Usage: vnstat (for historical bandwidth data)

Linux Networking Troubleshooting Commands

  1. Check Network Configuration
    • Description: Displays the current network configuration for interfaces.
    • Example: ip a
    • Usage: ifconfig (alternative command)
  2. Inspect Interface Status
    • Description: Shows the status and configuration of network interfaces.
    • Example: ip link
    • Usage: ifconfig -a (alternative command)
  3. View Interface Errors
    • Description: Displays errors and dropped packets on network interfaces.
    • Example: ip -s link
    • Usage: netstat -i (alternative command)
  4. 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)
  5. List Open Ports and Services
    • Description: Lists all open ports and the services associated with them.
    • Example: ss -tuln
    • Usage: netstat -tuln (alternative command)
  6. Summarize Network Configuration
    • Description: Provides a summary of routing and network configurations.
    • Example: ip route
    • Usage: route -n (alternative command)
  7. 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)
  8. Check Interface State
    • Description: Displays the current operational state of network interfaces.
    • Example: ip link show
    • Usage: ifconfig (alternative command)
  9. Trace Network Path
    • Description: Traces the route packets take to reach a destination host.
    • Example: tracepath example.com
    • Usage: traceroute example.com (alternative command)
  10. Capture Network Packets
    • Description: Captures network packets for analysis.
    • Example: tcpdump -i eth0
    • Usage: wireshark (for graphical packet analysis)
  11. 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)
  12. 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)
  13. Network Connection Statistics
    • Description: Displays statistics about active network connections.
    • Example: ss -s
    • Usage: netstat -s (alternative command)
  14. Detailed Interface Error Information
    • Description: Shows detailed error information for network interfaces.
    • Example: ip -s link
    • Usage: ifstat (for interface statistics)
  15. Device Configuration Information
    • Description: Retrieves configuration details for network devices.
    • Example: lshw -C network
    • Usage: lsusb (for USB network devices)
  16. 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)
  17. Display Interface Configuration
    • Description: Shows configuration details for a specified network interface.
    • Example: ifquery eth0
    • Usage: nmcli device show eth0 (alternative command)
  18. System-wide Network Statistics
    • Description: Provides overall network statistics for the system.
    • Example: netstat -s
    • Usage: sar -n DEV (for historical network statistics)
  19. 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)
  20. 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)
  21. 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)
  22. 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)
  23. Analyze Network Traffic Patterns
    • Description: Examines network traffic patterns and usage.
    • Example: vnstat
    • Usage: iftop (for real-time traffic analysis)
  24. Protocol-specific Network Statistics
    • Description: Shows network statistics categorized by protocol types.
    • Example: netstat -p
    • Usage: ss -p (for protocol-specific connection statistics)
  25. 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)
  26. 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)
  27. Check Interface Speed
    • Description: Verifies the speed of a network interface.
    • Example: ethtool eth0
    • Usage: ethtool -S eth0 (for statistics and speed information)
  28. 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)
  29. Measure Network Throughput
    • Description: Tests the network throughput between systems.
    • Example: iperf -c [server IP]
    • Usage: iperf3 -c [server IP] (for improved version)
  30. 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)
  31. 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)
  32. 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)
  33. Display TCP Connection Details
    • Description: Shows detailed information about TCP connections.
    • Example: ss -t -a
    • Usage: netstat -tn (alternative command)
  34. View Network Interface Configuration
    • Description: Retrieves the configuration details of network interfaces.
    • Example: ifconfig eth0
    • Usage: ip addr show eth0 (alternative command)
  35. Monitor Network Latency
    • Description: Observes network latency over time.
    • Example: mtr example.com
    • Usage: ping -i 2 example.com (for regular interval pings)
  36. 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)
  37. View Network Connections by Port
    • Description: Lists network connections grouped by port number.
    • Example: ss -tnlp
    • Usage: netstat -tulpn (alternative command)
  38. Show Interface Driver Information
    • Description: Displays driver information for network interfaces.
    • Example: ethtool -i eth0
    • Usage: lsmod | grep [driver_name] (for module details)
  39. 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)
  40. 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)
  41. Analyze Network Bandwidth Usage
    • Description: Analyzes network bandwidth usage over a specified period.
    • Example: vnstat -d
    • Usage: nload (for real-time analysis)
  42. Check System Network Configuration
    • Description: Displays the system-wide network configuration.
    • Example: ip a s
    • Usage: ifconfig -a (alternative command)
  43. View Interface Packet Errors
    • Description: Shows packet errors and dropped packets for interfaces.
    • Example: ip -s link show
    • Usage: netstat -i (for interface statistics)
  44. Analyze Network Device Usage
    • Description: Provides usage statistics for network devices.
    • Example: dstat -n
    • Usage: sar -n DEV 1 (for historical data)
  45. Check for Network Interface Issues
    • Description: Diagnoses issues with network interfaces and configuration.
    • Example: ip link show eth0
    • Usage: ifconfig eth0 (alternative command)