Skip to main content

Command Palette

Search for a command to run...

Networking Basics

Let's learn about the fundamentals of Networking

Updated
•8 min read•View as Markdown
Networking Basics

Network Basics

See the below basic terms we use for our home network

  1. ISP - Your internet service provider, the company you pay to get internet at your house.

  2. Router - The router allows each machine on your network to connect to the internet. In most modern routers, you can connect via wireless or an Ethernet cable.

  3. WAN - Wide Area Network. This is what we call the network that encompasses everything between your router and a wider network, such as the internet.

  4. WLAN - Wireless Local Area Network. This is the network between your router and any wireless devices you may have, such as laptops.

  5. LAN - Local Area Network. This is the network between your router and any wired devices, such as desktop PCs.

  6. Hosts - Each machine on a network is known as a host.

Note: The data and the information that gets transmitted through networks are known as ‘packets’.

OSI : Open System Interconnection. This is a theoritical model of networking which shows how the packets are transmitted in a network in seven different layers.

Network Addressing: Packets are transferred using MAC(Media Access Control) address and IP address. Hostname is more easily readable for human.

MAC Address: A MAC address is a unique idenitifier used as a hardware address. This address will never change. MAC addresses are given to the network adapters when they are manufactured.
Each manufacturer has an Organizationally Unique Identifier (OUI) to identify them as the manufacturer. This OUI is denoted by the first 3 bytes of the MAC address. For example, Dell has 00-14-22, so a network adapter from Dell could have a MAC address like: 00-14-22-34-B2-C2.

IP Address: An IP address is used to identity a device on a network. They are hardware independent and can vary in syntax depending on if you are using IPv4 or IPv6.
Typical IP Address looks like: 10.24.12.4
IP Addresses are used with the software side of networking.

  • Anytime a system is connected to the internet, it should have an IP address. They can also change if your network change.

Note: It takes both software and hardware to move packets accross networks. So we have 2 identifiers for each: MAC(hardware) and IP Address(software).

Hostnames: Another way to identify your machine is through hostname. Hostname takes your IP address and tie that to a human readable name. Instread of remembering 192.12.41.4, you can just remember myhost.com.

Note: A packet is consist of a header and a payload.
Header contains information about where the packet is going to and where it has come from.
The Payload contains the actual data that is being transferred.

First, we start off in the application layer. When we send our email through our email client, the application layer will encapsulate this data. The application layer talks to the transport layer through a specified port, and through this port, it sends its data. We want to send an email through the application layer protocol SMTP (Simple Mail Transfer Protocol). The data is sent through our transport protocol, which opens a connection to this port (port 25 is used for SMTP). So, we get this data sent through this port, and that data is sent to the Transport layer to be encapsulated into segments.

Transport Layer: This layer helps to transfer the data in such a way that the network can read it. It breaks the data into chunks and that will be transported and put back together in correct order. These chunks are known as segments. Segments make it easier to transport data accross network.

Ports: Even though IP adress are required to send the data, but it’s not enough for certain process or services. Services such as HTTP use a communication channel via ports. Ex- If we want to send a webpage data, we need to send it via HTTP Port (port 80).

In addtion to forming segments, the transport layer will also attach the source and the destination ports to the segment, so when the receiver receives the final package, it will know which port to use.

UDP: It is one of the transport protocol. UDP is not a reliable method of transporting data; in fact, it doesn't really care if you get all of your original data. This may sound terrible, but it does have its uses, such as for media streaming. It's okay if you lose some frames; in return, you get your data a little faster.

TCP: It provides a reliable, connection oriented stream of data. TCP uses ports to send data to and from hosts. In order to establish the connection, we use the TCP handshake.

  • The client (connecting process) sends a SYN segment to the server to request a connection.

  • The server sends the client a SYN-ACK segment to acknowledge the client's connection request.

  • The client sends an ACK to the server to acknowledge the server's connection request.

Once this connection is established, data can be exchanged over a TCP connection. The transport layer attaches the destination port (25) to the source port of the source host.

Network Layer: This determines the routing of packets from host to a destination host. Internet is made up of many large networks. Small network make up the internet are known as subnet.

Link Layer: At the bottom of the TCP/IP model sits the Link Layer. This layer is hardware-specific. In the link layer, our packet is encapsulated once more into something called a frame. The frame header attaches the source and destination MAC addresses of our hosts, checksums, and packet separators so that the receiver can tell when a packet ends

