In addition to Yamakaja's answer, this is how you setup a local DNS server.
First, you need a computer you want to run the DNS server on. This can be one of your normal computers (if they run Linux and are on most of the time) or for example a Raspberry Pi. The advantages of such a device are that it's cheap, does not need much power and it's small.
Setting up the DNS server
I decided to set up the DNS server on a Raspberry Pi using dnsmasq
, which is a small DNS server tool, ideal for use in small networks. You could also use bind
, the de facto standard DNS tool, but this is probably a little too mighty for a small home network.
Install dnsmasq
using the package manager, on Debian-based systems (e. g. Raspbian), the command would be
sudo apt-get install dnsmasq
I now assume you already have set up a static IP address allocation (i.e. the IP addresses you mention in your question don't change). If you haven't, dnsmasq
can be also used as a DHCP server, but I haven't done that yet.
dnsmasq
fetches the host names from the /etc/hosts
. Edit this file as follows:
# IP address Host name
192.168.1.1 router
192.168.1.22 printer
The host name router
is now assigned to 192.168.1.1
, printer
to 192.168.1.22
.
Now, you've set up your own DNS server, but the computers in your network don't use it yet. To make them use this server, you have to do one step of preparation:
Find the IP address of your dnsmasq device using ip address
(let's assume it's 192.168.1.42
). Open the /etc/dnsmasq.conf
and append the following lines:
listen-address=127.0.0.1
listen-address=192.168.1.42
This tells dnsmasq
it should listen to requests to it when they are addressed either to 127.0.0.1
(i.e. when itself wants to use its DNS server) or 192.168.1.42
(i.e. when other computers want to use its DNS server).
Using the DNS server
You have to tell each computer in your network it should (also) use 192.168.1.42
as DNS server.
The way you do this depends on your operating system.
You can look this up for your specified operation system on the internet easily (just search "Change DNS server on <OS>", or something like that).
For Windows 7, you could follow this tutorial: https://www.opennicproject.org/configure-your-dns/how-to-change-dns-servers-in-windows-7/.
On my system (Arch Linux), I had to append the following line to /etc/resolvconf.conf
name_servers=192.168.1.42
Note the file you have to use depends to your network manager configuration.
Add the DNS server IP on each computer you want to use your DNS.
You'll probably have to restart the devices if it does not work immediately.
That's it, you're done. You can now access all devices you've entered in /etc/hosts
of the dnsmasq server simply using the host name you've given it.
(Optional) Checking functionality
If you want to check whether the DNS resolve works correctly, install dnsutils
(Linux) on the system that should use your server. Then execute
$ dig router
This should return something like this
; <<>> DiG 9.10.4-P1 <<>> router
;; global options: +cmd
;; Got answer:
...
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;router. IN A
;; ANSWER SECTION:
router. 0 IN A 192.168.1.1
;; Query time: 14 msec
;; SERVER: 192.168.1.42#53(192.168.1.42)
;; WHEN: So Jun 26 10:43:18 CEST 2016
;; MSG SIZE rcvd: 50
It shows you the host name you wanted to resolve, the IP address it got resolved to and the DNS server used. As you see, everything is fine.
(Optional) Specifying a TLD
If you want to access the devices not just with router
or printer
but with router.home
and printer.home
, add the following lines to your /etc/dnsmasq.conf
:
expand-hosts # Tells dnsmasq to add a TLD to each host name
domain=home # The TLD
You may need to restart again.
Sources / further reading
About dnsmasq
:
About bind
(if you're interested in it):
2
Note that some routers do this themselves, for example, if you use Asus routers, and you go to http://router.asus.com it will open the router's config page. Other routers have similar "tricks" to do similar to this as well.
– acejavelin – 2016-06-25T14:07:24.950Nope, I do not use asus router. The question is actually a bit more general... Not only I would like to access router without the IP, but other devices attached to network too. I will add an edit. – sanjihan – 2016-06-25T14:13:30.750
2My point was some routers have this capability built in since they often act as a DNS caching server, since you didn't state what router you are using I left it open to "other routers have similar tricks to do this as well" – acejavelin – 2016-06-25T14:16:11.000
1yes yes, I got that and thank you! router was just an example. imagine running printer or raspberry PI or internet controlled ventilation system on the LAN too. – sanjihan – 2016-06-25T14:19:47.250
@sanjihan I think you will need to disclose the make and model of your router or else tell what you are using for DNS for someone to give you instructions further on the configurations you may be able to complete for this task. So to recap,
1.)
make and model of your router device or2.)
what are you using exactly for DNS (e.g. Windows DNS, built-in router functionality, etc.) – Pimp Juice IT – 2016-06-25T14:30:14.217This question is very vague, which is why I didn't give an answer... the line "I guess the goal is to have a local DNS server" really leaves the answers open. Some routers can do this, servers, and other network appliances, it depends a lot on your setup... for example, if your router can run OpenWRT or DD-WRT, you could certainly build any host entries you wish for the LAN and everyone could use them. The answer by Yakamaja only addresses your one PC. – acejavelin – 2016-06-25T15:06:05.240