Networking is at the core of Linux systems, and understanding how to analyze and manage networks is a crucial skill for cybersecurity professionals. This chapter covers the tools and commands needed to inspect, configure, and troubleshoot network connections in Linux.
- Displays network interfaces and their configurations.
- Deprecated on some systems; replaced by
ip
.
- Provides detailed information and control over network interfaces.
ifconfig # Display all network interfaces
ip a # Show all IP addresses
ip link show # Show link-layer information
ip addr show eth0 # Show details for a specific interface (e.g., eth0)
- Use
ifconfig
orip
to enable or disable network interfaces.
sudo ifconfig eth0 up # Enable eth0 interface
sudo ifconfig eth0 down # Disable eth0 interface
sudo ip link set eth0 up # Enable eth0 interface with ip
sudo ip link set eth0 down # Disable eth0 interface with ip
- Sends ICMP packets to test reachability.
ping 8.8.8.8 # Ping Google DNS
ping -c 4 example.com # Send 4 packets to a domain
- Identifies the path packets take to a destination.
traceroute example.com
- Queries DNS servers for information about domains.
dig example.com # Perform a DNS lookup
dig +short example.com # Show only the IP address
- Provides basic DNS resolution.
nslookup example.com
- Captures and inspects network packets.
sudo tcpdump -i eth0 # Capture all traffic on eth0
sudo tcpdump port 80 # Capture HTTP traffic
sudo tcpdump -w capture.pcap # Save captured traffic to a file
- Analyze captured traffic with a graphical interface.
- Displays or changes the kernel routing table.
route -n # Display routing table
sudo route add default gw 192.168.1.1 # Add a default gateway
- Replaces
route
for managing routing tables.
ip route show # Display current routes
sudo ip route add default via 192.168.1.1 # Add a default gateway
- Scans networks for open ports and services.
nmap 192.168.1.0/24 # Scan an entire subnet
nmap -p 80,443 example.com # Scan specific ports on a domain
- Displays active connections, listening ports, and routing tables.
netstat -tuln # Show listening ports and connections
- Provides detailed information and settings for network interfaces.
sudo ethtool eth0 # Display details about eth0
- Displays and modifies the ARP table.
arp -a # View ARP table
sudo arp -d 192.168.1.1 # Delete an entry from the ARP table
- Configures network packet filtering rules.
sudo iptables -L # List all rules
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT # Allow SSH traffic
By the end of this chapter, you should be able to:
- View and configure network interfaces.
- Test and troubleshoot network connectivity.
- Analyze network traffic using
tcpdump
andnmap
. - Manage routes and DNS resolution.
- Move to Chapter 4: Adding and Removing Software to learn about managing packages in Linux.
- Display all active network interfaces on your system.
- Ping your default gateway and verify connectivity.
- Use
tcpdump
to capture HTTP traffic and save it to a file. - Scan your local subnet with
nmap
to identify active devices. - Add a new default gateway using
ip route
and verify it withip route show
.