---
# System prepended metadata

title: Configuring DNS Server
tags: [mininet-wifi-tutorials]

---

---
tags: mininet-wifi-tutorials
---

# Configuring DNS Server

This tutorial requires you to install _containernet_ from https://github.com/ramonfontes/containernet. So, considering that you already have installed _containernet_, run the script below:


```python=
#!/usr/bin/python

"""
@author: Ramon Fontes
@email: ramonreisfontes@gmail.com
"""


from containernet.net import Containernet
from containernet.node import Docker
from containernet.cli import CLI
from mininet.log import info, setLogLevel


def topology():
    net = Containernet()

    info('*** Adding docker containers\n')
    sta1 = net.addStation('sta1', ip='10.0.0.1', mac='00:02:00:00:00:01')
    h1 = net.addHost('h1', ip='10.0.0.3', mac='00:02:00:00:00:03',
                     cls=Docker, dimage="mec1", cpu_shares=20)
    h2 = net.addHost('h2', ip='10.0.0.4', mac='00:02:00:00:00:04',
                     cls=Docker, dimage="mec2", cpu_shares=20)
    h3 = net.addHost('h3', ip='10.0.0.5', mac='00:02:00:00:00:05',
                     cls=Docker, dimage="dns:latest", cpu_shares=20)
    ap1 = net.addAccessPoint('ap1', position='75,100,0', failMode='standalone')
    ap2 = net.addAccessPoint('ap2', position='125,100,0', failMode='standalone')

    net.setPropagationModel(model="logDistance", exp=4)

    info('*** Configuring WiFi nodes\n')
    net.configureWifiNodes()

    info('*** Configuring Links\n')
    net.addLink(ap1, ap2)
    net.addLink(ap1, h1)
    net.addLink(ap2, h2)
    net.addLink(ap2, h3)

    info('*** Plotting Graph...\n')
    net.plotGraph(max_x=200, max_y=200)

    net.startMobility(time=0, repetitions=1)
    net.mobility(sta1, 'start', time=1, position='10.0,90.0,0.0')
    net.mobility(sta1, 'stop', time=12, position='150.0,90.0,0.0')
    net.stopMobility(time=23)

    info('*** Starting network\n')
    net.start()
    ap1.start([])
    ap2.start([])

    info('*** Running CLI\n')
    CLI(net)

    info('*** Stopping network\n')
    net.stop()


if __name__ == '__main__':
    setLogLevel('info')
    topology()
```



```
sudo python containernet_wifi_dns.py
```

## Installing and configuring bind9


The node **h3** will be our DNS Server. So, open a terminal for **h3** and let's then install and configure Bind9.

```
containernet> xterm h3
```

Bind is the most widely used Domain Name System (DNS) software on the Internet. On Unix-like operating systems it is the de facto standard. It performs both of the main DNS server roles – acting as an authoritative name server for one or more specific domains, and acting as a recursive resolver for the DNS system generally.


The APT package index is essentially a database of available packages from the repositories defined in the /etc/apt/sources.list file and in the /etc/apt/sources.list.d directory. To update the local package index with the latest changes made in the repositories, type the following:

```
apt update
```

Now, let’s install bind9 on the server, and set it up so that our server can answer requests for our subdomain.

```
apt install bind9 bind9utils bind9-doc
```

Now that bind is installed, we will have to configure it. Add the content below in **/etc/bind/named.conf.options**:


```
acl "trusted" {
        10.128.10.11;    # ns1 - can be set to localhost
        10.128.20.12;    # ns2
        10.128.100.101;  # host1
        10.128.200.102;  # host2
};

options {
        directory "/var/cache/bind";

        recursion yes;                 # enables resursive queries
        allow-recursion { trusted; };  # allows recursive queries from "trusted" clients
        listen-on { 10.128.10.11; };   # ns1 private IP address - listen on private network only
        allow-transfer { none; };      # disable zone transfers by default

        forwarders {
                8.8.8.8;
                8.8.4.4;
        };
};
```


