Networking
Computer networking is the practice of connecting computer systems and other computing devices (like servers, mobile phones, printers, etc.) together through various communication links to allow them to share data and resources. This interconnection facilitates communication between users and enables access to shared services and information.
Networking forms the backbone of modern computing, enabling everything from sharing files between two computers to the global connectivity provided by the Internet. It relies on a set of rules called protocols that govern how data is formatted, sent, and received.
Contents
Overview
At its core, computer networking is about enabling devices to communicate. This communication can be:
- Device-to-Device: Two computers exchanging files directly.
- Device-to-Server: A computer accessing a website hosted on a web server.
- Server-to-Server: Two servers synchronizing data.
Networks can vary greatly in scale, from a few devices in a home to millions worldwide. The complexity of managing communication between devices increases significantly with the size and geographical distribution of the network.
Components
Computer networks are comprised of various hardware and software components:
- Devices (Nodes): The computers, servers, phones, etc., connected to the network.
- Network Interfaces: Hardware (like an Ethernet card or Wi-Fi adapter) that allows a device to connect to the network medium.
- Transmission Media: The physical pathways data travels on, such as Ethernet cables, fiber optic cables, or wireless signals (radio waves).
- Network Switches: Devices that connect multiple devices within a local network (like a home or office) and forward data packets only to the intended destination device based on its physical address.
- Routers: Devices that connect different networks together (e.g., your home network to the internet) and forward data packets between them based on IP addresses.
- Protocols: Rules and standards (like TCP/IP) that define how devices communicate, format data into packets, address recipients, and handle errors.
Types of Networks
Networks are often classified by their scale and scope:
- LAN (Local Area Network): Connects devices within a limited area, such as a home, office building, or campus.
- WAN (Wide Area Network): Connects devices over a large geographical area, spanning cities, regions, or even countries, often using telecommunication links.
- Internet: The largest WAN, a global network of interconnected networks.
- Other types: Include PAN (Personal Area Network), MAN (Metropolitan Area Network), SAN (Storage Area Network), etc.
How it Works (Simplified)
When one device sends data to another across a network, the process generally follows these steps:
1. The sending device's software breaks the data into smaller chunks called packets. 2. Each packet is given a header containing information like the source and destination IP addresses, the type of data, and the packet's sequence number. 3. The packet travels from the source device, through network interfaces, switches, and routers. Each router along the path reads the destination IP address and forwards the packet towards the destination network. 4. Intermediate devices ensure the packet reaches the next hop in the path. 5. Upon reaching the destination network, the packet is delivered to the device with the matching destination IP address. 6. The receiving device's software collects all the packets belonging to the data and reassembles them in the correct order. If packets are missing or corrupted, requests for retransmission may occur (depending on the protocol).
This entire process relies on a stack of protocols (like the TCP/IP model) where different protocols handle different aspects of the communication, from the physical transmission of bits to the reliable delivery of application data.
Network Troubleshooting on Linux (CLI Tutorial)
Network troubleshooting involves identifying and resolving problems that prevent devices from communicating correctly across a network. Tools like `traceroute` and `mtr` are invaluable for diagnosing connectivity issues and pinpointing where delays or packet loss might be occurring along the path data takes to a destination.
Prerequisites:
- A Linux system.
- Command-line access.
- sudo privileges may be needed for installation.
Using traceroute
The `traceroute` command maps the path that data packets take from your computer to a specified destination on the network, showing each router (hop) along the way and the time it takes to reach each hop.
- Open your terminal.
- Run the traceroute command:
Replace `hostname_or_ip` with the website address (like `google.com`) or the IP address you want to trace to.
traceroute hostname_or_ip
Example:
traceroute google.com
- Interpret the output:
The output lists the hops (routers) in order from your system to the destination.
traceroute to google.com (142.250.186.14), 30 hops max, 60 byte packets
1 myrouter (192.168.1.1) 1.234 ms 0.876 ms 0.987 ms 2 isp-router1.example.com (203.0.113.1) 9.876 ms 10.123 ms 9.987 ms 3 isp-router2.example.com (203.0.113.5) 15.123 ms 14.876 ms 15.010 ms ... 8 google-router.example.com (142.250.186.14) 25.123 ms 24.876 ms 25.010 ms
- The first column is the hop number.
- The second column is the hostname (if resolved) and IP address of the router at that hop.
- The following three columns are the round-trip times (RTT) for three separate packets sent to that hop, measured in milliseconds (ms).
Troubleshooting with traceroute:
- High Latency: If the RTT times suddenly jump at a specific hop and remain high for subsequent hops, it might indicate congestion or a problem at that router or the link leading to it.
- Packet Loss: Asterisks (`*`) instead of RTT times indicate that packets sent to that hop timed out, suggesting packet loss somewhere along the path to or from that hop. If loss occurs consistently starting at a particular hop, that hop or the network segment beyond it could be the source of the problem.
- Timeout at the End: If traceroute completes but shows timeouts for the final hops, the destination might be blocking ICMP traffic (which traceroute uses) or have a firewall issue, even if the service (like a website) is actually available.
Using mtr
`mtr` (My Traceroute) is a more advanced tool that combines the functionality of `ping` and `traceroute`. It continuously sends packets and provides updated statistics for each hop, allowing you to see performance over time.
- Install mtr (if not already installed):
sudo apt update sudo apt install mtr
- Run the mtr command:
mtr hostname_or_ip
Example:
mtr google.com
This will open a dynamic display in your terminal that updates statistics continuously. Press `q` to quit.
- Interpret the output:
The `mtr` output shows a list of hops like traceroute, but with ongoing statistics columns:
Packets Pings Host Loss% Snt Last Avg Best Wrst StDev 1. myrouter.lan 0.0% 100 1.2 0.9 0.8 1.5 0.1 2. isp-router1.example.com 0.0% 100 10.1 10.0 9.8 10.5 0.2 3. isp-router2.example.com 0.0% 100 15.0 14.9 14.8 15.2 0.1 ... 8. google-router.example.com 0.0% 100 25.0 25.1 24.8 25.5 0.2
- Loss%: Percentage of packets lost at this hop.
- Snt: Number of packets sent.
- Last, Avg, Best, Wrst: Latency (RTT) for the last, average, best (minimum), and worst (maximum) packet, in ms.
- StDev: Standard deviation of the latency, indicating how much the RTT varies.
Troubleshooting with mtr:
- Identifying Packet Loss: Look for hops with a significant `Loss%`. If loss occurs at a hop but not at subsequent hops, the loss might be specific to the traffic `mtr` sends back from that hop (e.g., rate limiting on the router). If loss starts at a hop and continues for all subsequent hops, it strongly indicates a problem at that hop or the network link immediately after it.
- Identifying Latency Issues: Look for hops where the `Avg` or `Wrst` latency is significantly higher than previous hops. A sudden jump in latency that persists down the path indicates a slowdown at or after that hop. A high `StDev` suggests inconsistent latency (jitter).
- mtr Report Mode:
You can run `mtr` for a specific number of cycles and generate a report instead of a live display using the `-c` and `-r` options.
mtr -c 10 -r hostname_or_ip
This sends 10 packets and prints a final report.
These tools help narrow down whether a network problem is local, with your internet service provider, or further out on the internet towards the destination.