Location of the hosts file on Android Xiaomi: search and editing

The hosts system file is a fundamental element of the Android operating system architecture, including the shell. MIUI And Xiaomi's new HyperOS, which is the text document that's responsible for prioritizing domain names to match them with other domain names. IP-addresses before addressing DNS-Users often search for it to block system-level ads, disable updates, or redirect traffic to local servers.

However, finding and editing this file on Redmi and POCO smartphones is not as easy as it is on desktop computers. Android security by default hides system partitions from normal access, requiring special rights and tools. In this article, we will discuss in detail the exact path to the file, how to open it and the nuances of working with the file system of modern devices.

Android File System Architecture and the Role of Hosts

The Android operating system that runs your Xiaomi smartphone is based on the Linux kernel, which means that the storage of data here is subject to strict rules of UNIX-like systems. The hosts file is located in the system partition, which is by default mounted read-only, this is done by developers specifically to prevent accidental or malicious changes to critical network settings.

When you enter a site address in your browser or an application tries to connect to a server, the system first checks the local match table. If the desired record is found in the hosts file, the connection is established according to the specified IP-address, ignoring requests to external DNS. This allows you to effectively block unwanted connections, such as ad servers or analytics trackers.

On Xiaomi devices, the situation is complicated by the presence of additional layers of protection. The MIUI shell has built-in integrity controls that can prevent modification of system files even if root rights are available. In addition, new versions of Android use the mechanism of System-as-Root, which changes the traditional structure of directories and requires a more careful approach to editing.

The exact path to the hosts file on Xiaomi

Regardless of your smartphone model β€” whether it’s a budget Redmi Note or a flagship Xiaomi 14 β€” the physical location of the file in the directory structure remains the same. The absolute path to it always looks the same. To navigate the file system, you’ll need a file manager with support for displaying hidden system folders and access to the root of the system.

The standard path is as follows:

/system/etc/hosts

In some cases, especially on very old versions of Android or specific builds, a file may be duplicated or in an alternate location, although this is rare for modern devices. Sometimes users confuse this file with the configuration files of specific applications that may lie in the /data/data/ folder, but the global rule is precisely the path through /system/etc.

⚠️ Warning: Direct editing of the file along this path without creating a backup can result in loss of internet access or a cyclical device restart (bootloop).Always backup the original file before making any changes!

To work with this way, you will not be able to use the usual tools of the file manager built into MIUI. You will need a third-party application capable of handling root permissions, such as Root Explorer, Solid Explorer (with plugins) or a specialized Hosts Editor.

πŸ“Š Do you need root rights to edit hosts?
Yeah, that's the only way.
No, there are methods without root.
I'm using it. DNS-applications
I don't know what it is.

Need to obtain Root rights

The main obstacle to the hosts file is that the average user does not have superuser rights. In Android terminology, this is called Root. Without these rights, any attempt to write to the /system directory will be rejected by the system kernel with the Permission denied error. On Xiaomi devices, obtaining these rights is a paid and complex process.

Xiaomi has implemented a strict Bootloader unlocking procedure, without which superuser rights cannot be set. You will have to wait 7 to 30 days after submitting an application in the official Mi Unlock app. Only after the bootloader is unlocked can you install a custom recover (TWRP) and implement a su binary file through Magisk patches.

Are there ways around this limitation? In theory, some vulnerabilities allow temporary root, but they are quickly closed by security updates. For stable operation and constant access to the hosts file, full unlocking and rooting are a must, without which you can only read the contents of the file, but not change it.

  • πŸ”‘ Root rights give you full control over the file system, including partitioning. /system.
  • πŸ”’ Without unlocking the bootloader, access to recording in hosts on Xiaomi is closed forever.
  • ⚠️ Unlocking procedure drops all data from phone and can void warranty.
  • πŸ›‘οΈ Some banking apps and anti-cheat games will stop working on rooted devices.

If your goal is simply to block ads, consider alternative methods that do not require deep intervention, such as using a private DNS. However, for fine-tuning network settings and redirecting domains, the hosts file remains an unrivalled tool.

Tools for editing system files

Once you have superuser rights, you will need the right software tools. Standard text editors from Google Play will not be able to save changes to the system folder, because they do not have the appropriate privileges. You will need specialized applications-wires or editors with Root Access.

One of the most popular and reliable solutions is the Root Explorer application, which allows you to mount the file system in read-write (R/W) mode. Also perfectly cope with the task of Solid Explorer (with a root plugin attached) or MT Manager, which is often used by advanced users to modify APKs and system files. You can use the built-in editors of these applications for direct text editing or install QuickEdit with root support.

β˜‘οΈ Verification of editing readiness

Done: 0 / 5

The process of connecting rights in the file manager usually looks like this: you open the application, it requests permission to access the superuser (a request from Magisk or SU appears), you confirm access. After that, the Explorer interface allows you to switch the state of the partition /system between Read-Only and Read-Write. Without switching to write mode, any attempts to save the file will fail.

⚠️ Note: When working with system files through third-party explorers, carefully monitor the encoding. ASCII or UTF-8 without BOM. Adding extra encoding characters can make a file unreadable for the system.

Step-by-step instructions for changing hosts

The editing process requires carefulness and strict adherence to the algorithm. IP-The following is a detailed guide for users with already obtained superuser rights on a Xiaomi device.

Open your root guide first and go along the way. /system/etc/. Find a file called hosts (without extension). Before opening, make sure to create a copy of it in a convenient folder, such as the root of the internal storage, and name it. hosts_backup. This is your crash insurance.

