File hosts on Android is a hidden system document that manages the mapping of domain names (for example, google.com) to IP addresses. Editing it allows you to block ads, redirect traffic or test web projects locally. But unlike Windows or macOS, on smartphones this process is complicated by manufacturer restrictions and the OS version.
Many users encounter problems when trying to change hosts: the system simply resets the edits after a reboot, and without root access access to the file is completely blocked. In this article we will look at all current methods editing - from simple (via applications) to complex (using ADB i Magisk). You will also learn how to avoid common mistakes and why some methods stopped working after Android 10.
โ ๏ธ Attention: Incorrect editing of the hosts file can lead to loss of Internet access or application failures. You make all changes at your own peril and risk.
What is the hosts file and why edit it on Android
The file /etc/hosts exists in all operating systems, including Android. It works like a local "phone book" for domains: when you enter a site address in a browser, the system first checks this file, and only then contacts DNS servers. If hosts a rule for a domain is specified, it takes precedence.
The main reasons to edit a file on a smartphone:
- ๐ซ Ad blocking โ redirecting advertising domains to an โemptyโ IP (
127.0.0.1). - ๐ Testing sites โ linking a domain to a local IP (
192.168.x.x) for developers. - ๐ก๏ธ Phishing protection โblocking known fraudulent sites.
- ๐ Bypassing geo-blocking โredirecting domains to proxy servers.
On Android the file hosts is located on the path /system/etc/hosts (or /etc/hosts on some firmwares The main problem is that it is protected). from entries: even if you open it through the file manager, you will not be able to save changes without special rights.
โ ๏ธ Attention: Starting from Android 9 Pie, Google has tightened its security policy. Now many applications cannot change system files even with root access - additional configuration is required via Magisk or ADB.
Method 1: Editing hosts without root (via ADB)
If your device is no root accessbut enabled USB debugging, you can temporarily change the file hosts via ADB (Android Debug Bridge). to Android 11, but after a reboot the changes will be reset.
You will need:
- ๐ฅ๏ธ A computer with installed ADB drivers.
- ๐ฑ Smartphone with USB debugging enabled (
Settings โ About phone โ Build number(7 taps) โFor developers โ USB debugging). - ๐ USB cable (preferably original).
Step-by-step guide:
- Connect the phone to the PC and confirm permission to debug.
- Open the command line (
cmdon Windows orTerminalon macOS/Linux) and enter:adb devicesMake sure that the device is detected (its serial number should appear).
- Download the file
hoststo your computer:adb pull /system/etc/hosts C:\hosts_backup.txt - Open the downloaded file in any text editor (for example, Notepad++), make changes and save.
- Upload the edited file back:
adb push C:\hosts_backup.txt /system/etc/hosts - Change the file permissions so that the system accepts it:
adb shell chmod 644 /system/etc/hosts
โ ๏ธ Important: On Android 10+ this method may not work due to limitations Read-Only File System (ROFS). In this case, you will need remount section:
adb shellsu
mount -o rw,remount /system
But this requires root access (see method 3).
USB debugging is enabled
ADB drivers are installed on the PC
A backup of the original hosts file was made
USB cable connected directly (without hubs)
-->
Method 2: Applications for editing hosts without root
If ADB it seems difficult, you can use specialized applications. They do not require root access, but have limitations:
- ๐ Changes are reset after reboot.
- ๐ฑ They do not work on all firmwares (especially on MIUI, Flyme).
- ๐ก๏ธ They can be blocked by antiviruses as โsuspicious.โ
Best applications for editing hosts:
| Application | Android support | Features | Link |
|---|---|---|---|
| Hosts Editor | 5.0โ12 | Simple interface, file import/export, ad blocking | Google Play |
| Hosts Go | 6.0โ13 | Support for custom block lists, backup copying | Google Play |
| DNS66 | 7.0โ14 | Blocking ads via VPN, without editing hosts | F-Droid |
Instructions for Hosts Editor:
- Install the application and open it.
- Click
Loadโthe app will automatically download the current filehosts. - Add your own rules (for example,
127.0.0.1 doubleclick.netto block Google ads). - Click
Saveand confirm the action. - Restart your browser or applications for the changes to take effect.
โ ๏ธ Attention: On Android 13+ some applications may require additional permissions in Settings โ Applications โ Accessibility โ Changing system settings.
If after saving the changes are not applied, try manually restarting DNS cache through the command adb shell "su -c 'ndc resolver flushdefaultif'".
Method 3: Editing hosts with root access
If your device has root (for example, through Magisk or SuperSU), the editing process is simplified. access to system files, and changes will be saved even after a reboot.
Step-by-step guide:
- Install any root explorer (for example, Root Explorer or Solid Explorer with enabled root mode).
- Navigate to the path
/system/etc/and find the filehosts. - Tap and hold the file, select
Open with โ Text editor. - Make changes (for example, add a line
192.168.1.100 mysite.localfor local testing). - Save the file and set the permissions
644(owner - read/write, others - read only).
For reliability It is also recommended:
- ๐ Make a backup of the original file (
hosts.bak). - ๐ง Check the correctness of the syntax (each line must end with a line feed).
- ๐ฑ Reboot the device after changes.
On devices c Android 10+ i Magisk an additional module may be required Magisk โ Systemless Hostsfor the changes to be applied correctly.
What to do if the hosts file is not saved even as root?
If the file is reset after saving, the reason may be in:
1. SELinux โcheck its status with the command getenforce (should be Permissive).
2. Only Read File System โrun mount -o rw,remount /system before editing.
3. Magisk DenyList โadd your file manager to exceptions in Magisk settings.
Method 4: Using Magisk and Modules
If you use Magisk to root, the most reliable way to edit hosts โthrough special modules. This ensures that the changes will not be reset after updating the system.
Instructions:
- Open Magisk Manager and go to the section
Modules. - Click
+and selectInstall from storage. - Find the module
Systemless Hostsand install it. - After installation, reboot the device.
- File
hostswill now be located along the path/data/adb/modules/hosts/system/etc/hosts. Edit it through any root explorer.
Advantages of the method:
- ๐ Changes are saved after OTA updates.
- ๐ก๏ธ Does not affect the system partition (
/systemremains untouched). - ๐ฑ Compatible with Android 12โ14.
โ ๏ธ Attention: If the Internet stops working after installing the module, check the file syntax hosts. An error in one line can break the entire network.
The Systemless Hosts module is the only reliable way to edit hosts on modern versions of Android with Magisk.
Method 5: Alternatives to editing hosts
If all of the above methods are not suitable (for example, on devices with Samsung Knox or Android 14+), consider alternative ways to achieve the same goals:
1. Local DNS server (for example NextDNS or AdGuard Home)
- ๐ Set up custom DNS in the router or on the device (
Settings โ Network โ Private DNS). - ๐ซ Blocks ads and trackers at the DNS level, without editing
hosts.
2. VPN with traffic filtering
- ๐ Applications like Blokada or NetGuard block unwanted domains through a VPN tunnel.
- โก Does not require root access, works on all versions of Android.
3. Browsers with built-in ad blocking
- ๐ฆ Firefox with extension uBlock Origin.
- ๐ Brave Browser - blocks ads and trackers by default.
โ ๏ธ Attention: Some applications (for example, banking) can block work when a VPN or custom DNS is detected. In this case, use Magisk to hide root access (Magisk Hide).
Typical errors and their solutions
When editing hosts users often encounter problems. Here are the most common ones and how to fix them:
| Error | Cause | Solution |
|---|---|---|
| Changes are reset after reboot | The file is located in the /systempartition, which is mounted as read-only |
Use Magisk or ADB remount |
| No access to the file even with root | SELinux in Enforcing or firmware limitations |
Install Permissive via adb shell setenforce 0 |
| The Internet disappeared after editing | Syntax error in the file (for example, an extra space) | Check the file for validity or restore the backup |
| Applications ignore new rules | DNS cache has not been updated | Run adb shell "su -c 'ndc resolver flushif'" |
If none of the methods helped, check:
- ๐ฑ Android version (on Android 13+ many methods have stopped working).
- ๐ง Availability of firmware updates (manufacturers often close "holes").
- ๐ ๏ธ Error logs via
adb logcat(for experienced users).
To quickly return the original hosts file, download it from the official Android repository: original hosts
FAQ: Frequently asked questions about editing hosts on Android
โ Is it possible to edit hosts on Samsung without root?
On devices Samsung with One UI editing hosts without root is almost impossible due to Knox and strict restrictions on writing to /system. - use ADB s remount, but this requires unlocking the bootloader and does not work on all models.
Alternative: set private DNS to Settings โ Connections โ Other networks โ Private DNS (specify the address AdGuard DNS or NextDNS).
โ Why is advertising not blocked after editing hosts?
There may be reasons as follows:
- ๐ต The advertisement is loaded by HTTPS (hosts blocks only HTTP requests).
- ๐ The DNS cache has not been updated (run
adb shell "su -c 'ndc resolver flushif'"). - ๐ฑ The application uses own DNS (for example, Facebook or YouTube).
Solution: combine blocking via hosts with VPN (for example, Blokada) or Firewall (for example, NetGuard).
โ How to roll back changes in the hosts file?
If after editing the Internet is lost or errors occur, restore the original file:
- Download the standard one
hostsfor Android: original file. - Copy it to the device via
ADB:adb push hosts /sdcard/adb shell
su
mount -o rw,remount /system
cp /sdcard/hosts /system/etc/hosts
chmod 644 /system/etc/hosts - Restart the device.
โ Does editing hosts work on Android 14?
On Android 14 most traditional editing methods hosts stopped working due to:
- ๐ Enhanced partition protection
/system(even with root). - ๐ก๏ธ Limitations SELinux i AVB 2.0.
- ๐ฑ Blocking changes to system files through Dynamic Partitions.
Alternatives:
- Use Magisk + Systemless Hosts module.
- Configure VPN with filtering (for example, AdGuard VPN).
- Install custom recovery (for example, TWRP) and edit file manually.
โ Is it possible to edit hosts on an Android emulator (BlueStacks, Genymotion)?
Yes, on emulators the process is simpler, since you have full access to the virtual machine:
- Close emulator.
- Find the file
hostsin the emulator folder (for example,C:\app Files\BlueStacks\Engine\etc\hosts). - Open it as an administrator and make changes.
- Save and restart the emulator.
โ ๏ธ On some emulators (for example NOX), the file may be locked - in this case, use ADB the same as on a physical device.