> For the complete documentation index, see [llms.txt](https://mamawhocode.gitbook.io/devops/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mamawhocode.gitbook.io/devops/pre-requisite/networking.md).

# Networking

### Switching

check host order on [<mark style="color:yellow;">/etc/nsswitch.conf</mark>](#user-content-fn-1)[^1]

### Routing

#### What is routing?

The **`process`** to find the [<mark style="color:yellow;">`best path`</mark>](#user-content-fn-2)[^2] for data to travel from 1 device to another.

#### Commands

```sh
# show routing table
route
ip route

# add entries into routing table
ip route add 192.168.1.0/24 via 192.168.2.1

# assign new ip address
sudo ip addr add 172.16.238.15/24 dev eth0
```

### Default gateway

### DNS configuration

#### Domain names

for example: [www.google.com](http://www.google.com)

<figure><img src="/files/JdmotRTAArO4dvgiPdET" alt=""><figcaption><p>Domain names: root > top level > subdomain</p></figcaption></figure>

#### Record types

| Type  | explain              | IP (ex)                                 |
| ----- | -------------------- | --------------------------------------- |
| A     | IPv4                 | 192.168.1.1                             |
| AAAA  | IPv6                 | 2001:0db8:85a3:0000:0000:8a2e:0370:7334 |
| CNAME | name to name mapping | eat.web-server, hungry.web-server       |

#### Commands

```sh
# query the DNS server
nslookup www.google.com

# get details of DNS name resolution
dig www.google.com
```

#### DNS configuration file

`resolv.conf` contains nameserver, the resolver will ask the nameserver for ip address.

```
/etc/resolv.conf
```

#### Commands

```sh
# check host list
cat /etc/resolv.conf

# add server to host file
cat >> /etc/hosts
192.168.1.1
```

[^1]: Name Service Switch config file

[^2]: the shortest path
