DNSmasq on Android in Xiaomi Redmi: what it is, how it works and why it is needed

If you've ever been digging into your Xiaomi Redmi network settings or trying to optimize your Internet connection, you've probably come across the term DNSmasq. It's not just another technical jargon, a tool that can dramatically change your mobile Internet experience, but what is it really about? Why does it appear in your system logs, how does it relate to adblock, and can it be used to speed up page loading?

In this article, weโ€™ll take DNSmasq from the Xiaomi Redmi ownerโ€™s perspective, from basics to practical setup instructions, how it interacts with Android, why itโ€™s often mentioned in the context of ad blocking, and what pitfalls can arise when manually configured, and how to check if DNSmasq is working on your device right now, even if youโ€™ve never heard of it before.

What is DNSmasq and why is it needed on Android?

DNSmasq is a lightweight. DNS-forwarder DHCP-On Android (including Xiaomi Redmi smartphones), it performs two key functions:

  • ๐Ÿ”„ Caching DNS-Reduces delays when opening websites, keeping responses to frequent requests.
  • ๐Ÿ›ก๏ธ Traffic Filtering: Allows you to block ad domains or malicious sites at the system level.
  • ๐Ÿ“ก Local Name Resolution: Speeds up access to devices on a local network (e.g., a router or printer).

On Xiaomi Redmi, DNSmasq usually works in the background as part of system services, but it can also be reconfigured to block ads through a hosts file or custom rules. It is important to understand that this is not a separate application, but a system component that is managed through configuration files or specialized utilities like Magisk.

Why is this relevant for Redmi? it's about aggressive advertising in MIUI and the limitations of the standard DNS-DNSmasq allows you to bypass these restrictions by redirecting requests through alternative servers (e.g. Cloudflare or AdGuard). DNS) or block them completely.

๐Ÿ“Š Have you ever tried to block ads on Xiaomi Redmi?
Yes, through apps like AdGuard.
Yes, editing the hosts file.
No, I haven't.
I don't know how to do that.

How DNSmasq Interacts with MIUI on Xiaomi Redmi

In MIUI firmware (even on the latest versions for Redmi Note 12 or POCO X5), DNSmasq is integrated into the network system stack, but its behavior depends on several factors:

  • ๐Ÿ“ฑ Version. MIUI: in older versions (up to) MIUI 12) the service may not work smoothly, especially when used VPN.
  • ๐Ÿ”’ Root rights: without them, you canโ€™t edit a configuration file /etc/dnsmasq.conf.
  • ๐ŸŒ Network settings: if you are using a private DNS (For example, 1.1.1.1), DNSmasq will forward requests through it.

One key point is that DNSmasq in MIUI often works in tandem with netd, which means that even if you manually disable DNSmasq, the system can automatically restart it when you change the network, such as when you connect to a new Wi-Fi point or reboot your device.

Fun fact: some Redmi models (e.g. Redmi 9A) use DNSmasq to implement the "Private DNS" function in the settings. If you turn it on, you've actually activated DNS-over-TLS, and DNSmasq acts as an intermediate for encrypting queries.

๐Ÿ’ก

To check if DNSmasq works on your Xiaomi, type ps | grep dnsmasq in the terminal. If the process is active, you will see its PID.

Can you use DNSmasq to block ads on Xiaomi?

Yes, and this is one of the most popular uses of DNSmasq on Android. The mechanism is simple: you download a list of ad domains (e.g., from the StevenBlack/hosts project) and configure DNSmasq to redirect queries to those domains to 127.0.0.1 (i.e., โ€œnowhereโ€).

