Skip to main content
Version: 7.26

Networking Fundamentals

A computer network is built from many components and protocols that work together. This page explains the basics that the rest of the manual relies on: how the layers of a network fit together, how Ethernet and IPv4 address devices, how ARP connects the two, and how TCP carries data reliably. The IPv6 basics are on separate pages:

Network models​

The OSI model and the TCP/IP model split network communication into layers. Each layer uses the services of the next lower layer and provides services to the next higher layer.

OSI Model​

The Open Systems Interconnection (OSI) model has seven layers. It was designed as a standard architecture for building network systems. Today it is used mainly as a teaching tool, because real networks do not separate the layers as strictly as the model suggests.

  • Layer 7 (Application): the protocol that defines the communication between a server and a client, for example HTTP. When a web browser downloads an image, this protocol organizes and carries out the request.
  • Layer 6 (Presentation): makes sure that the data arrives in a usable format. Encryption belongs to this layer in the model, although real protocols do not always follow it (IPsec, for example, encrypts at the network layer).
  • Layer 5 (Session): sets up, manages and closes the sessions between a client and a server.
  • Layer 4 (Transport): divides a data stream into chunks (segments), numbers them and puts them back together at the other end. The segments are carried in a protocol header, for example TCP or UDP.
  • Layer 3 (Network): gives devices logical addresses. The data is carried in an IP header and is called a packet.
  • Layer 2 (Data link): carries the data in a link header, for example 802.3 (Ethernet) or 802.11 (wireless), and is called a frame. This layer also handles flow control on the link.
  • Layer 1 (Physical): the medium that sends and receives bits: the electrical or radio signal and the hardware interface.

TCP/IP model​

The TCP/IP model has the same purpose as the OSI model but matches the protocols that networks use today, which makes it more practical for troubleshooting. It has four layers:

  • Application layer (4): combines the application, presentation and session layers of the OSI model.
  • Transport layer (3): the same as the OSI transport layer (TCP, UDP).
  • Internet layer (2): does the same as the OSI network layer (IP, ICMP).
  • Link layer (1): also called the network access layer. It combines OSI layers 1 and 2 and deals with the physical exchange of data between nodes.
TCP/IPOSI modelProtocols
Application layerApplication layerDNS, DHCP, HTTP, SSH, for example
Presentation layerJPEG, MPEG, PICT, for example
Session layerPAP, SCP, ZIP, for example
Transport layerTransport layerTCP, UDP
Internet layerNetwork layerICMP, IGMP, IPv4, IPv6, IPsec
Link layerData link layerARP, CDP, MPLS, PPP, for example
Physical layerBluetooth, Ethernet, Wi-Fi, for example

Ethernet​

Ethernet is the most widely used link layer (OSI layer 2) protocol. Each node on an Ethernet network has a unique address, the MAC address (Media Access Control address), also called the Ethernet address.

A MAC address is 48 bits long. It used to be fixed by the manufacturer, but today it is common to change it, and RouterOS can set a custom MAC address on an interface. The usual format is six hexadecimal numbers separated by colons, for example D4:CA:6D:01:22:96.

RouterOS shows the MAC address of every Ethernet-like interface (Ethernet, wireless, VPLS and others) in its configuration:

[admin@MikroTik] > /interface/ethernet/print
Flags: R - RUNNING
Columns: NAME, MTU, MAC-ADDRESS, ARP
# NAME MTU MAC-ADDRESS ARP
0 R ether1 9001 02:FF:D5:5D:51:27 enabled

An Ethernet frame is delivered in one of three ways:

  • Unicast: the frame carries the MAC address of one node. On a shared medium (a hub, or all receivers in range of a wireless signal) every node receives the frame, but only the node with the matching MAC address accepts it, unless the interface is in promiscuous mode.
  • Broadcast: the frame is sent to the special address FF:FF:FF:FF:FF:FF. Every node on the layer 2 network accepts it and switches forward it to all ports.
  • Multicast: the frame is sent to a multicast address and is received by all nodes that are configured to listen to this address.

