Learning Objectives
- Understand Linux networking architecture.
- Identify network interfaces.
- Learn IPv4, IPv6 and CIDR notation.
- View network configuration and routing.
- Understand basic DNS configuration.
Prerequisites
Complete Chapters 1–7 before starting this chapter.
Jump to hands-on practice, or skip to the networking basics and pass over the OSI/TCP/ports reference tables below if you already know them.
OSI Model Quick Reference
Understanding layers helps troubleshoot network issues:
| Layer | Name | Example | Linux Tools |
|---|---|---|---|
| 7 | Application | HTTP, SSH, DNS | curl, ssh, dig |
| 6 | Presentation | SSL/TLS, JPEG | openssl |
| 5 | Session | NetBIOS, RPC | ss |
| 4 | Transport | TCP, UDP | ss |
| 3 | Network | IP, ICMP | ping, traceroute, ip route |
| 2 | Data Link | Ethernet, MAC | ip link, ip neigh |
| 1 | Physical | Cables, Hubs | ethtool |
TCP vs UDP Comparison
| Feature | TCP | UDP |
|---|---|---|
| Connection | Connection-oriented | Connectionless |
| Reliability | Reliable, ordered byte stream: lost segments are acknowledged and retransmitted | Best effort: no acknowledgements, retransmission, or ordering |
| Overhead | Higher (handshake, acknowledgements, connection state) | Lower (no handshake or connection state) |
| Use Cases | HTTP, SSH, SMTP, FTP | DNS, DHCP, Streaming, VoIP |
| Header Size | 20-60 bytes | 8 bytes |
TCP does not "guarantee" delivery in an absolute sense — if the network stays broken, the connection eventually fails. What it provides is a reliable, ordered stream: within a working connection, data arrives in order and lost segments are retransmitted. UDP has lower overhead, which often makes it feel faster, but it is not automatically faster; on a congested link its lack of flow and congestion control can actually hurt throughput.
Common Ports Reference
| Port | Service | Protocol | Description |
|---|---|---|---|
| 22 | SSH | TCP | Secure Shell |
| 53 | DNS | TCP/UDP | Domain Name System |
| 80 | HTTP | TCP | Web traffic |
| 443 | HTTPS | TCP | Secure web traffic |
| 25 | SMTP | TCP | Email sending |
| 110 | POP3 | TCP | Email retrieval |
| 143 | IMAP | TCP | Email access |
| 3306 | MySQL | TCP | Database |
| 5432 | PostgreSQL | TCP | Database |
| 6379 | Redis | TCP | In-memory store |
1. Linux Networking Architecture
Application ──► TCP / UDP ──► IP Layer ──► Network Interface ──► Physical Network
Linux networking is layered, allowing applications to communicate reliably across local and remote networks.
2. Network Interfaces
ip link
ip addr
ip -br addr
hostname -I
| Interface | Purpose |
|---|---|
| lo | Loopback interface. |
| eth0 / ens* | Ethernet interface. |
| VLAN | Logical network segmentation. |
| Bridge | Virtual switching. |
| Virtual NIC | Used by virtual machines. |
3. IP Addressing
| Concept | Example |
|---|---|
| IPv4 private (RFC 1918): 192.168.0.0/16 | 192.168.1.10/24 |
| IPv4 private (RFC 1918): 10.0.0.0/8 | 10.0.0.5/16 |
| IPv4 private (RFC 1918): 172.16.0.0/12 | 172.16.20.50/24 |
| IPv6 documentation (RFC 3849) | 2001:db8::10/64 |
CIDR notation combines the IP address with the network prefix length, replacing traditional subnet mask notation. The three private ranges defined by RFC 1918 — 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16 — are reserved for internal networks and are not routable on the public internet.
4. Viewing Network Information
| Command | Purpose |
|---|---|
| ip addr | Show IP configuration. |
| ip route | Display routing table. |
| hostname -I | Display assigned IP addresses. |
| ss -tuln | Show listening TCP/UDP ports. |
5. DNS Basics
| File | Purpose |
|---|---|
| /etc/resolv.conf | DNS server configuration. |
| /etc/hosts | Local hostname resolution. |
Query DNS directly with dig to see exactly what the resolver returns:
dig example.com # full answer for the A record
dig +short example.com # just the IP address(es)
dig example.com MX # mail (MX) records
dig +short -x 93.184.216.34 # reverse lookup (IP to name)
nslookup example.com # simpler, interactive alternative
On systems running systemd-resolved, resolvectl status shows which DNS servers each interface is using and resolvectl query example.com resolves a name through that service.
6. Linux vs IBM AIX
| Linux | IBM AIX |
|---|---|
| ip addr | ifconfig -a |
| ip route | netstat -rn |
| ss -tuln | netstat -an |
7. Hands-on Practice
- List all interfaces using
ip link. - Display IP addresses with
ip addr. - Show routing information.
- View listening ports.
- Inspect
/etc/resolv.confand/etc/hosts.
8. Common Mistakes
- Confusing IP addresses with hostnames.
- Ignoring the default gateway.
- Editing DNS files without backups.
- Overlooking IPv6 configuration.
9. Part 1 Summary
Key Takeaways
- Linux networking starts with interfaces, IP addressing and routing.
- Use
ipcommands to inspect network configuration. - DNS relies on
/etc/resolv.confand/etc/hosts. sshelps identify listening services.
10. Connectivity Testing (ping, traceroute)
ping -c 4 google.com
traceroute google.com
tracepath google.com
ping tests basic IP connectivity, and traceroute/tracepath show the route packets take to a host. Remember that ping uses ICMP, which many firewalls and cloud providers block — a failed ping does not always mean the host is down. Confirm another way: test DNS with dig +short host, probe the application with curl -I https://host, or use nc -vz host 443 for a TCP port check. On the server itself, ss -tuln only shows whether a service is listening locally — it does not prove remote reachability.
11. Routing & Default Gateways
| Route Type | Purpose |
|---|---|
| Default Gateway | Route used for external networks. |
| Static Route | Manually configured network path. |
| Connected Route | Automatically created for local networks. |
12. Network Configuration (nmcli, curl)
nmcli is the command-line front end for NetworkManager, which manages interfaces and connections on most desktop and RHEL-family systems. Not every system uses NetworkManager: some servers use systemd-networkd, and Debian/Ubuntu server installs often use Netplan (which renders to either backend). Check what is active with systemctl status NetworkManager before relying on nmcli. Use curl and wget to test HTTP endpoints and download files:
nmcli device status # per-interface state (NetworkManager)
nmcli connection show # configured connection profiles
curl -I https://example.com # fetch just the HTTP response headers
wget https://example.com/file.zip # download a file
13. OpenSSH Remote Administration (ssh, scp, sftp)
SSH encrypts remote administration sessions. Edit /etc/ssh/sshd_config, validate the syntax with sshd -t, then reload the service so the new settings take effect.
ssh user@server.example.com # open a remote shell
scp report.txt user@server.example.com:/tmp/ # copy a file to the server
sftp user@server.example.com # interactive file transfer session
sudo systemctl reload sshd # RHEL/Rocky/Fedora unit name
# Common hardening directives in /etc/ssh/sshd_config
PermitRootLogin no
PasswordAuthentication no
Where key-based login is available, set those directives, run sshd -t, then reload. Keep a second session open so a bad change does not lock you out.
14. Firewall Basics (ufw, firewalld)
Both UFW and firewalld are friendly front ends to the kernel's netfilter/nftables packet filter; you rarely need to write raw rules by hand. Use the tool your distribution ships with.
Debian / Ubuntu (UFW):
sudo ufw status
sudo ufw allow OpenSSH
sudo ufw enable
RHEL / Rocky / AlmaLinux / Fedora (firewalld):
sudo firewall-cmd --state
sudo firewall-cmd --add-service=ssh --permanent # allow SSH across reboots
sudo firewall-cmd --reload # apply permanent rules
sudo firewall-cmd --list-all # show the active zone's rules
With firewalld, changes made without --permanent apply immediately but are lost on reload/reboot; adding --permanent then --reload makes them persist. Both tools ultimately program nftables underneath.
15. Production Networking Troubleshooting
| Problem | Possible Cause | Useful Commands |
|---|---|---|
| Cannot SSH | SSH service stopped or firewall blocked | systemctl status sshd|ssh, ss -tuln, journalctl -u … |
| DNS Failure | Incorrect resolver configuration | dig, getent hosts, cat /etc/resolv.conf |
| Wrong Gateway | Incorrect default route | ip route, ip route get DEST |
Commands Covered in This Chapter
ip— show and configure interfaces, addresses, and routesping— test reachability with ICMPtraceroute— show the path packets take to a hostss— list sockets and listening ports (modern netstat)dig/nslookup— query DNSnmcli— manage NetworkManager connectionsssh/scp/sftp— remote login and file transfercurl/wget— fetch URLs and download filesufw/firewall-cmd— manage firewall rules (UFW and firewalld)