There can be many cases where you want to make your own dns server to redirect some dns request to your site. This article will show you how to create a fake dns server or spoof dns response with a program called dnsmasq. You can install it in linux using the following command. In Kali it comes preinstalled.
- apt-get update
- apt-get install dnsmasq-base
Here 1. will update your apt-get and 2. will install dnsmasq-base.
After installing the dnsmasq edit the file /etc/dnsmasq.conf, create it if it doesn’t exit.
Here 1. & 2. will configure dnsmasq to use 18.104.22.168 (Google Public DNS) if no dns record is found in the /etc/dnsmasq.hosts file. /etc/dnsmasq.hosts is custom host file for dnsmasq. You can add your own host files.
Till now we haven’t created the /etc/dnsmasq.hosts file so create this file and add some dns entries as shown below.
- 192.168.0.1 www.router.my router.my
- 192.168.0.2 www.facebook.com facebook.com
- 192.168.0.3 www.mycustompageonnon80port.my
If you want an IP to point multiple site then you can give the URLs with space. And if you want to add a URL which runs on port other than 80 then, you just put IP in host file and in the browser put URL as http://www.mycustompageonnon80.portmy:1234.
Notice that some popular site like Facebook, Google etc will not be directed to these IPs as modern browser uses certificate pinning.
Now to start the dnsmasq server run the following commands.
- killall -g dnsmasq
- dnsmasq –no-daemon
Here 1. will stop dnsmasq if it is running currently and 2. will start it. –no-daemon will not send dnsmasq to background.