On Internet model, there are 5 layers. They’re Physical Layer, Data Link Layer, Network Layer, Transport Layer and Application Layer. Each of them has its own protocols and addresses. Each layer can only communicates with its adjacent layers.
Addresses
MAC Address is the address in Data Link Layer (Layer 2). IP Address is the address in Network Layer (Layer 3). Port Number is the address in Transport Layer (Layer 4). Mostly, we’re dealing with IP address and Port number.
IP Address
IP address is used to identify a host. IPv4 address is ranged from 0.0.0.0-255.255.255.255. Each section is from 0-255. An IP address can be private, public or for special use.
Private IP address can be used in local network only, it doesn’t resolve on the internet. LAN IP are often private IP. Private IP are ranged at 10.0.0.0-10.255.255.255, 172.16.0.0-172.31.255.255, 192.168.0.0-192.168.255.255.
Public IP address are used on the internet, WAN IP are often public IP. Public IP is ranged from 1.0.0.0-223.255.255, except for Private IP, 127.0.0.0-127.255.255.255 (loopback address) and 169.254.0.0-169.254.255.255 (link local address).
The remaining addresses are reserved or for special use.
Port Number
Port number indicates which application the packet is sending to. Port number can be ranged from 0-65535. Port number on server side is often static and on client side it’s dynamic. Port 49151-65535 are explicitly for private use (client port).
Well known server ports includes 21 (FTP), 22 (SSH), 23 (Telnet), 25 (SMTP), 53 (DNS), 67/68 (DHCP), 80 (HTTP), 110 (POP3), 137/139 (Samba), 143 (IMAP), 443 (HTTPS), 465/587 (SMTPS), 520 (RIP), 546/547 (DHCPv6), 993 (IMAPS), 995 (POP3S).
NAT
Network Address Translation is widely used in home router. It allows us to use the same public IP address (the one from ISP) with multiple devices. The IP address of our devices is actually a private address, which means it can be used in LAN only.
Let’s see what’s happening when we browse a webpage in LAN:
- When we open Chrome, the computer assigns a random port number. If we go to google from Chrome, Chrome sends a packet to Google with source destination and its assigned port (Let’s say 192.168.0.3:54321 -> 216.58.220.110:443).
- Then the router maps the private address and source port to a random port in router, then alters the source address and source port of the packet (e.g. 123.234.321.23:11111) and send it to Google, now the packet becomes 123.234.321.23:11111 -> 216.58.220.110:443.
- Google replies to the router with the webpage, it’s destination is 123.234.321.23:11111, the router maps back to the original private address and rewrites the destination to 192.168.0.3:54321. Then your computer knows port 54321 is for Chrome and sent the data to it.
That’s it for what we need to configure our device working on LAN. With the basic concept of how network works we can now proceed to implement access to Raspberry Pi.