8

So I'm using dnsmasq for my local dev environment & I need to set it up to use multiple domains ex. (.dev, .test, .somethingelse) how can this be done?

currently It's working with .dev only

this is how my dnsmasq.conf looks like

address=/dev/127.0.0.1
listen-address=127.0.0.1
John
  • 91
  • 1
  • 1
  • 3

5 Answers5

7

For every (sub)domain you want to server locally, add the following entry to your dnsmasq.conf:

address=/.domain/127.0.0.1

Now let your OS know, that you want to redirect requests to this domain to your local dnsmasq nameserver. Do this by creating a file "domain" in "/etc/resolvers".

/etc/resolvers/domain has the following content:

nameserver 127.0.0.1

More info about the resolver thing.

mattes
  • 8,936
  • 5
  • 48
  • 73
  • that doesn't do what the OP actually requested. Your solution maps everything in .domain to localhost. If you run dnsmasq on localhost, that works, but if you are in a virtualized environment and have .dev your localhost, .test your test VM and .build your build VM, all 3 having different IP address,. then your solution doens't work, even though the request is the same. – ciuly Oct 17 '16 at 07:20
  • The initial question doesn't mention a VM setup. – mattes Oct 17 '16 at 22:07
  • It doesn't have to. You can simply have a regular LAN with the same number of hosts. I have 2 PCs, 1 laptop, 1 printer and 2 phones physical devices on my LAN. Not at all uncommon nowadays. Problem still stands. – ciuly Oct 18 '16 at 05:14
3

A more generic answer would be to have in /etc/dnsmasq.conf

local=/mylan/ 

and in /etc/hosts

192.168.1.3 dev dev.mylan 
192.168.1.3 test test.mylan 
192.168.1.4 build build.mylan 

as per https://serverfault.com/questions/136332/setting-up-dnsmasq-for-a-local-network

(note that the solution comes in aid for the DHCP settings where you cannot have 2 hosts on the same IP, as the OP liked)

Community
  • 1
  • 1
ciuly
  • 532
  • 5
  • 13
  • 1
    however, I'm looking for something along this line: http://osdir.com/ml/network.dns.dnsmasq.general/2008-06/msg00024.html to be able to have dxe5.dev d10.dev and dxe5.test with d10.test and same for build. – ciuly Oct 18 '16 at 05:27
3

for me, address=/.aaa.com/.bbb.com/127.0.0.1 do the trick.

Jayy Lucas
  • 39
  • 2
1

.dev is not recommended to be used in development as Google actually owns that top level domain.

You might want to use reserved TLDs, like .localhost, for development.

Good article about the same problem: https://web.archive.org/web/20180722223228/https://iyware.com/dont-use-dev-for-development/

Dan Loewenherz
  • 10,879
  • 7
  • 50
  • 81
arkki
  • 104
  • 6
0

In your /usr/local/etc/dnsmasq.conf add:

address=/dev/test/127.0.0.1

And then create files: /etc/resolver/dev and /etc/resolver/test. Both with content:

nameserver 127.0.0.1

From now all xyz.dev and xyz.test domains will point to 127.0.0.1.

dudzio
  • 222
  • 1
  • 3
  • 13