But there are nuances:

  • โš™๏ธ Root rights: without them, you canโ€™t change system files or install DNSmasq as a service.
  • ๐Ÿ”„ Listing updates: Advertising domains are constantly changing, so rules need to be updated manually or through scripts.
  • ๐Ÿ“ต Limitations MIUI: some system applications (for example, MIUI System Ads can ignore DNSmasq settings.

An alternative way is to use apps like AdGuard or Blokada, which emulate VPNs and filter traffic at the DNS level. They donโ€™t require root, but they are less effective because they donโ€™t block ads at the system level.

How to get around MIUI restrictions without root?
Some users manage to block ads through DNSmasq even without root, using Termux and running the service in the user space. However, this requires the terminal to be constantly open and works unstable.
Method of blocking advertisingRoot is required.EfficiencyDifficulty setting up
DNSmasq + custom rulesโœ… Yes.โญโญโญโญโญMedium
Applications (AdGuard, Blokada)โŒ No.โญโญโญLow.
Editing the hosts fileโœ… Yes.โญโญโญโญTall.
Private DNS (MIUI)โŒ No.โญโญLow.

How to set up DNSmasq on Xiaomi Redmi: step-by-step instructions

If youโ€™re ready to dive into the settings, hereโ€™s the basic DNSmasq configuration algorithm on Xiaomi Redmi (youโ€™ll need root rights and a file manager with access to system folders, such as Root Explorer):

Get root rights (for example, through Magisk)|Download the current list of advertising domains (for example, from GitHub)|Make a backup of the original file /etc/dnsmasq.conf|Install a terminal (Termux or built-in) MIUI)-->

Step 1. Backup

Before changing, copy the original config:

cp /etc/dnsmasq.conf /etc/dnsmasq.conf.bak

Step 2: Configuration editing

Open the /etc/dnsmasq.conf file and add the following lines:

addn-hosts=/etc/dnsmasq.hosts


conf-dir=/etc/dnsmasq.d

Here /etc/dnsmasq.hosts is a file with a list of blocked domains, and /etc/dnsmasq.d is a folder for additional configs.

Step 3: Download the lock lists

Download the current list (for example, StevenBlack/hosts) And keep it like /etc/dnsmasq.hosts. Make sure the file is authorized. 644.

Step 4: Restart the service

Follow the commands:

chmod 755 /etc/dnsmasq.conf


killall dnsmasq




dnsmasq --no-daemon

If there are no errors, add DNSmasq to the autoload via init.d or Magisk.

๐Ÿ’ก

After setting up, check the DNSmasq operation with logcat | grep dnsmasq. If you see errors such as "permission denied", correct the file rights.

Common Problems and Their Solutions

Even with the right DNSmasq setup on Xiaomi Redmi, there may be failures.

  • ๐Ÿšซ Advertising is not blocked: check that the /etc/dnsmasq.hosts domains are specified in format 0.0.0.0 ad.example.com. some applications (e.g. Facebook) may use HTTPS bypass the lockdown.
  • ๐ŸŒ Internet is not working: DNSmasq may conflict with netd. DNS customized MIUI.
  • ๐Ÿ”„ Settings are reset after restart: add the autorun script to /data/adb/service.d/ Or use the Magisk module.

Critical error: on some MIUI firmware (for example, for Redmi Note 10 Pro), the system dnsmasq compiles without support for the option addn-hosts. In this case, locking through the hosts file will not work - you will need to collect a custom binary.

If your site opens slower than usual, check:

  1. Is the block list overloaded (optimally up to 50,000 domains).
  2. Does DNSmasq conflict with others? DNS-services (e.g. Google) DNS or Cloudflare).
  3. Is the power saving mode turned on, which can โ€œsleepโ€ network processes?

๐Ÿ’ก

For diagnosis, use the command dig @127.0.0.1 example.com. If the response comes with a delay, the problem is in the DNSmasq configuration.

DNSmasq vs. Alternatives: Whatโ€™s Best for Xiaomi Redmi

DNSmasq is not the only way to manage DNS-Let's look at the alternatives and their pros/cons:

