> For the complete documentation index, see [llms.txt](https://olb.gitbook.io/linux-essentials-certification/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://olb.gitbook.io/linux-essentials-certification/4.linux-operating-system/4.4-your-computer-on-the-network.md).

# 4.4 Networking

**Weight 2**\
Key knowledge areas

* Internet, network, routers
* Querying DNS client configuration
* Querying network configuration

Partial list of the used files, terms and utilities

* route, ip route show
* ifconfig, ip addr show
* netstat, ss
* /etc/resolv.conf, /etc/hosts
* IPv4, IPv6
* ping
* host

***

* **Link Layer** Handles the communication between directly connected devices.
* **Network Layer**
  * Handles routing outside of individual networks and the unique addressing of devices beyond a single link layer network.
  * packet switching. Data is grouped up with a header, which contains information about where the information is coming from and where it’s going to.
* **Application Layer** Enables individual programs to connect to each other.

## Link Layer Networking

* use MAC address to identify network cards
* `ip link show` display network interfaces / MAC addresses

## IP v4

* 32-bit addresses for routing
* `11000000.10101000.00000000.00000001` = 192.168.0.1 : 4 digits of 8 bit = 32-Bit
* Now for this IP address, the subnet mask sets each bit which belongs to the network part to 1 and each bit that belongs to the host part to 0
* Subnet mask : 255.255.255.0 = 11111111.11111111.11111111.00000000 = 192.168.0.1/24 : allow 192.168.0.0 to 192.168.0.255
* Subnet mask CIDR notation = 192.168.0.1/24
* Private Network:
  * 10.0.0.0/8
  * 172.16.0.0/12
  * 192.168.0.0/16
* Network Address Translation (NAT) : map internal adresses to single external IP or external IP to internal addresses
* DHCP (Dynamic Host Configuration Protocol) for automatic IP configuration
* `ip addr add` add manually a new ip eg.: `sudo ip addr add 192.168.0.5/255.255.255.0 dev ens33`
* `ip addr show` to see information
* `ip route show` lists the current IPv4 routing table
* `sudo ip route add default via 192.168.0.1` add a default route via router 192.168.0.1

## IP v6

* `2001:0db8:0000:abcd:0000:0000:0000:7334` 8 groups of 16-bit (hexa :0 to f) = 128 bits

## IP v6 Prefix

* The first 64 bits of an IPv6 address are known as the **routing prefix**
* Prefix is used by routers to **determine which network a device belongs**
* ISPs usually hand out /48 or /58 prefixes to their customers, leaving them 16 or 8 bits for their internal subnetting.
* There are three major prefix types in IPv6:
  * **Global Unique Address** Wherein the prefix is assigned from the blocks reserved for global addresses. These addresses ware valid in the entire internet.
  * **Unique Local Address** May not be routed in the internet. They may, however, be routed internally within an organization. These addresses are used within a network to ensure the devices still have an address even when there is no internet connection. They are the equivalent of the private address ranges from IPv4. The first 8 bits are always fc or fd, followed by 40 randomly generated bits.
  * **Link Local Address** Are only valid on a particular link. Every IPv6 capable network interface has one such address, starting with fe80. These addresses are used internally by IPv6 to request additional addresses using automatic configuration and to find other computers on the network using the Neighbor Discovery protocol.

## IPv6 Interface Identifier

* the interface identifier is used to enumerate the devices within a network. The last 64 bits in an IPv6 address form the interface identifier, just like the last bits of an IPv4 address

## IPv6 Address Configuration

* **(SLAAC)** Stateless Address Autoconfiguration. Use the new NDP (Neighbor Discovery Protocol) which allows devices to find each other and request information regarding a network.
* **DHCPv6** updated DHCP for IPv6
* `sudo ip addr add 2001:db8:0:abcd:0:0:0:7334/64 dev ens33`

## DNS

* translate domain name to ip
* DNS is set in `/etc/resolv.conf`
* `/etc/host` used first then after DNS server
* `host` to perform a lookup - `dig` for more info
* DNS records:
  * Textual data :TXT
  * Reverse IP address lookup : PTR
  * Translet Domain name to IP : A
  * Domain relies on another domain : CNAME
  * Mail Server : MX

## Sockets

* communication endpoint provided by an application. Protocol + port
* **Unix Sockets** Which connect processes running on the same device.
* **UDP (User Datagram Protocol) Sockets** Which connect applications using a protocol which is fast but not resilient.
* **TCP (Transmission Control Protocol) Sockets** Which are more reliable than UDP sockets and, for example, confirm the receipt of data.
* `ss` to list open sockets
  * `-p` list processes
  * `-s` summarize
  * `-t` for tcp `-u` for udp
  * `-l` only listening socket
  * `-4` or `-6` for filter IPv4 / IPv6
