Skip to content

Networking basics

Kyle Terrien edited this page Feb 19, 2017 · 1 revision

Networking is the process of enabling multiple computers to communicate with each other.

The key concept of networking is a protocol, which is an agreed upon way of communicating. When two devices speak the same protocol correctly, they can communicate. If they deviate, then bad things happen, ranging from no work getting done to a network meltdown.

ISO/OSI model

Networking at a basic level is a bunch of protocols building on top of each other. The ISO/OSI model defines 7 layers of protocols. Protocols in a higher layer build off of services provided by protocols in the lower layers. The term network stack is occasionally used to refer to the ISO/OSI model, along with the terms higher level protocol and lower level protocol.

Layer Name Common protocols
7 Application Layer HTTP, DNS, Email, SSH, FTP, Gopher
6 Presentation Layer Normally part of application layer
5 Session Layer Normally part of application layer
4 Transport Layer TCP, UDP
3 Network Layer IP
2 Data Link Layer Ethernet, Wi-Fi
1 Physical Layer Cat6/RJ45, radio waves

The important thing to remember about the OSI is that the layers are guidelines. Sometimes there is blurring between the lines of layers, and quite often some layers (particularly 5 and 6) are not used at all.

Layers 1-2: Ethernet, Wireless Fidelity (Wi-Fi)

Layers 1 and 2 are usually tied together. On the wired front, there is Ethernet. Devices connected on the same Ethernet network are said to be on the same network segment. Originally, a hub was used to forward frames to all devices on the network segment.

In some configurations, coaxial cable was used to link several computers together. This coaxial cable formed a line with a splitter for each device and terminators on both ends (hence the term network segment).

TODO: Diagram of a hub architecture. Possibly another one of a coaxial network segment.

However, there was a scalability problem. As the number of devices on the network segment increases, the likelihood of packet collisions increases. The way around this is by using a switch. A switch stores a packet and forwards it to the correct destination.

TODO: Diagram of a layer 2 switch in action.

Each device has a physical address (usually called a MAC address). A unit of data sent across a layer 2 network is called a frame.

Ethernet typically runs over Cat6/RJ45, but it can run over other media. On the wireless side, there is Wireless Fidelity (Wi-Fi), which resembles Ethernet except frames are sent over radio. Wi-Fi also has additional authentication mechanisms.

If you are using a Wi-Fi network that does not implement authentication, then you are broadcasting your frames in plain text for anyone to see (even those who have not "joined" the network).

Layer 3: Internet Protocol

Internet Protocol (IP) deals with logical addresses instead of physical addresses. This means that any given address can have its assignment changed to another physical device. IPv4 uses 32-bit addresses. IPv6 uses 128-bit addresses.

A unit of data sent across a layer 3 protocol is called a packet.

There is a protocol called Address Resolution Protocol (ARP) that takes an IP address and maps it to a physical address. It does this by sending a broadcast frame to the entire network segment asking, "who has IP address X?" The device with IP address X replies, "I do!"

Routers

Layer 3 protocols can connect layer 2 network segments and forward data between them. This is possible due to a special device called a router. A router is a device connected to at least two network segments. A router forwards data between its network segments according to a set of firewall rules. One property of a route is that it has one IP address for each network segment to which it is connected. (So, if a router is connected to two segments, it will have two IP addresses.)

TODO: Diagram of a router

Network Address Translation (NAT)

Not all IP addresses are publicly accessible. There are two notable ranges that are reserved for private networks: 10.0.0.0/8 and 192.168.0.0/16. If you want to connect devices to the Internet without having them accessible from the Internet, use one of these ranges and set your router to a mode called Network Address Translation (NAT). (By default, most consumer-level router boxes are already set to NAT.)

Network Address Translation (NAT) is the process of rewriting the source and destination fields of packets as they flow through the router. Obviously, sending a packet from a private LAN to a public address is easy. However, sending a reply is impossible unless some entity rewrites the source address as the packet leaves the network.

TODO: Diagram of NAT setup

This is how your home network is setup. Your router has an internal IP address used for your LAN and an external (WAN) IP address that the rest of the world sees.

Layer 4: Transmission Control Protocol (TCP), User Datagram Protocol (UDP)

The problem with the Internet (like most road networks) is congestion. If there were no congestion and reliability control, then packets clog up one router until the router cannot store any more packets. At that point, packets are dropped and will never reach the destination.

Transmission Control Protocol (TCP) ensures that packets arrive at the destination. It does this by implementing congestion control algorithms to ensure that the network path does not get overloaded and by retransmitting any packets that get dropped.

User Datagram Protocol (UDP) does not provide any reliability. UDP simply sends the packets and hopes for the best. The application must handle reliability and congestion control.

Why would someone ever use UDP? UDP is common in realtime scenarios, where the cost of resending a dropped packet outweighs the cost of just accepting that the packet was dropped. Voice over IP (VOIP) systems use UDP for that reason. Also, network games (such as our LUG's favorite of BZFlag) use UDP because the games must be synchronized in realtime.

Layer 5-7: Application protocols

The upper layers run the protocols that actually do things to serve us users.

  • Hypertext Transfer Protocol (HTTP) := Transfers data from web sites.
  • Email
    • Post Office Protocol (POP) := Retrieves mail from a datastore and stores the mail locally. The mail is deleted from the server. (The server acts like a post office box.)
    • Internet Message Access Protocol (IMAP) := Retrieves mail from a persistent datastore and sometimes synchronizes the mail locally. The mail is left on the server.
    • Simple Mail Transfer Protocol (SMTP) := Forwards mail across hosts.
  • Secure Shell (SSH) := Provides a secure authenticated remote shell. It can also forward network ports and X11 commands.
  • File Transfer Protocol (FTP) := This is the old-school method of downloading (and uploading) files.
  • Gopher := Text-based hypertext system that predates the web. It has a cult following because of its simplicity.
  • Many proprietary undocumented protocols such as iTunes, Microsoft's data collection protocol, etc.

There are also quite a few infrastructure services that most take for granted.

  • Dynamic Host Configuration Protocol (DHCP) := Gives a new host joining a network an IP address, routing information, and optionally DNS/NTP information.
  • Domain Name Service (DNS) := Resolves hostnames to IP addresses.
  • Network Time Protocol (NTP) := Synchronizes clocks across machines. This may seem silly at first, but there is network software that relies on the system clock being accurate between two machines.