2

I am currently trying to set up an ad-hoc network for passing notes while I'm in class. The idea is to run a chat server on my laptop (I'm using prosody, that's up and running), so we can share information.

I have also set up a BIND DNS server on my laptop so my friends can just log in using my hostname instead of manually setting up their accounts to point to my IP address.

I am having two seperate issues in this regard. 1) I can't really figure out how to make their computers use my laptop as their DNS server. Should I install a DHCP server too? 2) My computer refuses to use my own DNS server. I think it's because of the dnsmasq that networkmanager runs. I can work around it by editing /etc/hosts, but I do want to use my server locally.

I am running 16.04.

For future generations: in regards to number 2, i just went to NetworkManagers config file and removes the line including dnsmasq. Otherwise dnsmasq refuses to use a dns server on localhost.

In addition, i set up my ad-hoc network to do manual ip address for me, because automatic didn't work for me at all. So i used NetworkManager to give me a static IP and then all my clients use the DHCP from dnsmasq just fine.

  • i think you can make it work woth hostpad and dnsmasq like they do in this tutorial – bistoco Jun 1 '17 at 17:19
  • 1) it's hostapd, and 2) i'm using an ad-hoc network b/c my card doesn't support master mode – A Gold Man Jun 15 '17 at 20:39
1

You can do this with dnsmasq.

Dnsmasq accepts DNS queries and either answers them from a small, local, cache or forwards them to a real, recursive, DNS server. It loads the contents of /etc/hosts so that local hostnames which do not appear in the global DNS can be resolved and also answers DNS queries for DHCP configured hosts.

Installing dnsmasq is just a case of using apt-get.

sudo apt-get install dnsmasq

Setup dnsmasq as DNS DHCP

Looking at the file /etc/dnsmasq.conf first. The lines are listed are those that I changed from their defaults. Just uncomment and amend them as necessary. (Remove the ‘#’ from the beginning of the line).

sudo nano /etc/dnsmasq.conf
domain-needed
bogus-priv
no-resolv
no-poll
server=/example.com/192.168.0.5
server=8.8.8.8
server=208.67.220.220
local=/example.com/
address=/doubleclick.net/127.0.0.1
no-hosts
addn-hosts=/etc/dnsmasq_static_hosts.conf
expand-hosts
domain=example.com
dhcp-range=192.168.0.20,192.168.0.50,72h  
dhcp-host=mylaptop,192.168.0.199,36h
dhcp-option=option:router,192.168.0.1
dhcp-option=option:ntp-server,192.168.0.5
dhcp-option=19,0 # ip-forwarding off
dhcp-option=44,192.168.0.5 # set netbios-over-TCP/IP aka WINS
dhcp-option=45,192.168.0.5 # netbios datagram distribution server
dhcp-option=46,8           # netbios node type

What these lines will do for you.

  • domain-needed This tells dnsmasq to never pass short names to the upstream DNS servers. If the name is not in the local /etc/hosts file then “not found” will be returned.

  • bogus-priv All reverse IP (192.168.x.x) lookups that are not found in /etc/hosts will be returned as “no such domain” and not forwarded to the upstream servers.

  • no-resolv Do not read resolv.conf to find the servers where to lookup dns.

  • no-poll Do not poll resolv.conf for changes

  • server=8.8.8.8 Set one or more DNS servers to use when addresses are not local. These are open DNS servers.

  • local=/example.com/ Our local domain, queries in these domains are answered from /etc/hosts or the static-hosts files.

  • address=/doubleclick.net/127.0.0.1 Use this force an address for the specified domains. e.g to block adverts force doubleclck.net to localhost

  • no-hosts This options stops dnsmasq using the local /etc/hosts file as a source for lookups .

  • addn-hosts=/etc/dnsmasq_static_hosts.conf Force dnsmasq to use this file for lookups. It is in the same format as /etc/hosts.

  • expand_hosts So we can see our local hosts via our home domain without having to repeatedly specify the domain in our /etc/hosts file.

  • domain This is your local domain name. It will tell the DHCP server which host to give out IP addresses for.

  • dhcp-range This is the range of IPs that DHCP will serve: 192.168.0.20 to 192.168.0.50, with a lease time of 72 hours. The lease time is how long that IP will be linked to a host.

  • dhcp-host=mylaptop,192.168.0.199,36h Any machine saying they are hostname = ‘mylaptop’ gets this IP address

  • dhcp-option=option:router,192.168.0.1 When a host is requesting an IP address via DHCP also tell it the gateway to use.

  • dhcp-option=option:ntp-server,192.168.0.5 When a host is requesting an IP address via DHCP also tell it the NTP to use.

In the file /etc/dnsmasq_static_hosts.conf you can add a list of local machines with static IP addresses in the same format as the hosts file. It is also an easy way of creating aliases or CNAME records.

192.168.0.8  mail mail.example.com
192.168.0.9  smtp smtp.example.com
192.168.0.120 mythtvbox mythtvbox.example.com

Starting and stopping the service

sudo service dnsmasq start
sudo service dnsmasq stop
sudo service dnsmasq restart

And one more thing to do. Terminate all other DHCP servers on local network. Your DHCP/DNS server must be only one.

  • Sounds great. Does this also allow my own computer to do lookups through the full instance of dnsmasq, or will the one owned by networkmanager continue jacking my requests? – A Gold Man Jun 1 '17 at 20:22
  • Yes. If dnsmasq can not resolve locali will redirect request to 8.8.8.8. – 2707974 Jun 1 '17 at 20:26
  • There's a typo in your posted config file, it should say dhcp-host, not hcp – A Gold Man Jun 2 '17 at 11:30
  • Yes you are right. – 2707974 Jun 2 '17 at 11:33
  • Do you have a word on what I should set in NetworkManager for my network to make it use my server for dhcp and dns? – A Gold Man Jun 3 '17 at 18:38
0

Setting up a local DNS server seems like a lot of work and overkill for your issue. Ditto for creating a DHCP server. Both approaches would probably work but how much time do you want to invest in this exercise?

I'd think the easiest and cleanest way to do what you want is to have each user add a line to their local /etc/host file:

hostname IP_Address

Then, after the exercise is over, that line could be removed or commented out.

Based on your feedback it sounds like building a private LAN that you completely control, with your own DHCP and DNS server is the way to go. Obviously no need to spell out how to do that here since it is a complicated process that you seem to be sell capable of executing.

  • Eh, my friends are running windows, and are very non-technical. Not an option so much. – A Gold Man Jun 1 '17 at 19:39
  • In that case you should probably take total control over the environment and employ a DHCP and DNS server for your own little LAN. – jones0610 Jun 1 '17 at 19:43

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.