DecisionPlusesConsRoot is required.
DNSmasqSystem-wide lockdown, low resource consumptionComplicated settings require updating of rulesโœ… Yes.
AdGuard (VPN-regime)Simple installation, regular filter updatesIncreased battery consumption, does not block MIUI system advertisingโŒ No.
BlokadaOpen source, support for custom listsMay be in conflict with others VPN-applicationsโŒ No.
Private DNS (MIUI)Built-in function, does not require additional applicationsIt does not block ads, only encrypts requests.โŒ No.
Hosts fileSimplicity, works without root (on some firmware)Limited functionality, does not support regular expressionsโœ… Yes, for full access)

For most users of Xiaomi Redmi, the best solution is a combination of:

  1. DNSmasq to block system advertising (if there is root).
  2. AdGuard or Blokada to filter application traffic.
  3. Private DNS in MIUI settings for encrypting requests.

If youโ€™re not ready to mess with manual settings, itโ€™s best to stick with AdGuard โ€“ it offers a balanced balance of efficiency and ease of use.

Safety and risks of using DNSmasq

Like any system tool, DNSmasq can become a vulnerability if configured incorrectly.

  • ๐Ÿ•ต๏ธ Data Leakage: If you are redirecting traffic through an unreliable DNS-server, your requests may be intercepted.
  • ๐Ÿ”“ Conflicts with VPN: some VPN-Applications (e.g., ProtonVPN) can ignore DNSmasq settings, which will lead to a leak. DNS.
  • ๐Ÿ› ๏ธ Network instability: Incorrect rules in dnsmasq.conf can disrupt access to certain sites or services (e.g. Google Play).

โš ๏ธ Attention: On some firmware MIUI (Especially Chinese versions of DNSmasq may conflict with the system DNS-A proxy that is used to track users. If you notice increased traffic to suspicious domains after setting up, roll back the changes immediately.

To minimize the risks:

  1. Use only proven sources for lock lists (e.g. Steven Black or OISD).
  2. Update your DNSmasq and related components regularly (e.g., via Magisk).
  3. Check the logs of dnsmasq for errors: logcat | grep -i dns.

If you use Xiaomi Redmi to work with sensitive data (for example, online banking), it is better to abandon customization. DNS-Decisions in favour of standard security mechanisms MIUI.

FAQ: Frequent questions about DNSmasq on Xiaomi Redmi

Can you use DNSmasq without root rights?
Technically, but with serious limitations. You can run DNSmasq in user space via Termux, but: It won't block traffic to system applications. You'll need to keep the terminal open all the time. Some applications (like Chrome) may ignore your DNS. Root is a must to work properly.
Why do some sites not open after setting up DNSmasq?
This is a typical problem when using aggressive lock lists. Possible reasons: The site is blacklisted (check /etc/dnsmasq.hosts). Conflict with a VPN or Private DNS in MIUI. DNSmasq can't resolve a domain because of configuration errors. Solution: temporarily disable the lock and check if the site opens. If so, look for a problem in the rules.
How to roll back changes if the Internet is lost after setting up?
If you have saved the backup (as recommended in the instructions), simply restore the original /etc/dnsmasq.conf: cp /etc/dnsmasq.conf.bak /etc/dnsmasq.conf killall dnsmasq If there is no backup, restart the device in Safe Mode (press the power button โ†’ "Reboot in Safe Mode") and remove all changes manually.
Does DNSmasq work on all Xiaomi Redmi models?
Yes, but with reservations: Older models (e.g. Redmi 4X) may require manual compilation of DNSmasq for an older version of Android. On new flagships (e.g. Redmi K60), the system DNSmasq can be replaced with android.net.dns.DnsProxy. On Chinese firmware (MIUI China), some DNSmasq functions can be disabled at the kernel level. Before setting up, check the system logcat | grep -i dnsmasq.
Can DNSmasq be used to speed up the internet?
Yes, but the effect will only be noticeable in specific scenarios: If you visit the same sites frequently, caching is a good idea. DNS It will reduce the time it opens. If your provider uses slow ones, DNS-servers, forwarding requests via Cloudflare (1.1.1.1) or Google DNS (8.8.8.8) can speed up downloads, but don't expect miracles: download speeds or ping in DNSmasq games are almost unaffected by the game's DNSmasq.