This blog post will guide you through the process of using your computer as a DNS server using Dnsmasq. This setup offers several advantages, such as running multiple applications on your computer and being able to access them from your mobile devices or iPad using a specific address.
What is Dnsmasq?
Dnsmasq is a lightweight and easy-to-configure DNS and DHCP server. It provides a flexible and efficient solution for managing domain names and IP addresses on a local network. It offers a wide range of customization options and is particularly useful for those who want to run multiple applications on their computer and access them from other devices.
Dnsmasq installation
- Install dnsmasq
sudo apt update
sudo apt install dnsmasq
- In
/etc/dnsmasq.conf
add these 2 lines (to have access to the internet):
server=8.8.8.8
server=4.4.4.4
- Check your private IP with
ifconfig
- Change
127.0.0.1
to your private IP in/etc/hosts
, something like this:
- stop systemd-resolved which is the default and start dnsmasq
sudo systemctl stop systemd-resolved
sudo service dnsmasq restart
Ipad configuration
- In Your Ipad go to WiFi settings and Click in the info icon in your WiFi
- Scroll down and click in configure DNS
- Change from Automatic to Manual, remove the other entries and add one with the private IP and press save
- Now you can connect to your apps, and if they communicate with each other through this custom domain, you won’t have any issues.
Return to normal
Using dnsmasq can be slower than systemd-resolve and 127.0.0.1 (depending on your connection speed), so to return to normal, follow these steps:
Change
/etc/hosts
back to how you had itStop dnsmasq and restart systemd-resolved
sudo systemctl stop dnsmasq
sudo systemctl start systemd-resolved
- Change DNS options in Ipad to automatic
Conclusions
You can use this to debug a complex stack in local on any device or even to create a small intranet. For Android users, you can download an application like Hosts Go to change the DNS server (I have personally tested it).
Here are a couple of tricks I use when debugging applications locally from different devices:
- We can’t see the console locally but you can inject from javascript using `alert` or `innerHTML`
- We can use `getComputedStyle` to see the styles of an element