IP Networking​

Ethernet is enough to deliver data between two nodes on the same Ethernet network, but not to nodes several hops away across other networks. For that, the network layer (OSI layer 3) uses the Internet Protocol (IP), which gives each host a unique logical address.

Most networks use IPv4, which has 32-bit addresses written in dotted-decimal notation (192.168.88.1). IPv6 uses 128-bit addresses and is used more and more widely.

An interface can have several IP addresses, or none. A physical interface without an address can still carry traffic: for example, a bridge port or an interface that only carries a PPPoE connection. Set the IP address of a bridge on the bridge interface, not on its ports: an address on a bridge port gets the S (slave) flag, and the router adds no route for its network.

Netmasks​

An IP network is a range of addresses, and the netmask tells which part of an address identifies the network. A netmask is usually written as the number of bits that identify the network, for example /24. The same mask can also be written in dotted-decimal notation: a 24-bit netmask is 255.255.255.0.

IPv4 Addresses​

An IPv4 address has four bytes, split into four 8-bit fields called octets. Each octet is written as a decimal number, and the octets are separated by dots. For example:

11000000 10101000 00000011 00011000 => 192.168.3.24

This is how the netmask of 192.168.3.24/24 gives the address range:

11000000 10101000 00000011 00011000 => 192.168.3.24
11111111 11111111 11111111 00000000 => /24 or 255.255.255.0

The mask covers the first 24 bits, so the last octet is free, and the range is 192.168.3.0 to 192.168.3.255. The range has three types of addresses:

  • Network address: the first address of the range identifies the network (192.168.3.0 in this example).
  • Broadcast address: the last address of the range (192.168.3.255). A packet sent to this directed broadcast address reaches all hosts of the network, so the sender sends the data only once and every receiver gets a copy. The address 255.255.255.255 is the limited broadcast: it reaches all hosts on the local network segment, and routers do not forward it.
  • Unicast address: all other addresses of the range identify single hosts (192.168.3.1 to 192.168.3.254 in this example).

As in Ethernet, there is a special address range for multicast. A multicast address stands for a group of interested receivers. In IPv4, the addresses 224.0.0.0 to 239.255.255.255 are multicast addresses. The sender sends a single packet from its unicast address to the group address, and the routers on the way copy it to every receiver that has joined the group.

Three clouds of hosts: in unicast one host sends to one other host, in broadcast one host sends to every host, in multicast one host sends to the group of interested hosts only

Some address ranges are reserved for special purposes:

  • Private address ranges (RFC 1918), for use in local networks only. They are not routed on the internet:
    • 10.0.0.0/8: 10.0.0.0 to 10.255.255.255
    • 172.16.0.0/12: 172.16.0.0 to 172.31.255.255
    • 192.168.0.0/16: 192.168.0.0 to 192.168.255.255
  • 198.18.0.0/15: benchmarking.
  • 192.88.99.0/24: 6to4 relay anycast (deprecated by RFC 7526).
  • 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24: documentation.
  • 169.254.0.0/16: link-local addresses that hosts assign to themselves when no other address is available.

Point-to-point addressing​

A point-to-point link is a layer 3 network with only two nodes, for example two routers connected with one cable. To save address space, address such a link in one of two ways:

  • Use a /31 network: the two addresses of the range are the two hosts, and the range has no network or broadcast address.

  • Use /32 addresses, and set the address of the other side as the network of each address. For example:

    flowchart LR
      H1 --- H2
    
      H1["**Host 1**<br />____________________<br /> **Address**: 192.168.0.1/32<br />**Network**: 192.168.0.2"]
      H2["**Host 2**<br />____________________<br /> **Address**: 192.168.0.2/32<br />**Network**: 192.168.0.1"]
    
      style H1 text-align:left
      style H2 text-align:left

Address configuration​

IPv4 addresses are added in /ip/address, with the netmask after the slash. This command gives the bridge of a local network the address 192.168.88.1 in the network 192.168.88.0/24:

