1

I'm trying to create a local DNS on my computer so I can access it locally with a DNS address instead of an IP. The first thing that I did was to configure my hostname on the files /etc/hosts and /etc/init.d/hostname.sh.

$ sudo vi /etc/hosts

127.0.0.1   localhost
127.0.1.1   mynewhostname 

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

$ sudo vi /etc/hostname

mynewhostname

Then I installed the avahi-daemon as a DNS server:

sudo apt-get install avahi-daemon

After rebooting the system I can access the local DNS mynewhostname.local only from localhost (only from my own computer), other computers on the local network can only access my computer with the IP address and not with the DNS. Does anyone know why that happens? Or what would be a different approach to create a local DNS that's seen from all my local network?

  • have you tried adding machine-network-ip myhostname in /etc/hosts in addition to 127.0.0.1 myhostname? – ptetteh227 Nov 14 '18 at 10:27
  • @ptetteh227 I've tried that just now and rebooted the computer... But the DNS is still only available from my computer. – Rafael Muynarsk Nov 14 '18 at 10:59
  • avoid using .local and use say .home. how many computers form the network?. If there are few computers you could manually enter into each machine's hosts file the machine-network-ip hostname.home of the other pc on the network. but if there are lots of computers consider dnsmasq. – ptetteh227 Nov 14 '18 at 16:15
  • Keep in mind there isn't a DNS 'server' running open to the world on your computer by default. Avahi-Daemon is typically used for local mDNS things not network-wide normal DNS lookups. – Thomas Ward Nov 16 '18 at 15:50
2

the .local domain is used by avahi for its special services and i haven't been able to get other computers to use it over the network except when using mDNS applications.

You could run a proper dns server such as dnsmasq to achieve dns resolving of hostnames to ip addresses over a small network in addition to the /etc/hosts file.

To setup dnsmasq as your domain resolver choose another domain instead of .local. for example say .home or .house or anything other than .local. This domain works only on the network.

install dnsmasq onto the central "server". In this case your computer:

sudo apt install dnsmasq

Then setup dnsmasq:

sudo nano /etc/dnsmasq.conf

create a static file:

sudo rm /etc/resolv.conf
echo 'nameserver 127.0.0.1' | sudo tee /etc/resolv.conf

stop any instances of the services:

sudo killall dnsmasq
sudo service systemd-resolved stop

edit the dnsmasq conf:

sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
sudo nano /etc/dnsmasq.conf

and add the following

#Beginning of configuration
domain-needed
bogus-priv
no-resolv
interface=wlp2s0
#Use below nameservers to reach the internet
server=8.8.8.8
server=8.8.4.4
#use below line to point to the router address.
#dhcp-option=option:router,192.168.0.50
#use two lines below to resolve local domains (eg .home)
local=/home/
domain=home

then restart dnsmasq:

sudo service dnsmasq restart

if you have a firewall remember to open ports 53, 67/udp, 68/udp, in the firewall

then edit the hosts file:

sudo nano /etc/hosts

and paste into it

. . .
127.0.0.1       localhost localhost.home
. . . 
127.0.0.1 www.mysite1.home
127.0.0.1 mysite1.home
192.168.0.50 mysite1.home
192.168.0.50 mysite2.home

where 192.168.0.50 is the servers computer ip on the network and mysite.home are services that are listening on the server computer*

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.