Then you need to switch the file system to write mode. Most conductors have a Mount R/W button or a switch in the top menu. Once you activate the mode, open the hosts file with the built-in text editor. You will see content where the commented lines begin with the # grille symbol.

# Copyright (c) 2023 Xiaomi Inc.

# Android hosts file


127.0.0.1       localhost



::1             localhost

To add a lock or redirect rule, add a new line at the end of the file. IP-Add an address, then through a space or tab, a domain name. For example, to block access to an ad server, add a line:

127.0.0.1       adserver.example.com

After making all the necessary changes, save the file. It is important to make sure that the application has actually written the data to the disk. In some cases, you need to manually restart the device to make the changes effective, because DNS-Android client can cache old records.

What to do if the file is not saved?
If the changes do not apply after clicking the Save button, check if the R/W mode is activated. If the mode is active but the recording is not going, it is possible that the file is protected by download verification (AVB). In this case, you need to disable verification through the Magisk module or vbmeta patch when you are firmware. Also check the free space in the /system partition, although the hosts file takes up a minimum of space.

Alternative methods without Root access

Because getting super-user rights to Xiaomi is a time-consuming and risky process, many users are looking for ways to achieve a similar result without tampering with the system partition. Fortunately, modern versions of Android (starting with 9.0 Pie and up) provide a built-in Private DNS (Private DNS) mechanism.

This method does not edit the hosts file directly, but allows you to redirect everything. DNS-requests to a third-party server that can filter traffic, such as using AdGuard servers DNS, You block ads at the network level without touching system files. β†’ Connection and sharing β†’ Private DNS and enter the host address of the provider.

Another option is to use local VPN-applications like Blokada or AdGuard (the rootless version) create local applications. VPN-A tunnel through which all traffic is passed by a device, filtering it according to its internal lists, which technically perform the same function as the entries in the hosts file, but at the user application level.

  • πŸš€ Private method DNS No need to unlock the bootloader and root rights.
  • πŸ“‰ Battery consumption when using locally VPN It may be higher than the system lock.
  • πŸ”„ The lock lists in the applications are updated automatically, unlike the static hosts file.
  • πŸ“± Some applications may conflict with local applications VPN, require.

⚠️ Note: When using third-party DNS-servers VPN-filters all your Internet traffic passes through their infrastructure. Choose only trusted service providers with transparent privacy policies to avoid data leakage.

Recovery of the original hosts file

If you have problems connecting to the Internet after editing the hosts file, if some sites stopped opening or applications started to give out network errors, you need to return the original system state, which is why we recommended backing up at the beginning of the process.

To restore, open a file manager with root access, go to the folder where you saved the copy (for example, /storage/emulated/0/hosts_backup). Copy this file and paste it into the directory /system/etc/, Make sure that the permissions of the recovered file match the original: usually rw-r--r-- (644).

If the phone goes into a cyclic reboot and you can’t boot the operating system, you will need to log in to Recovery mode. Through TWRP or other custom recovery, you can open the file manager, find a backup and restore the /system/etc/hosts file. If the backup is not available, you can create an empty file with the correct rights or restore a standard file from stock firmware.

Reset network settings in the Android menu (Settings) β†’ Connection and sharing β†’ Resetting Wi-Fi, Mobile Networks and Bluetooth Could Also Help Clean Up DNS-cache, but it will not restore the contents of the hosts file if it has been physically modified.

ParameterStandard AndroidXiaomi (MIUI/HyperOS)Requirements
The path to the file/system/etc/hosts/system/etc/hostsRoot access
EditingOnly Root.Only with Root+ unlocking BLApps: Root Explorer
The alternativePrivate DNSPrivate DNS + Local VPNAndroid 9.0+
Risks.Loss of networkNetwork loss, Bootloop, warranty rallyAvailability of backup

πŸ’‘

Before any operation with system files, make sure your device is at least 60% charged. interrupting the writing process due to battery discharge can cause file system damage and data loss.

πŸ’‘

Xiaomi hosts file is on the way /system/etc/hosts, But to change it, root rights are required, and you need to unlock the bootloader. DNS.

Frequently Asked Questions (FAQ)

Can I edit hosts on Xiaomi without a computer?
Yes, it is possible. You will need to install a root-rights application (like Magisk) and a root-enabled file manager directly on your smartphone. You only need the computer when you unlock the bootloader through the Mi Unlock Tool.
Why are hosts not blocked from YouTube ads after editing?
Blocking ads in apps like YouTube often requires blocking specific domains that change all the time. The hosts file is static. YouTube also uses HTTPS and can bypass blocking if the application has built-in security mechanisms or uses multiple domain names for a single feature. YouTube is more effective at using modified clients.
Will the hosts file reset when you update your MIUI firmware?
Yes, when you upgrade your system over the air (OTA) or through Recovery, the system partition /system is overwritten with the new version. All your changes to the hosts file will be lost, and the file will return to factory status. You will have to make changes again after each major update.
Is it safe to use Magisk modules to manage hosts?
Using Magisk modules (such as Hosts AdBlocker) is a safer and more convenient way than manual editing. The modules work in the system partition without its physical modification (systemless), which makes it easy to disable changes and reduces the risk of system damage when updating.
How do I know if my hosts file is active?
You can check the activity of the records using the command line through ADB Or a terminal on a phone. The ping command will show you which domain.com is on. IP-If you block a domain through hosts (directing to 127.0.0.1), the ping will go to the local address, not the real server.