Now we have to add our zone to named.conf.local, and create the zone-file. Put the following into your **/etc/bind/named.conf.local**:


```
zone "nyc3.example.com" {
    type master;
    file "/etc/bind/zones/db.nyc3.example.com"; # zone file path
    allow-transfer { 10.128.20.12; };           # ns2 private IP address - secondary
};

zone "128.10.in-addr.arpa" {
    type master;
    file "/etc/bind/zones/db.10.128";  # 10.128.0.0/16 subnet
    allow-transfer { 10.128.20.12; };  # ns2 private IP address - secondary
};
```

If there are no errors, we can create our zone-file. To do so we have to create the directory **/etc/bind/zones**.

```
mkdir /etc/bind/zones
```

Then we copy the content of db.local to our file zone.

```
cp /etc/bind/db.local /etc/bind/zones/db.nyc3.example.com
```


This is what my zone-file, **db.nyc3.example.com** looks like:


```
$TTL    604800
@       IN      SOA     ns1.nyc3.example.com. admin.nyc3.example.com. (
                  3     ; Serial
             604800     ; Refresh
              86400     ; Retry
            2419200     ; Expire
             604800 )   ; Negative Cache TTL
;
; name servers - NS records
     IN      NS      ns1.nyc3.example.com.
     IN      NS      ns2.nyc3.example.com.

; name servers - A records
ns1.nyc3.example.com.          IN      A       10.128.10.11
ns2.nyc3.example.com.          IN      A       10.128.20.12

; 10.128.0.0/16 - A records
host1.nyc3.example.com.        IN      A      10.128.100.101
host2.nyc3.example.com.        IN      A      10.128.200.102
```


Now that the zone file is setup and resolving names to IP Adresses a Reverse zone is also required. A Reverse zone allows DNS to convert from an address to a name. To start, create the db.10.128 file:

```
cp /etc/bind/db.127 /etc/bind/zones/db.10.128
```

Next edit /etc/bind/zones/db.10.128 changing it according to the content below:


```
$TTL    604800
@       IN      SOA     nyc3.example.com. admin.nyc3.example.com. (
                              3         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
; name servers
      IN      NS      ns1.nyc3.example.com.
      IN      NS      ns2.nyc3.example.com.

; PTR Records
11.10   IN      PTR     ns1.nyc3.example.com.    ; 10.128.10.11
12.20   IN      PTR     ns2.nyc3.example.com.    ; 10.128.20.12
101.100 IN      PTR     host1.nyc3.example.com.  ; 10.128.100.101
102.200 IN      PTR     host2.nyc3.example.com.  ; 10.128.200.102
```

After creating the reverse zone file restart bind9:

```
systemctl restart bind9
```

We can now check the configuration using check-nameconf.

```
named-checkconf
```

This will check named.conf.options, named.local, named.conf.default-zones, and named.conf, as the three first are included in named.conf.


You can also use the named-checkzone utility that is part of the bind9 package:


```
named-checkzone nyc3.example.com /etc/bind/zones/db.nyc3.example.com
```
and

```
named-checkzone 128.10.in-addr.arpa /etc/bind/zones/db.10.128
```


You should now be able to ping host1<span>.nyc3.example.com and have it resolve to the host configured above. However, we still need to configure the client. To configure Linux as DNS client you need to edit or modify /etc/resolv.conf file. This file defines which name servers to use. 

In Linux and Unix like computer operating systems, the /etc/resolv.conf configuration file contains information that allows a computer connected to the Internet to convert alpha-numeric names into the numeric IP addresses that are required for access to external network resources on the Internet. The process of converting domain names to IP addresses is called "resolving."

The resolv.conf file typically contains the IP addresses of nameservers (DNS name resolvers) that attempt to translate names into addresses for any node available on the network.


To do so, open a terminal for **sta1** and add our ISP nameserver in **/etc/resolv.conf**  as follows:

```
nameserver 10.0.0.5
```

Now, run the ping command as below:

```
ping host1.nyc3.example.com
```

You can do the same with host2<span>.nyc3.example.com:

```
ping host2.nyc3.example.com
```