Skip to main content

Command Palette

Search for a command to run...

Linux Network Administrator’s Guide

Published
5 min readView as Markdown

The Linux Network Administrator’s Guide is designed to provide network administrators with essential commands and practices for configuring, monitoring, and troubleshooting networks on Linux-based systems. This guide covers key aspects of network administration, from basic configurations to advanced topics.

Table of Contents

Network Configuration

  • Display Network Interfaces and IP Addresses

  • Configure Network Interface

  • Display Routing Information

  • Set Default Gateway

  • DNS Configuration

Network Monitoring

  • Monitor Network Connections

  • Capture Network Packets

Firewall Management

  • Display iptables Rules

  • Allow Incoming Traffic

  • Block Incoming Traffic

Network Troubleshooting

  • Check Network Connectivity

  • DNS Lookup

  • Check Open Ports

1. Network Configuration

Display Network Interfaces and IP Addresses

# Display information for all network interfaces

$ ifconfig

The ifconfig command provides a comprehensive view of all network interfaces along with their current configuration details, including IP addresses, MAC addresses, and more.

# Display detailed information for all network interfaces

$ ip addr show

The ip addr show command, part of the iproute2 package, offers more detailed information about network interfaces, including IPv4 and IPv6 addresses, broadcast addresses, and the current status.

Configure Network Interface

# Configure a network interface with a static IP address

$ sudo ifconfig eth0 192.168.1.2 netmask 255.255.255.0 up

This command configures the eth0 interface with a static IP address (192.168.1.2) and a netmask of 255.255.255.0. The up parameter activates the interface.

# Configure a network interface with DHCP

$ sudo dhclient eth0

The dhclient command requests an IP address from a DHCP server for the specified interface (eth0 in this case).

Display Routing Information

# Display the routing table

$ route -n

The route -n command shows the system’s routing table, including destination networks, gateways, and interface associations.

# Display the routing table using ip command

$ ip route show

The ip route show command, part of the iproute2 package, provides a modern and more flexible way to display routing information.

Set Default Gateway

# Set the default gateway

$ sudo route add default gw 192.168.1.1

This command sets the default gateway for the system, directing traffic not matching any specific route to the specified gateway (192.168.1.1).

# Set the default gateway using ip command

$ sudo ip route add default via 192.168.1.1

The ip route add default via command is an alternative to the route command for setting the default gateway.

DNS Configuration

# Display DNS information

$ cat /etc/resolv.conf

The /etc/resolv.conf file contains DNS configuration information, including the IP addresses of DNS servers.

# Edit DNS configuration

$ sudo nano /etc/resolv.conf

Use a text editor, such as nano, to edit the DNS configuration. This file allows specifying DNS servers and search domains.

2. Network Monitoring

Monitor Network Connections

# Display active network connections

$ netstat -tunlp

The netstat -tunlp command shows active network connections along with the associated processes and listening ports.

# Display listening ports

$ ss -tunlp

The ss -tunlp command provides similar information to netstat but is part of the iproute2 package.

Capture Network Packets

# Capture packets on a specific interface

$ sudo tcpdump -i eth0

The tcpdump command captures and displays network packets on the specified interface (eth0 in this example).

# Capture packets on a specific port

$ sudo tcpdump port 80

Use the port option to capture packets related to a specific port (e.g., port 80 for HTTP traffic).

3. Firewall Management

Display iptables Rules

# Display all iptables rules

$ sudo iptables -L

The iptables -L command shows the current rules configured in the iptables firewall.

# Display detailed iptables rules with line numbers

$ sudo iptables -L -n - line-numbers

Adding the — line-numbers option to iptables -L displays the rules with line numbers, aiding in management.

Allow Incoming Traffic

# Allow incoming traffic on a specific port

$ sudo iptables -A INPUT -p tcp - dport 22 -j ACCEPT

This command appends a rule to the INPUT chain, allowing incoming TCP traffic on port 22 (SSH).

Block Incoming Traffic

# Block incoming traffic on a specific port

$ sudo iptables -A INPUT -p tcp - dport 80 -j DROP

This command appends a rule to the INPUT chain, blocking incoming TCP traffic on port 80.

4. Network Troubleshooting

Check Network Connectivity

# Ping a host to check network connectivity

$ ping google.com

The ping command sends ICMP Echo Request messages to a host, checking for network connectivity.

# Trace the route to a host

$ traceroute google.com

The traceroute command traces the route that packets take to reach a destination, showing each hop along the way.

DNS Lookup

# Perform DNS lookup

$ nslookup google.com

The nslookup command performs DNS lookups, providing information about domain names and IP addresses.

# Resolve IP address to hostname

$ host 8.8.8.8

The host command resolves an IP address to its associated hostname.

Check Open Ports

# Check if a specific port is open

$ telnet localhost 22

The telnet command checks if a specific port (e.g., port 22 for SSH) is open on a local or remote system.

# Check if a specific port is open using nc

$ nc -zv localhost 22

The nc command (netcat) with options -zv checks for open ports without sending any data.

This comprehensive guide provides Linux network administrators with essential commands and examples for configuring, monitoring, and troubleshooting networks on Linux-based systems. Adjust parameters and options based on specific requirements and scenarios.

More from this blog

khushbu's blog

38 posts