/ip/address/add address=192.168.88.1/24 interface=bridge1

With the /32 method, two directly connected routers can use addresses from unrelated ranges without spending a whole subnet on the link. Each router sets the address of the other side in network:

Router 1:

/ip/address
add address=10.1.1.1/32 interface=ether2 network=172.16.1.1

Router 2:

/ip/address
add address=172.16.1.1/32 interface=ether2 network=10.1.1.1

Each router then has a connected route to the address of the other side, and the routers reach each other. On Router 1:

[admin@MikroTik] > /ip/route/print where dst-address=172.16.1.1/32
Flags: D - DYNAMIC; A - ACTIVE; c - CONNECT
Columns: DST-ADDRESS, GATEWAY, ROUTING-TABLE, DISTANCE
DST-ADDRESS GATEWAY ROUTING-TABLE DISTANCE
DAc 172.16.1.1/32 ether2 main 0
[admin@MikroTik] > /ping 172.16.1.1 count=3
SEQ HOST SIZE TTL TIME STATUS
0 172.16.1.1 56 64 973us
1 172.16.1.1 56 64 631us
2 172.16.1.1 56 64 631us
sent=3 received=3 packet-loss=0% min-rtt=631us avg-rtt=745us
max-rtt=973us

ARP and Tying It All Together​

IP packets are addressed with IP addresses, but on an Ethernet network the frames that carry them are delivered by MAC address. The sender has to find out which MAC address belongs to the IP address it sends to.

That is the job of the Address Resolution Protocol (ARP), which maps the IPv4 address of a host to its hardware (MAC) address. ARP is defined in RFC 826. IPv6 does not use ARP: it resolves addresses with multicast Neighbor Discovery messages instead.

Each network device keeps a table of the ARP entries it uses. By default, the table is built dynamically. To make the network more secure, part or all of it can be built from static entries instead.

When a host wants to send an IP packet to another host on the same local network, it looks for the MAC address of the destination in its ARP table. If the address is not there, the host sends an ARP request: a broadcast to all devices on the network that asks the device with the given IP address to reply with its MAC address. The device that has that IP address answers with an ARP reply that carries its MAC address:

sequenceDiagram
    participant A as Host A<br/>192.168.99.1
    participant B as Host B<br/>192.168.99.2
    participant C as Host C<br/>192.168.99.3
    A->>B: ARP request (broadcast): who has 192.168.99.3?
    A->>C: ARP request (broadcast): who has 192.168.99.3?
    C->>A: ARP reply (unicast): 192.168.99.3 is at the MAC address of C
    A->>C: ICMP echo request (ping)
    C->>A: ICMP echo reply

To see this on routers, connect three RouterOS devices to the same Ethernet network through their ether2 ports and add an address on each one.

Host A:

/ip/address/add address=192.168.99.1/24 interface=ether2

Host B:

/ip/address/add address=192.168.99.2/24 interface=ether2

Host C:

/ip/address/add address=192.168.99.3/24 interface=ether2

On Host A, start the packet sniffer, which saves the packets to a file, ping Host C once, and stop the sniffer:

/tool/sniffer/set file-name=arp.pcap filter-interface=ether2
/tool/sniffer/start
/ping 192.168.99.3 count=1
/tool/sniffer/stop

Download arp.pcap from the router and open it in Wireshark or another packet analyzer. It holds four packets:

1 0.000000000 2e:f6:6d:87:b6:4c → Broadcast ARP 42 Who has 192.168.99.3? Tell 192.168.99.1
2 0.000411833 32:07:40:aa:9f:d7 → 2e:f6:6d:87:b6:4c ARP 42 192.168.99.3 is at 32:07:40:aa:9f:d7
3 0.000418229 192.168.99.1 → 192.168.99.3 ICMP 70 Echo (ping) request id=0xff00, seq=0/0, ttl=255
4 0.000750811 192.168.99.3 → 192.168.99.1 ICMP 70 Echo (ping) reply id=0xff00, seq=0/0, ttl=64 (request in 3)
  • Host A broadcasts an ARP request that asks who has 192.168.99.3.
  • Host C replies that 192.168.99.3 is at its MAC address.
  • Both hosts add each other to their ARP tables, and the ICMP (ping) packets can be sent.

