What is a name server?
A name server is basically just a small service that assigns a name to an IP address. The entire internet is based on name servers. If you enter "google.de" in the address bar of your browser, one of the first steps the browser takes is to ask a name server which IP address is behind this domain. The domain names are therefore only used for us humans because they are easier to read.
Why would you want to install your own name server on a Raspberry Pi?
The answers can be many and varied:
- A local name server reduces access times when surfing, as a name server that can be reached on the Internet is further away.
- A local name server can be shared by all PCs, mobile phones, consoles, etc. in the network. Caching means that a request for "google.de" from one PC is answered much more quickly from the name server's cache on another PC, as the name server already knows the IP for this.
- A local name server offers the possibility of assigning fixed names in one's own network. For example, you can call up a PC with its name instead of its IP address.
- A local name server offers the possibility to add a PTR entry to a local IP address (also called rDNS).
How to install a local name server?
We use a very common name server, bind9. This is easy to install:
sudo apt-get install bind9
How is the name server configured?
We assume that our Raspberry Pi has the following fixed IP address 192.168.15.4 and want to assign ".lan" as domain.
The following 4 files must be adapted:
/etc/bind/db.lan (create new)
BIND data file for domain lan
;
$TTL 604800
@ IN SOA ns.lan. root.localhost. (
2015121701 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.lan.
@ IN A 192.168.15.4
ns IN A 192.168.15.4
localhost IN A 127.0.0.1
fritzbox IN A 192.168.15.1
pc1 IN A 192.168.15.2
pc2 IN A 192.168.15.3
/etc/bind/.db.15.168.192 (create new)
; BIND reverse data file for 178.168.192.in-addr.arpa
;
$TTL 604800
@ IN SOA ns.lan. root.localhost. (
2015121701 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.lan.
4 IN PTR rpi.lan.
1 IN PTR fritzbox.lan.
2 IN PTR pc1.lan.
3 IN PTR pc2.lan.
/etc/bind/named.conf.local
//
// Do any local configuration here
//
// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";
zone "lan" {
type master;
file "/etc/bind/db.lan";
};
zone "15.168.192.in-addr.arpa" {
type master;
notify no;
file "/etc/bind/db.15.168.192";
};
/etc/bind/named.conf.options
options {
directory "/var/cache/bind";
// If there is a firewall between you and nameservers you want
// to talk to, you may need to fix the firewall to allow multiple
// ports to talk. See http://www.kb.cert.org/vuls/id/800113
// If your ISP provided one or more IP addresses for stable
// nameservers, you probably want to use them as forwarders.
// Uncomment the following block, and insert the addresses replacing
// the all-0's placeholder.
forwarders {
8.8.8.8;
8.8.4.4;
};
//========================================================================
// If BIND logs error messages about the root key being expired,
// you will need to update your keys. See https://www.isc.org/bind-keys
//========================================================================
dnssec-validation auto;
auth-nxdomain no; # conform to RFC1035
listen-on-v6 { any; };
};
How is the name server used?
The installation and configuration is now complete. It is important that the name server has a fixed IP, otherwise it cannot be found by other systems.
In order to use the name server, it must be entered in all devices. This can be achieved via fixed entries on the devices or via a DHCP server that distributes the name server IP to all devices.
Leave a comment now