Packet Traversal Flow

  1. Pete sends Patty an email: this data gets sent to the transport layer.

  2. The transport layer encapsulates the data into a TCP or UDP header to form a segment. The segment attaches the destination and source TCP or UDP port, then the segment is sent to the network layer.

  3. The network layer encapsulates the TCP segment inside an IP packet; it attaches the source and destination IP address. Then it routes the packet to the link layer.

  4. The packet then reaches Pete's physical hardware and gets encapsulated in a frame. The source and destination MAC addresses get added to the frame.

  5. Patty receives this data frame through her physical layer and checks each frame for data integrity, then de-encapsulates the frame contents and sends the IP packet to the network layer.

  6. The network layer reads the packet to find the source and destination IP that was previously attached. It checks if its IP is the same as the destination IP, which it is! It de-encapsulates the packet and sends the segment to the transport layer.

  7. The transport layer de-encapsulates the segments, checks the TCP or UDP port numbers, and makes a connection to the application layer based on those port numbers.

  8. The application layer receives the data from the transport layer on the port that was specified and presents it to Patty in the form of the final email message.

ip a: This is a shortcut for IP Address show.

labex:~/ $ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:16:3e:02:c7:98 brd ff:ff:ff:ff:ff:ff
    altname enp0s5
    altname ens5
    inet 172.16.50.30/24 metric 100 brd 172.16.50.255 scope global dynamic eth0
       valid_lft 1892159915sec preferred_lft 1892159915sec
    inet6 fe80::216:3eff:fe02:c798/64 scope link 
       valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:59:7f:f3:1f brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
  1. lo: This is the loopback interface, a virtual network interface that the system uses to communicate with itself. It always has the IP address 127.0.0.1.

  2. eth0 (or a similar name like enp0s5): This is your primary Ethernet interface, which connects your system to the external network. Notice the altname fields, which provide alternative names for the interface.

  3. docker0: If Docker is installed, you might see a docker0 interface, which is a virtual bridge created by Docker for container networking.

MAC Address (link/ether): This is to identify the Media Access Control address.

labex:~/ $ ip a | grep "link/ether"
    link/ether 00:16:3e:02:c7:98 brd ff:ff:ff:ff:ff:ff
    link/ether 02:42:59:7f:f3:1f brd ff:ff:ff:ff:ff:ff
##IPv4 Address
labex:~/ $ ip a | grep "inet "
    inet 127.0.0.1/8 scope host lo
    inet 172.16.50.30/24 metric 100 brd 172.16.50.255 scope global dynamic eth0
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
  1. 127.0.0.1: This is the loopback address, which the system uses to communicate with itself.

  2. 172.16.50.202/24: This is the primary IPv4 address for the eth0 interface, used for communicating with other devices on the network. The /24 is the CIDR notation, which defines the subnet mask for the network. Your address will be different.

  3. 172.17.0.1/16: This is the IPv4 address for the docker0 bridge.

##IPv6 Address
labex:~/ $ ip a | grep "inet6"
    inet6 ::1/128 scope host 
    inet6 fe80::216:3eff:fe02:c798/64 scope link
  1. ::1/128: This is the compressed format for the IPv6 loopback address, equivalent to 127.0.0.1 in IPv4.

  2. fe80::216:3eff:fe0e:d83c/64: This is a link-local IPv6 address for the eth0 interface. Link-local addresses are automatically configured on all IPv6-enabled interfaces and are used for communication only on the same local network segment. Your address will be different.

Note: The loopback address, which is almost always 127.0.0.1, is a special IP address that a computer uses to refer to itself.

labex:~/ $ ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.038 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.021 ms

##we will ping a well-known public IP address: 8.8.8.8. 
##This is the address for one of Google's public DNS servers
##which is highly available and a standard choice for testing internet connectivity.

labex:~/ $ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=1.40 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=118 time=1.34 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=118 time=1.35 ms

##Pinging to unassigned IP
labex:~/ $ ping 172.16.50.250
PING 172.16.50.250 (172.16.50.250) 56(84) bytes of data.
^C
--- 172.16.50.250 ping statistics ---
23 packets transmitted, 0 received, 100% packet loss, time 22521ms

##The IP address range from 224.0.0.0 to 239.255.255.255 is reserved for multicast (Class D). 
##We will use a special, 
##well-known multicast address: 224.0.0.1. This is the "all-hosts" group address. 

labex:~/ $ ping 224.0.0.1
PING 224.0.0.1 (224.0.0.1) 56(84) bytes of data.
^C
--- 224.0.0.1 ping statistics ---
5 packets transmitted, 0 received, 100% packet loss, time 4093ms

Networking Fundamentals

Part 1 of 2

In this series, let's go through all the basic fundamental concepts of networking.

Up next

Networking Basics Part 2

Let's see some linux commands related to Network