The ARP tables of both hosts (/ip/arp/print) now hold the entry of the other host:

[admin@HostA] > /ip/arp/print where interface=ether2
Flags: D - DYNAMIC; C - COMPLETE
Columns: ADDRESS, MAC-ADDRESS, INTERFACE, VRF, STATUS
# ADDRESS MAC-ADDRESS INTERFACE VRF STATUS
0 DC 192.168.99.3 32:07:40:AA:9F:D7 ether2 main reachable

[admin@HostC] > /ip/arp/print where interface=ether2
Flags: D - DYNAMIC; C - COMPLETE
Columns: ADDRESS, MAC-ADDRESS, INTERFACE, VRF, STATUS
# ADDRESS MAC-ADDRESS INTERFACE VRF STATUS
1 DC 192.168.99.1 2E:F6:6D:87:B6:4C ether2 main reachable

Host B also received the broadcast request, but it did not add an entry for Host A.

ARP modes​

Each interface that supports ARP has an arp setting that changes how the router uses ARP on it:

  • enabled: the router resolves addresses automatically and adds dynamic entries to the ARP table. This is the default.

  • disabled: the router does not send ARP requests and does not answer the requests of other hosts. Both sides then need static ARP entries, or they cannot reach each other. For example, with ARP disabled on Host A, which reaches Host C only:

    Host A:

    /interface/ethernet/set ether2 arp=disabled
    /ip/arp/add mac-address=32:07:40:AA:9F:D7 address=192.168.99.3 \
    interface=ether2

    Host C:

    /ip/arp/add mac-address=2E:F6:6D:87:B6:4C address=192.168.99.1 \
    interface=ether2
  • reply-only: the router answers ARP requests but does not send its own and does not learn dynamic entries, so it reaches only the neighbors that have static entries in its /ip/arp table. Unlike with disabled, the other hosts do not need a static entry for the router.

  • proxy-arp: the router answers ARP requests for addresses that it reaches through another interface, so it acts as a transparent proxy between directly connected networks. This is used, for example, to give dial-in (PPP, PPPoE, PPTP) clients addresses from the same range as the local network. The proxy ARP example in the next section shows how it works.

  • local-proxy-arp: the router does proxy ARP for traffic that comes in and goes out of the same interface. On a LAN, two hosts usually talk to each other directly, without the router. With local-proxy-arp, the router answers ARP requests of the hosts on the interface with its own MAC address instead of the MAC address of the other host.

    For example, when Host A (192.168.88.2/24) asks for the MAC address of Host B (192.168.88.3/24), the router answers with its own MAC address. The ARP tables of Host A and Host B then point to the router for each other, and the router forwards the traffic between them. A typical use is a bridge with isolated bridge ports (the same horizon value), where the hosts of one subnet can reach each other only at layer 3, through the router:

    /interface/bridge
    add arp=local-proxy-arp name=bridge1
    /interface/bridge/port
    add bridge=bridge1 horizon=1 interface=ether2
    add bridge=bridge1 horizon=1 interface=ether3
    add bridge=bridge1 horizon=1 interface=ether4

    This technique has other names:

    • VLAN aggregation (RFC 3069).
    • Private VLAN (Cisco, Allied Telesis).
    • Source-port filtering or port isolation (Hewlett-Packard).
    • MAC-forced forwarding (Ericsson, RFC draft).

Proxy ARP Example​

In this network, the router connects two subnets: 172.16.1.0/24 on ether2 and 172.16.2.0/24 on ether3. Host A has a /16 netmask by mistake, so it believes that the whole 172.16.0.0/16 range, including Host D, is on its own network segment. Host D uses the router (172.16.2.254) as its gateway:

flowchart TB
  subgraph SA["Subnet A: 172.16.1.0/24"]
    A["Host A<br/>172.16.1.2/16"]
  end
  R["Router<br/>ether2: 172.16.1.254/24<br/>ether3: 172.16.2.254/24"]
  subgraph SB["Subnet B: 172.16.2.0/24"]
    D["Host D<br/>172.16.2.3/24"]
  end
  A --- R
  R --- D

To reach Host D (172.16.2.3), Host A (172.16.1.2) does not send the packets to its gateway. It broadcasts an ARP request on subnet A instead. The broadcast reaches ether2 of the router, but not Host D, because a router does not forward layer 2 broadcasts. Without proxy ARP, nobody answers, and Host A cannot reach Host D.

Enable proxy ARP on ether2 of the router:

/interface/ethernet/set ether2 arp=proxy-arp

The router knows that 172.16.2.3 is on another subnet that it reaches, so it answers the request itself, with its own MAC address. In effect it says: "send these packets to me, and I will forward them". A packet analyzer on ether2 shows the request of Host A:

Address Resolution Protocol (request)
Hardware type: Ethernet (1)
Protocol type: IPv4 (0x0800)
Hardware size: 6
Protocol size: 4
Opcode: request (1)
Sender MAC address: 62:d8:bc:cd:96:a9 (62:d8:bc:cd:96:a9)
Sender IP address: 172.16.1.2
Target MAC address: 00:00:00_00:00:00 (00:00:00:00:00:00)
Target IP address: 172.16.2.3

And the reply of the router, which gives the MAC address of its ether2 for the address of Host D:

Address Resolution Protocol (reply)
Hardware type: Ethernet (1)
Protocol type: IPv4 (0x0800)
Hardware size: 6
Protocol size: 4
Opcode: reply (2)
Sender MAC address: 92:e8:17:7b:46:cc (92:e8:17:7b:46:cc)
Sender IP address: 172.16.2.3
Target MAC address: 62:d8:bc:cd:96:a9 (62:d8:bc:cd:96:a9)
Target IP address: 172.16.1.2

Host A adds the answer to its ARP table. This is the table of Host A when it is a RouterOS device:

[admin@HostA] > /ip/arp/print where interface=ether2
Flags: D - DYNAMIC; C - COMPLETE
Columns: ADDRESS, MAC-ADDRESS, INTERFACE, VRF, STATUS
# ADDRESS MAC-ADDRESS INTERFACE VRF STATUS
5 DC 172.16.2.3 92:E8:17:7B:46:CC ether2 main reachable

From now on, Host A sends all packets for Host D to the MAC address of the router, and the router forwards them to Host D. The same happens for every other host of subnet B that Host A talks to: with proxy ARP, many IP addresses map to the single MAC address of the router.

Gratuitous ARP​

RouterOS can create gratuitous ARP requests with the /tool/traffic-generator/inject tool. This example sends a gratuitous ARP request that updates the ARP table on a remote device:

/tool/traffic-generator/inject interface=ether2 \
data="ffffffffffff4c5e0c14ef78080600010800060400014c5e0c14ef780a057a01ffffffffffff0a057a01000000000000000000000000000000000000"

Replace the MAC address (4c5e0c14ef78) and the IP address (0a057a01) with those of the device that wants the ARP tables updated, and ether2 with the interface that sends the request. The receiving device must support gratuitous ARP requests. The traffic generator needs the traffic-gen feature of device mode.

Transport Layer​

Transport layer protocols carry data end to end between applications. Some of them make sure that the packets arrive in order and without errors: the receiver acknowledges the data, and the sender retransmits lost packets.

The best known and most widely used protocol is the Transmission Control Protocol (TCP). It is connection-oriented and has mechanisms for reliable data transfer.

The connectionless User Datagram Protocol (UDP) is the other common protocol, used for simple data transfer.

TCP Protocol Operation​

