# DNS and Hosts Resolution

<span class="TextRun SCXO38321458 BCX0" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun SCXO38321458 BCX0">====================================================================================</span></span>

### <span class="TextRun SCXO38321458 BCX0" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun SCXO38321458 BCX0">DNS and Hosts Testing</span></span>

<span class="TextRun SCXO41186676 BCX0" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun SCXO41186676 BCX0">------------------------------------------------------------------------------------------------------------------------------------------------</span></span>

```
dig domainname
```

dig from a specific DNS server

```
dig domainname @DNS_ServerIP
```

<span class="TextRun SCXO38321458 BCX0" data-contrast="none" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun SCXO38321458 BCX0">====================================================================================</span></span>

### DNS and Host Resolution

<span class="TextRun SCXO41186676 BCX0" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun SCXO41186676 BCX0">------------------------------------------------------------------------------------------------------------------------------------------------</span></span>

#### <span class="EOP SCXO41186676 BCX0">/etc/resolv.conf</span>

<span class="EOP SCXO41186676 BCX0">The /etc/resolv.conf file is used to configure DNS server that your server will use for DNS lookups. </span>

*<span class="EOP SCXO41186676 BCX0">Important Note; The below documentation is related to the /etc/resolve.conf file. This is not the primary file that Linux machines will use for the resolution configuration. Instead, this file is symlinked to /run/systemd/resolve/stub-resolve.conf which is referenced by systemd-resolvd. The primary configuration file used by systemd-resolvd is /run/systemd/resolve/resolve.conf, but stub-resolv.conf is also referenced. TLDR; /etc/resolve.conf is still used, but it's not the primary place referenced by systemd-resolvd.</span>*

```
root@test:~# ls -l /etc/resolv.conf
lrwxrwxrwx 1 root root 39 Aug 10  2023 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
```

<span class="EOP SCXO41186676 BCX0">The systemd-resolved service listens on port 53 locally: this port needs to be open in order for DNS resolution to function.</span>

```
root@test:~# lsof -i:53
COMMAND      PID            USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
systemd-r 127318 systemd-resolve   13u  IPv4 1028696      0t0  UDP localhost:domain
systemd-r 127318 systemd-resolve   14u  IPv4 1028697      0t0  TCP localhost:domain (LISTEN)
```

##### <span class="EOP SCXO41186676 BCX0">/etc/Resolve.conf config:</span>

Below is a typical default configuration you might see on a Linux system:

```
# This file configures your system's DNS resolution.

nameserver 127.0.0.53  # Local DNS server (systemd-resolved)
options edns0 trust-ad  # Enables EDNS for performance 
search b4sed.xyz        # Search domain to append to incomplete names
```

<span class="EOP SCXO41186676 BCX0">`nameserver` - specifies where the system looks for DNS resolution</span>

`<span class="EOP SCXO41186676 BCX0">search</span>` - This is the default search domain. For example, if a lookup is made to google, this option would append .b4sed.xyz to the end: google.b4sed.xyz

`<span class="EOP SCXO41186676 BCX0">options:</span>`

<span class="EOP SCXO41186676 BCX0"> `edns0` - enables a potentially performance-enhancing feature.</span>

<span class="EOP SCXO41186676 BCX0"> `trust-ad` - instructs your resolver to accept and potentially use the information in the Additional Records section without further verification.</span>

##### <span class="EOP SCXO41186676 BCX0">View current DNS configuration:</span>

```
resolvectl status
```

<span class="TextRun SCXO41186676 BCX0" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun SCXO41186676 BCX0">------------------------------------------------------------------------------------------------------------------------------------------------</span></span>

#### /etc/hosts

The /etc/hosts file can be thought of as essentially a local DNS configuration. This means that DNS entries can be mapped here, overwriting any DNS entries provided by an external service.

Entries into the /etc/hosts file can be formatted as follows:

```
IP domainname
```

<span class="TextRun SCXO41186676 BCX0" data-contrast="none" lang="EN-US" xml:lang="EN-US"><span class="NormalTextRun SCXO41186676 BCX0">------------------------------------------------------------------------------------------------------------------------------------------------</span></span>