I have configured my own DNS server and want to make it possible for everyone on the subnet to lookup each other.
How do I do that?
First, you need a DNS server. BIND is example of widely used and standard server.
Below is an example for:
local.example.com
192.168.0.0
255.255.255.0
(24 bits)For server:
ns1
192.168.0.1
And for 2 external DNS servers of:
Change those values accordingly to fit your network structure.
sudo apt-get install bind9
In BINDs configuration file of /etc/named.conf.local
add config for name queries (name to IP number):
zone "local.example.com" {
type master;
file "/etc/bind/db.local.example.com";
allow-query { 192.168.0.0.0/24; 127.0.0.1; };
};
And for reverse queries (IP numbers to names):
zone "0.168.192.in-addr.arpa" {
type master;
file "/etc/bind/db.192.168.0";
allow-query { 192.168.0.0/24; 127.0.0.1; };
};
Create two configuration files for your network. In /etc/bind/db.local.example.com
, put:
$TTL 604800
@ IN SOA local.example.com. hostmaster.example.com. (
1503281 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns1.local.example.com.
ns1 IN A 192.168.0.1
;
; Local computers
comp1 IN A 192.168.0.101
comp2 IN A 192.168.0.102
comp3 IN A 192.168.0.103
In /etc/bind/db.192.168.0
put:
$TTL 604800
@ IN SOA v1.local.example.com. hostmaster.example.com. (
1503281 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns1.
1 IN PTR ns1.local.example.com.
; Local computers
101 IN PTR comp1.local.example.com.
102 IN PTR comp2.local.example.com.
103 IN PTR comp3.local.example.com.
Note the Serial
parameter: It may contain any number, and it should be changed every time you make changes to your config file. In this example it is constructed from date and unique number (YYMMDDN).
Your server needs to resolve other queries, configure external DNS servers in /etc/bind/named.conf.options
as "forwarders":
options {
forwarders {
1.2.3.4;
1.2.3.5;
};
[...]
}
You can reload configuration by:
sudo service bind9 reload
Check /var/log/syslog
if there is no errors loading your new configs.
You should now be able to query your DNS server from localhost
and from clients of 192.168.0.0/24
network. They need to be configured to use this server (192.168.0.1
) and this domainname (local.example.com
) - eg. with DHCP configuration or statically in /etc/network/interfaces
, like this:
auto eth0
iface eth0 inet static
address 192.168.0.101
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 192.168.0.1
dns-search local.example.com
To test your DNS on client machine (before switching permanently) you can try:
host comp1 192.168.0.1
localhost
is needed if you want to use server by its own, you need this for at least testing purposes. If you have all computers named with one pattern you could use DDNS with DHCP, try to search web and questions related to it and/or create new question if you need.