A connection-oriented protocol sends no data until a connection is established. TCP opens a connection with a handshake. The result is an end-to-end virtual (logical) circuit with flow control and acknowledgments for reliable delivery. TCP uses several message types to open and close connections.

The three-way handshake:

  1. HostA, which opens the connection, sends a SYN (synchronize) packet with a proposed initial sequence number to HostB.
  2. HostB receives the SYN and replies with a packet that has both the SYN and ACK flags set in the TCP header (SYN-ACK).
  3. HostA receives the SYN-ACK and replies with an ACK (acknowledgment) packet. When HostB receives the ACK, the connection is established.
sequenceDiagram
    HostA->>HostB: SYN
    HostB->>HostA: SYN-ACK
    HostA->>HostB: ACK
Note right of HostB: Established

During the transfer, the receiver acknowledges the data it gets. After the sender transmits a packet, it waits for the acknowledgment. If no ACK arrives in time, the sender transmits the packet again.

If the sender transmits faster than the receiver can process the data, the receiver stores the data in a buffer. When the buffer is full, the receiver drops the data that does not fit, and the sender has to transmit it again, which slows the transfer down.

TCP prevents this with flow control based on a window. In each TCP segment, the receiver sets the window field: the amount of data (in bytes) that it is ready to accept into its buffer. The sender sends only as much data as the window allows, and then waits for an acknowledgment with an updated window.

When the receiving application processes the data as fast as it arrives, the receiver advertises a larger window with each acknowledgment. When the sender is faster, the data fills the buffer, and the receiver advertises a zero window. A sender that receives a zero window stops sending until it receives a window larger than zero. An example of the windowing process:

  1. HostA starts with a window of 1000 bytes and sends one 1000-byte segment.
  2. HostB acknowledges it and increases the window to 2000 bytes.
  3. HostA receives the ACK and sends two segments of 1000 bytes each.
  4. HostB increases the window to 3000 bytes. HostA sends three segments and waits for an acknowledgment.
  5. The three segments fill the buffer of HostB faster than its application processes the data, so HostB advertises a zero window, and HostA waits before sending more.
  6. When the buffer has free space again, HostB advertises a larger window, and HostA continues.

The window of the receiver is flow control. The sender also keeps its own congestion window and sends no more than the smaller of the two windows. How the congestion window grows depends on the TCP congestion control algorithm, for example Reno, Vegas or Tahoe.

sequenceDiagram
    HostA->>HostB: 1000 bytes (window 1000)
    HostB->>HostA: ACK, window 2000
    HostA->>HostB: 1000 bytes
    HostA->>HostB: 1000 bytes
    HostB->>HostA: ACK, window 3000
rect rgb(185, 50, 50)
    HostA->>HostB: 1000 bytes
    HostA->>HostB: 1000 bytes
    HostA->>HostB: 1000 bytes
Note left of HostB: Buffer is full, stop sending
    HostB->>HostA: ACK, window 0
end
Note left of HostB: Buffer has free space, continue
    HostB->>HostA: ACK, window 1000

When the transfer is complete, a host closes the connection. Opening a connection takes a three-way handshake, but closing it takes four messages: each side sends a FIN (finish) and receives an ACK.

The four-way termination:

  1. HostA, which closes the connection, sends a segment with the FIN flag to say that it has finished sending data.
  2. HostB receives the FIN, acknowledges it with an ACK and enters the passive close (CLOSE_WAIT) state. It can still send data. When HostB has no more data to send, it sends its own FIN and enters the LAST_ACK state.
  3. HostA receives the FIN of HostB, sends an ACK back and enters the TIME_WAIT state.
  4. HostB receives the ACK, and the connection is closed.
sequenceDiagram
    HostA->>HostB: FIN
Note right of HostB: CLOSE_WAIT
    HostB->>HostA: ACK
    HostB->>HostA: FIN
Note right of HostB: LAST_ACK
    HostA->>HostB: ACK
Note right of HostB: Closed

See more​