dnsmasq interview questions
Top dnsmasq frequently asked interview questions
I have a device that is already mapped to domain.tld
. I now want to create a wildcard for all subdomains *.domain.tld
so that they are mapped to the ip of domain.tld
, too.
How do I do this with dnsmasq
?
Source: (StackOverflow)
In the command line of Android, there are dnsmasq commands. But where are all the config files (dnsmasq.conf, dnsmasq.pid...)?
As far as I try is creating my own configuration files and using the following command:
dnsmasq --conf-file=the/location/of/my/file
It says:
dnsmasq: failed to open pidfile /var/run/dnsmasq.pid: No such file or directory
When I create pid file it says:
dnsmasq: failed to open pidfile dnsmasq.pid: Read-only file system
Any recommendations on how I can control my dnsmasq (DHCP, DNS server)?
Source: (StackOverflow)
Does dnsmasq support overlapping address space. For example, 2 (or more than 2) subnets with same address space. If yes, how does that work?
Source: (StackOverflow)
I am trying to enable wildcard subdomain using dnsmasq. I followed the following link for that.
https://coderwall.com/p/6dgpsw
I am adding dns nameserver by editing /etc/dhcp/dhclient.conf with the line prepend domain-name-servers 127.0.0.1;
I am using ubuntu 12.04 with wifi connection.
But this is not working for me. can anyone please help me out.
Thanks in advance.
Source: (StackOverflow)
I'm really struggling with dnsmasq setup.
My dnsmasq config contains (amongst other things), the following
address=/local/127.0.0.1
listen-address=127.0.0.1
domain=local
My network manager conf and resolve conf are definitely including 127.0.0.1 as the first nameserver.
If I run
dig mysite.local
I get
; <<>> DiG 9.8.1-P1 <<>> mysite.local
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 61359
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;mysite.local. IN A
;; ANSWER SECTION:
mysite.local. 0 IN A 127.0.0.1
;; Query time: 1 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Tue Dec 17 10:33:40 2013
;; MSG SIZE rcvd: 46
(Yes, mysite.local is an apache vhost listening on port 80).
However, if I browse or wget to mysite.local, I get:
--2013-12-17 10:35:49-- http://mysite.local/
Resolving mysite.local (mysite.local)... failed: Name or service not known.
wget: unable to resolve host address `mysite.local'
Running Ubuntu 12.04. Tailing the output of syslog with dnsmasq debugging on indicates that neither wget or a browser ever queries dnsmasq for the .local domains, but running dig on a .local domain works fine.
Any thoughts much appreciated.
Source: (StackOverflow)
I have a situation where I want a bash script to replace an entire lines in a dnsmasq.conf
By default, lines are :
listen-address=192.168.42.1
dhcp-range=192.168.42.1,192.168.42.253,255.255.255.0,192.168.42.255,24h
dhcp-option=option:router,192.168.42.1
I implement :
new_ip=$1
broadcast=$2
base_ip=`echo $new_ip | cut -d"." -f1-3`
sed -i 's/^listen-address.*/listen-address=$new_ip/' /etc/dnsmasq.conf
sed -i 's/^dhcp-range.*/dhcp-range=$base_ip.1,$base_ip.254,255.255.255.0,$broadcast,24h/' /etc/dnsmasq.conf
sed -i 's/^dhcp-option.*/dhcp-option=option:router,$new_ip/' /etc/dnsmasq.conf
I am calling the bash as ./test.sh 172.24.239.40 172.24.239.255 and I obtain the following lines :
listen-address=$new_ip
dhcp-range=$base_ip.1,$base_ip.254,255.255.255.0,$broadcast,24h
dhcp-option=option:router,$new_ip
Is it possible to dissociate the parameter from text in sed command lines ?
Source: (StackOverflow)
I have a Pi that runs hostapd and dhcpd on arch linux to create it's own land with the Pi's (routers) IP being 10.0.0.1
. This uses the wlan0 interface and it only serves as a standalone router running a web server.
Once I connect to the Pi, I use 10.0.0.1
to display the web pages, but I want to use a hostname such as firepi
. I have tried using dnsmasq, but I haven't been successful. Any help would be greatly appreciated especially if you can give me some detailed examples as I am a novice.
The purpose of this system is that I have created a web app that you can use to ignite fireworks over WiFi at a safe distance. I would just like the convenience of using a hostname instead of the IP address.
I must add that I will more than likely be using an iPhone to connect to the server, should this affect anything.
Source: (StackOverflow)
I use dnsmasq to resolve DNS queries on my home network. Unfortunately, if a domain name is not known, it will append my own domain name to the request which means that I always end up viewing my own site in a browser.
For example, if I enter http://dlksfhoiahdsfiuhsdf.com in a browser, I end up viewing my own site with that URL. If I try something like:
host dlksfhoiahdsfiuhsdf.com
Instead of the expected:
Host dlksfhoiahdsfiuhsdf.com not found: 3(NXDOMAIN)
I get this:
dlksfhoiahdsfiuhsdf.com.mydomainname.com has address W.X.Y.Z.
Clearly, dnsmasq is appending my domain name to impossible name requests in an effort to resolve them, but I'd rather see the not found error instead.
I've tried playing with the expand-hosts and domain configuration settings, but to no avail. Is there anything else I can try?
Source: (StackOverflow)
I'm doing some mobile development on my iMac running snow-leopard and I wish to be able to access the virtual hosts configured on the iMac on the mobile devices on my LAN. So I've installed Dnsmasq through Macports. I think I've got it set up correctly and I believe it's running, but I just get a 'server not found' error if I try to access one of the virtual hosts from my iPhone.
So, my iMac has the IP 192.168.0.111 this is where Apache lives and the host example.dev
resolves properly to the dev website on the iMac. If I run the iOS simulator on the iMac, this also works. The iMac is connected to the LAN over ethernet, the iphone over Wifi, which cannot see example.dev
despite my putting the iMac into the iPhone's WiFi's DNS settings.
dnsmasq appears to be running:
ps aux | grep dnsmasq
dm 913 0.0 0.0 2435120 556 s000 R+ 12:17pm 0:00.00 grep dnsmasq
nobody 895 0.0 0.0 2435060 600 ?? Ss 12:09pm 0:00.01 /opt/local/sbin/dnsmasq -k
My /opt/local/etc/dnsmasq.conf is below:
#interface=en0
resolv-file=/etc/resolv.dnsmasq.conf
address=/.dev/127.0.0.1
I've tried it with and without the interface
line to no effect, I've restarted dnsmasq using sudo port unload dnsmasq
and then sudo port load dnsmasq
to no difference.
I've tried pinging any arbitrary host, some false, some correct (e.g. pwoefojpo.dev / foo.dev / example.dev ) from the iMac and I'd expect all of these to ping 127.0.0.1 but only the valid hosts (as in /etc/hosts
) actually allow me to ping 127.0.0.1.
The LAN is a simple Virgin Media Superhub, which contains a number of devices over Wifi and Cat5.
If anyone can shed any light, I'm grateful.
Source: (StackOverflow)
I know the following rules in my dnsmasq.conf file will redirect all requests with a ".dev" top level domain back to my local machine.
listen-address=127.0.0.1
address=/.dev/127.0.0.1
The problem I am having is that I want to set up an alias such that "myserver" gets directed to a real address out on the net "myserver.example.com".
Before installing dnsmasq, I used an entry in my hosts file to accomplish the task, something like...
555.555.555.555 myserver
This allowed me to simply type something like:
ssh myserver
to connect to my remote server.
The problem, this no longer works since I installed dnsmasq.
I have tried to configure dnsmasq to direct these requests to the proper server but so far I have had no luck. A few things I have tried unsuccessfully include...
1) using the "local" configuration directive in the following manner:
local=/myserver/
It was my understanding that this would force dnsmasq to use the hosts file for looking up the alias, it did not.
2) I tried defining an address entry in the configuration:
address=/myserver/555.555.555.555
Maybe it is a syntax issue, but this did not work either.
3) I tried adjusting the hosts file on the computer to alias the full host name like so...
myserver.example.com myserver
This like the above, did not work either.
Anyone have any suggestions on what to try next?
Thanks in advance.
Source: (StackOverflow)
I have a few Ubuntu VMs. One with a DHCP server and the rest would be clients.
On the DHCP server,
- I created a Linux bridge (br-1)
- Assigned static IP to eth1.
- Attached the interface eth1 to bridge br-1.
- Ran dnsmasq on eth1.
Then from a client I ran 'dhclient -v eth1' in the hope to get an IP. But it does not work. However, if I just move the eth1 out of the bridge and try a dhclient from one of my client VMs the client gets an IP assigned properly. Am not sure why. Can anyone please point out what am I missing here ?
I also tried the following --
- Assigning the bridge (br-1) a static IP in the subnet range as eth1.
- Adding default gateway for bridge IP.
- Adding default gateway for eth1 IP.
- Disabling IP tables fully.
None of the above helped. I have to use the Linux bridge as it is part of a larger requirement.
Any pointers would be of great help.
Thanks !
Source: (StackOverflow)
I like the idea of running my own nameserver (BIND) but if I do that, I can't get the benefit of blocking nasty websites by putting them in /etc/hosts
DNSMasq is able to refer to /etc/hosts but rather than specifying an "upstream" dnsserver, I'd like it to be able to use BIND on the same machine. However, they both need to use the same port.
Is this possible? I couldn't find anything about this in regular searching.
I suppose an alternative would be to run another Linux instance in a VM and run DNSMasq there (say) but I'd like to not have to do this.
Source: (StackOverflow)
Just installed docker 1.10.1 today using their installation guide. However, none of my containers can access the internet unless I used --net=host
in the docker run
command. I have tried various workarounds from these posts:
- http://odino.org/cannot-connect-to-the-internet-from-your-docker-containers/
- My docker container has no internet
- I can't get Docker containers to access the internet?
- Docker container cannot access internet
Nothing has worked so far save for adding --net=host
to the run command, but I can't build images from a Dockerfile because I can't use --net=host
with the build
command.
I ran docker network inspect bridge
to checkout the settings for the docker network bridge and noticed that it uses (almost) the same subnet and gateway as my work VPN. Could that be causing an issue? That could also explain why when I connect to my work VPN some of the sites do not load.
This is the result from docker network inspect bridge
:
[
{
"Name": "bridge",
"Id": "6d603ebd1c437d0d1f02be8406cf362f7f36d33168e42b9883891bae99834fa9",
"Scope": "local",
"Driver": "bridge",
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.17.0.0/16",
"Gateway": "172.17.0.1"
}
]
},
"Containers": {},
"Options": {
"com.docker.network.bridge.default_bridge": "true",
"com.docker.network.bridge.enable_icc": "true",
"com.docker.network.bridge.enable_ip_masquerade": "true",
"com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
"com.docker.network.bridge.name": "docker0",
"com.docker.network.driver.mtu": "1500"
}
}
]
This is ifconfig:
docker0 Link encap:Ethernet HWaddr 02:42:9a:29:4a:c2
inet addr:172.17.0.1 Bcast:0.0.0.0 Mask:255.255.0.0
inet6 addr: fe80::42:9aff:fe29:4ac2/64 Scope:Link
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:36 errors:0 dropped:0 overruns:0 frame:0
TX packets:55 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2080 (2.0 KB) TX bytes:8498 (8.4 KB)
enx00e09f0004bd Link encap:Ethernet HWaddr 00:e0:9f:00:04:bd
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:70948 errors:0 dropped:1 overruns:0 frame:0
TX packets:14839 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:14270948 (14.2 MB) TX bytes:3460691 (3.4 MB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:3407 errors:0 dropped:0 overruns:0 frame:0
TX packets:3407 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:326405 (326.4 KB) TX bytes:326405 (326.4 KB)
tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:172.17.62.55 P-t-P:172.17.62.55 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1406 Metric:1
RX packets:18 errors:0 dropped:0 overruns:0 frame:0
TX packets:21 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:1773 (1.7 KB) TX bytes:1466 (1.4 KB)
wlp6s0 Link encap:Ethernet HWaddr cc:3d:82:1a:1e:1d
inet addr:10.250.9.73 Bcast:10.250.9.255 Mask:255.255.254.0
inet6 addr: fe80::ce3d:82ff:fe1a:1e1d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4381 errors:0 dropped:0 overruns:0 frame:0
TX packets:4398 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2246805 (2.2 MB) TX bytes:835572 (835.5 KB)
Source: (StackOverflow)
I've got a setup like this:
ADSL router able to change its DNS settings.
3 PCs (windows) and a laptop converted into a local server (Debian 7.3) all connected to that router.
my goal: pass all DNS traffic through the local laptop server, so i can handle wildcard local domains like lets say "*.talibek.home"
the idea is simple, setup a DNS server so I don't need to edit each one PCshosts file to resolve a apache2 on the server.
i thought i can install a dnsmasq on the server pointing catching all the requests i want, and letting through all other requests like this:
PC looks for google.com -> ADSL ROUTER asks local DNS server (Debian 7.3) for google.pl from PC -> local server asks 8.8.8.8 or 8.8.4.4 for the domain and and sends it back to the router witch sends it back to PC.
DHCP is handled by the router, not the server.
Is that even possible without connecting my PCs to the server directly?
Because I'm getting strange things like, server not able to connect to any IP when setting up DNS to it on router etc. (dnsmasq is not using router as nameserver)
configs and info:
root@debian:~# nslookup google.pl
;; connection timed out; no servers could be reached
root@debian:~# nslookup google.pl 192.168.1.14
;; connection timed out; no servers could be reached
syslog
Feb 9 18:45:04 debian dnsmasq[3561]: opcje kompilacji: IPv6 GNU-getopt DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack
Feb 9 18:45:04 debian dnsmasq[3561]: czytanie /etc/resolv.dnsmasq
Feb 9 18:45:04 debian dnsmasq[3561]: używam serwera nazw 8.8.4.4#53
Feb 9 18:45:04 debian dnsmasq[3561]: używam serwera nazw 8.8.8.8#53
Feb 9 18:45:04 debian dnsmasq[3561]: wczytałem /etc/hosts - 5 adresów
Feb 9 18:45:46 debian dnsmasq[3561]: query[A] google.pl from 192.168.1.14
Feb 9 18:45:46 debian dnsmasq[3561]: forwarded google.pl to 8.8.8.8
Feb 9 18:45:46 debian dnsmasq[3561]: forwarded google.pl to 8.8.4.4
Feb 9 18:45:51 debian dnsmasq[3561]: query[A] google.pl from 192.168.1.14
Feb 9 18:45:51 debian dnsmasq[3561]: forwarded google.pl to 8.8.8.8
Feb 9 18:45:51 debian dnsmasq[3561]: forwarded google.pl to 8.8.4.4
Feb 9 18:45:56 debian dnsmasq[3561]: query[A] google.pl from 192.168.1.14
Feb 9 18:45:56 debian dnsmasq[3561]: forwarded google.pl to 8.8.8.8
Feb 9 18:45:56 debian dnsmasq[3561]: forwarded google.pl to 8.8.4.4
/etc/dnsmasq.conf
dhcp-option=3,192.168.1.1
address=/knobik.pl/192.168.1.14
resolv-file=/etc/resolv.dnsmasq
log-queries
mx-host=knobik.pl,mail.knobik.pl,10
/etc/resolv.dnsmasq
nameserver 8.8.8.8 #194.204.159.1
nameserver 8.8.4.4 #194.204.152.34
resolv.conf
domain home
search home
nameserver 192.168.1.1
router dns setup:
dns1: 192.168.1.14 (my server static ip)
dns2. 192.168.1.14 (my server static ip)
It looks like setting up the router DNS settings, I'm not able to connect to any other IP except my local network in my server. Any other PC can connect to any IP becausez the router is not sending DNS IP with the DHCP data.
netstat -nr
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 wlan0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan0
EDIT:
Thanks to you guys I can post this fix here
setup static DNS for the server, IP above DHCP range, manually set
/etc/resolv.conf to nameserver 127.0.0.1 and then setup the router
DNS to the new server IP.
now all my DNS goes through the server and I'm able to route it as
desired.
Thank you
Source: (StackOverflow)
I am trying to generate a temporary hosts file, which is based on a DNS log provided by dnsmasq. I have got it mostly working, however I am having a problem with CNAMEs. I will show what I have achieved so far.
There are 3 types of responses in the log which I need to obtain. The simplest is very easy to extract from the log, eg
Jun 20 14:27:59 dnsmasq[2551]: reply stackoverflow.com is 64.34.119.12
This can be output to "64.34.119.12 stackoverflow.com" using
grep reply /tmp/dnslog | grep -v 'NXDOMAIN\|NODATA' | awk '{print $8 " " $6}'
The other type of log concerns CNAMEs, here is one example;
Jun 20 14:42:11 dnsmasq[2551]: reply www.videolan.org is <CNAME>
Jun 20 14:42:11 dnsmasq[2551]: reply ganesh.videolan.org is 88.191.250.2
This can be output to "88.191.250.2 ganesh.videolan.org www.videolan.org" using
grep reply /tmp/dnslog | grep -v 'NXDOMAIN\|NODATA' | awk '{print $8 "\t" $6}' | awk '/CNAME/ {name=$2; getline ; print $0 " " 'name'}'
However this method does not work for the following type of log, where there are multiple CNAMEs
Jun 20 15:00:42 dnsmasq[2551]: reply en.wikipedia.org is <CNAME>
Jun 20 15:00:42 dnsmasq[2551]: reply wikipedia-lb.wikimedia.org is <CNAME>
Jun 20 15:00:42 dnsmasq[2551]: reply wikipedia-lb.esams.wikimedia.org is 91.198.174.225
The previous command gives the following result
<CNAME> wikipedia-lb.wikimedia.org en.wikipedia.org
By using the first command mentioned along with the second, wikipedia-lb.esams.wikimedia.org is associated with 91.198.174.225, however wikipedia-lb.wikimedia.org is not associated with wikipedia-lb.esams.wikimedia.org. The ideal result should be the following
91.198.174.225 wikipedia-lb.esams.wikimedia.org wikipedia-lb.wikimedia.org en.wikipedia.org
To remedy this problem, I believe the file would need to be read backwards, however would doing this not mess up the getline part of awk, to append to the next line?
Ideally, I would like to combine both types of log into a command which would then output everything, rather than having to run both scripts separately. Can anyone assist in mending the awk command to do this?
Here is a sample of "grep reply /var/dnslog", and the desired hosts file to be output. There are other issues that are secondary at the moment. These are highlighted in the desired hosts output.
Jun 20 15:28:21 dnsmasq[2551]: reply photos-a.ak.fbcdn.net is <CNAME>
Jun 20 15:28:21 dnsmasq[2551]: reply photos-a.ak.facebook.com.edgesuite.net is <CNAME>
Jun 20 15:28:21 dnsmasq[2551]: reply a995.dspmm1.akamai.net is 213.200.108.25
Jun 20 15:28:21 dnsmasq[2551]: reply a995.dspmm1.akamai.net is 213.200.108.48
Jun 20 15:28:21 dnsmasq[2551]: reply a995.dspmm1.akamai.net is 213.200.108.64
Jun 20 15:28:21 dnsmasq[2551]: reply a995.dspmm1.akamai.net is 213.200.108.9
Jun 20 15:28:21 dnsmasq[2551]: reply a995.dspmm1.akamai.net is 213.200.108.26
Jun 20 15:28:21 dnsmasq[2551]: reply a995.dspmm1.akamai.net is 213.200.108.51
Jun 20 15:28:21 dnsmasq[2551]: reply a995.dspmm1.akamai.net is 213.200.108.8
Jun 20 15:28:21 dnsmasq[2551]: reply a995.dspmm1.akamai.net is 213.200.108.50
Jun 20 15:28:21 dnsmasq[2551]: reply a995.dspmm1.akamai.net is 213.200.108.65
Jun 20 15:28:22 dnsmasq[2551]: reply stackoverflow.com is 64.34.119.12
Jun 20 15:29:41 dnsmasq[2551]: reply www.wikipedia.org is <CNAME>
Jun 20 15:29:41 dnsmasq[2551]: reply wikipedia-lb.wikimedia.org is <CNAME>
Jun 20 15:29:41 dnsmasq[2551]: reply wikipedia-lb.esams.wikimedia.org is 91.198.174.225
Jun 20 15:29:42 dnsmasq[2551]: reply en.wikipedia.org is <CNAME>
Jun 20 15:29:42 dnsmasq[2551]: reply wikipedia-lb.wikimedia.org is <CNAME>
Jun 20 15:29:42 dnsmasq[2551]: reply wikipedia-lb.esams.wikimedia.org is 91.198.174.225
Jun 20 15:29:42 dnsmasq[2551]: reply ja.wikipedia.org is <CNAME>
Jun 20 15:29:42 dnsmasq[2551]: reply wikipedia-lb.wikimedia.org is <CNAME>
Jun 20 15:29:42 dnsmasq[2551]: reply wikipedia-lb.esams.wikimedia.org is 91.198.174.225
hosts file
213.200.108.26 a995.dspmm1.akamai.net photos-a.ak.facebook.com.edgesuite.net photos-a.ak.fbcdn.net
##ideally select 1 host at random from multiple of a995.dspmm1.akamai.net, although list may be randomised already so 1st will suffice##
64.34.119.12 stackoverflow.com
91.198.174.225 wikipedia-lb.esams.wikimedia.org wikipedia-lb.wikimedia.org www.wikipedia.org
91.198.174.225 wikipedia-lb.esams.wikimedia.org wikipedia-lb.wikimedia.org en.wikipedia.org
91.198.174.225 wikipedia-lb.esams.wikimedia.org wikipedia-lb.wikimedia.org ja.wikipedia.org
##Ideally, detect these similarities for wikipedia and convert the 3 lines into this;##
91.198.174.225 wikipedia-lb.esams.wikimedia.org wikipedia-lb.wikimedia.org www.wikipedia.org en.wikipedia.org ja.wikipedia.org
The intention is that the file will be distributable on a low bandwidth, high latency link, so the file should be as small as possible. I am aware that using this file over a long period of time will cause lots of issues, I have configured the file only to be valid for a short period of time. If anyone can help with the issues pointed out, it would be greatly appreciated. Also, I have a limited range of UNIX applications available. If the above can be achieved in awk, that would be preferable. Thank you in advance!
Source: (StackOverflow)