Understanding networking is crucial for administering Linux systems, especially in environments where multiple systems need to communicate. This page covers the foundational concepts of networking and essential commands in Linux.
- IP Address: A unique identifier assigned to each device on a network. IP addresses can be either IPv4 or IPv6.
- IPv4: A 32-bit address represented as four decimal numbers separated by dots (e.g.,
192.168.1.1
). - IPv6: A 128-bit address represented as eight groups of four hexadecimal digits (e.g.,
2001:0db8:85a3:0000:0000:8a2e:0370:7334
).
- IPv4: A 32-bit address represented as four decimal numbers separated by dots (e.g.,
- Subnet: A subdivision of an IP network. Subnetting allows for better network management and security.
- Subnet Mask: A 32-bit number that separates the IP address into the network and host portions (e.g.,
255.255.255.0
). - CIDR Notation: A shorthand for specifying an IP address and its associated network mask (e.g.,
192.168.1.0/24
).
- Subnet Mask: A 32-bit number that separates the IP address into the network and host portions (e.g.,
- DNS: A system that translates human-readable domain names (e.g.,
www.example.com
) into IP addresses.- DNS Servers: Servers that store DNS records and respond to queries from clients (e.g.,
8.8.8.8
for Google DNS).
- DNS Servers: Servers that store DNS records and respond to queries from clients (e.g.,
- DHCP: A protocol used to automatically assign IP addresses and other network settings to devices on a network.
- DHCP Server: A server that dynamically assigns IP addresses to devices.
- DHCP Lease: The duration for which an IP address is assigned to a device.
- MAC Address: A unique hardware identifier assigned to a network interface card (NIC). MAC addresses are 48 bits long and typically represented in hexadecimal (e.g.,
00:1A:2B:3C:4D:5E
).
-
ifconfig
: A traditional command for configuring network interfaces.- Usage:
ifconfig
- Key Features:
- Displays IP addresses, subnet masks, and other information for network interfaces.
- Can be used to bring interfaces up or down.
- Usage:
-
ip
: A more modern and powerful command for network configuration.- Usage:
ip addr ip link ip route
- Key Features:
ip addr
: Displays IP addresses and associated information.ip link
: Manages network interfaces.ip route
: Manages routing tables.
- Usage:
ping
: Tests connectivity between your system and another device by sending ICMP echo requests.- Usage:
ping 8.8.8.8
- Key Features:
- Verifies whether a host is reachable.
- Measures round-trip time and packet loss.
- Usage:
traceroute
: Traces the path packets take to reach a destination.- Usage:
traceroute www.example.com
- Key Features:
- Identifies each hop between your system and the destination.
- Useful for diagnosing network routing issues.
- Usage:
-
netstat
: Displays network connections, routing tables, and interface statistics.- Usage:
netstat -tuln
- Key Features:
- Shows active listening ports.
- Displays network statistics.
- Usage:
-
ss
: A modern alternative tonetstat
for displaying socket statistics.- Usage:
ss -tuln
- Key Features:
- Faster and more detailed than
netstat
. - Displays TCP, UDP, and UNIX socket connections.
- Faster and more detailed than
- Usage:
-
curl
: A command-line tool for transferring data from or to a server using various protocols (HTTP, FTP, etc.).- Usage:
curl http://www.example.com
- Key Features:
- Downloads or uploads data to/from servers.
- Supports multiple protocols.
- Usage:
-
wget
: A command-line utility for downloading files from the web.- Usage:
wget http://www.example.com/file.zip
- Key Features:
- Supports downloading files from HTTP, HTTPS, and FTP protocols.
- Can download entire websites for offline viewing.
- Usage:
-
nslookup
: Queries DNS to obtain domain name or IP address mapping.- Usage:
nslookup www.example.com
- Key Features:
- Resolves domain names to IP addresses.
- Can be used to troubleshoot DNS issues.
- Usage:
-
dig
: A more flexible and powerful DNS lookup utility.- Usage:
dig www.example.com
- Key Features:
- Provides detailed information about DNS queries.
- Supports various query types (A, AAAA, MX, etc.).
- Usage:
-
iptables
: A command-line tool for configuring the Linux kernel’s packet filtering rules (firewall).- Usage:
sudo iptables -L
- Key Features:
- Manages rules that control incoming and outgoing traffic.
- Can filter packets based on IP address, port, protocol, etc.
- Usage:
-
ufw
: A user-friendly frontend for managing firewall rules, typically used on Ubuntu.- Usage:
sudo ufw status sudo ufw allow 22/tcp
- Key Features:
- Simplifies firewall management.
- Can quickly enable or disable firewall rules.
- Usage:
hostname
: Displays or sets the system's hostname.- Usage:
hostname sudo hostnamectl set-hostname new-hostname
- Key Features:
- Displays the current hostname.
- Can be used to change the system’s hostname.
- Usage:
- Location:
/etc/network/interfaces
- Purpose: Configuration file for network interfaces in Debian-based distributions.
- Example:
auto eth0 iface eth0 inet static address 192.168.1.100 netmask 255.255.255.0 gateway 192.168.1.1
- Location:
/etc/resolv.conf
- Purpose: Configuration file for DNS resolution.
- Example:
nameserver 8.8.8.8 nameserver 8.8.4.4
- Location:
/etc/hosts
- Purpose: Maps hostnames to IP addresses.
- Example:
127.0.0.1 localhost 192.168.1.100 myserver.localdomain myserver
- Use
ip addr
orifconfig
to ensure network interfaces are up and configured correctly.
- Use
ping
to check connectivity between devices. - Use
traceroute
to diagnose network path issues.
- Use
nslookup
ordig
to ensure DNS is resolving domain names correctly.
- Use
netstat
orss
to monitor network connections and troubleshoot issues.
Networking is a fundamental aspect of Linux system administration. Mastering the basic commands and understanding the underlying concepts will enable you to effectively manage and troubleshoot network issues on your Linux systems.
Next: Networking Commands
Previous: System Monitoring and Logging