The file hosts is a hidden system document that manages the mapping of domain names (for example, google.com) to IP addresses. On Android it works the same way as on Windows or Linux, but editing it requires a special approach due to operating system limitations. Many users want to change this file to block ads, unblock blocked sites, or speed up access to certain resources.
Unlike desktop OSs, where hosts is publicly available, on Android it is hidden in a protected part of the system. This means that changing it most often requires root access or special workarounds. However, there are alternative methods - from using applications to manipulating DNS. In this article, we will analyze all the current methods, their pros and cons, and also warn against common mistakes that can lead to malfunctions of the device.
Why change the hosts file on Android?
Editing hosts can solve several practical problems:
- ๐ Unblocking sites: if the provider or government authorities restrict access to certain resources (for example, social networks or torrent trackers), redirecting the domain to another IP via
hostscan bypass the blocking. - ๐ซ Blocking ads and trackers: Many advertising networks use fixed domains. By registering in
hostsa redirect to127.0.0.1, you can block banner displays in the browser and applications. - โก Speed up loading sites: if the provider's DNS server is slow, manually specifying the IP for frequently visited resources will reduce the time expectations.
- ๐ก๏ธ Phishing protection: you can block known fraudulent domains by redirecting them to โsafeโ IPs.
However, the method also has a downside. For example, if you make a mistake in the syntax or specify the wrong IP, some sites will stop opening. In addition, after updating Android, the file hosts may be reset to factory settings.
โ ๏ธ Attention: Changing system files without root access can lead to loss of warranty or unstable operation of the device. On some firmware (for example MIUI or One UI) methods without root are unstable.
Where is the file located hosts on Android?
In most cases, the path to the file is the same for all devices:
/system/etc/hosts
However, access to it depends on the version of Android and the presence of root access:
- ๐ฑ Without root: the file can be read (for example, via File Manager+ or FX File Explorer), but it cannot be changed directly succeeds - the system will block the recording.
- ๐ง With root: the file is open for editing with any text editor (for example, Root Explorer or Solid Explorer).
- ๐ค Android 10+: due to the division of the system partition (
/systemhas become read-only even with root) additional manipulations are required or Magisk.
On some custom firmware (for example, LineageOS) the path may differ. To find out the exact address, use the command in adb shell:
find / -name hosts 2>/dev/null
How to change hosts without root access
If your device is not rooted, there are several workarounds. They are less reliable than editing directly, but can work on some firmware.
Method 1: Using editor applications
Some applications can temporarily replace hosts via VPN or local proxy. Popular options:
- ๐ Hosts Editor (from Speed Software) - allows you to edit the file through bypass mechanisms, but requires
adbto activate. - ๐ก๏ธ Blokada - blocks ads and trackers without root, using VPN to redirect traffic.
- ๐ DNS Changer - alternative to editing
hostsby changing DNS servers (for example, to1.1.1.1or8.8.8.8).
Instructions for Hosts Editor:
- Install the application from Google Play.
- Connect the phone to the PC and run the command:
adb -d shell pm grant com.speedsoftware.rootexplorer android.permission.WRITE_SECURE_SETTINGS - Open Hosts Editor, select
Edit hostsand make changes. - Save the file and restart the device.
โ ๏ธ Attention: On Android 12+ this method may not work due to stricter security policies. applications.
Method 2: Via ADB (without root)
If you have access to adb, you can try changing the file permissions hosts temporarily:
adb shellsu
mount -o rw,remount /system
chmod 644 /system/etc/hosts
echo "127.0.0.1 example.com" >> /system/etc/hosts
mount -o ro,remount /system
This method will only work on older versions of Android (up to 9 inclusive) and can lead to bootloop (loop reboot) if done incorrectly.
Install ADB on PC
Enable USB debugging in the phone settings
Download the Hosts Editor application
Make a backup copy of the original hosts file
Connect the phone to the PC via USB-->
How to change hosts with root access
If your device has one root (for example, through Magisk or SuperSU), the process is simplified. You will need any file manager with root support (for example, Root Explorer or Mixplorer).
Step-by-step guide
- Open the file manager and go to the path
/system/etc/. - Find the file
hostsand make a backup copy of it (copy it to another location, for example, to an SD card). - Open the file in a text editor The standard content looks like this:
127.0.0.1 localhost::1 ip6-localhost - Add your rules at the end of the file. block advertising:
127.0.0.1 doubleclick.net127.0.0.1 googleads.g.doubleclick.net - Save the changes and reboot the device.
If after reboot the changes are not applied, check the file permissions. They should be rw-r--r-- (644) You can change them with the command:
chmod 644 /system/etc/hosts
Automation using. Magisk
If you use Magisk, you can install a module Systemless Hoststhat allows you to edit hosts without the risk of damaging the system partition. Install the module via Magisk Manager and edit the file in /data/adb/hosts.
| Method | Requires root | Complexity | Risk of crashes | Compatibility |
|---|---|---|---|---|
| Hosts Editor (via ADB) | โ No | Average | Low | Android 5โ9 |
| Blokada (VPN) | โ No | Low | Absent | All versions |
| Manual editing | โ Yes | High | Medium | All versions |
| Magisk + Systemless Hosts | โ Yes | Medium | Low | Android 7+ |
Before editing hosts, make a backup via TWRP or command adb pull /system/etc/hosts hosts_backupThis will help restore. file if something goes wrong.
Typical mistakes and how to avoid them
Even experienced users sometimes make mistakes when working with hosts. Here are the most common:
- ๐ Incorrect syntax: if you forget the space between the IP and the domain or use a tab. instead of a space, the rule will not work. Correct format:
127.0.0.1 example.com - ๐ Unsaved rights: after editing the file, its rights should be
644. If they are777, the system can ignore the changes. - ๐ฑ Incompatibility with firmware: on some custom ROMs (for example, Pixel Experience), the file
hostsmay be located in a different location or be additionally protected. - ๐ DNS Caching: even after changes, some applications (for example Chrome) may use cached DNS records. Clear the DNS cache with the command:
adb shell "su -c 'ndc resolver flushdefaultif'"
On devices with Android 10+, the hosts file may be automatically reset after a system update. To avoid this, use. Magisk modules or initialization scripts (init.d).
โ ๏ธ Attention: If after editing hosts the device stops booting, boot into recovery mode (for example, TWRP) and restore the original file from the backup.
What to do if after the changes the Internet has disappeared?
If after editing hosts the Internet stops working, check:
1. Are there any typos or extra characters in the file?
2. Are the IP addresses specified correctly (for example, 127.0.0.1 instead of 127.0.1).
3. Have you accidentally blocked the provider's DNS servers?
If the problem persists, restore the original file and reboot the device.
Alternatives editing hosts
If changing hosts is too risky or inconvenient, there are alternative ways to achieve the same goals:
- ๐ Change DNS: use public DNS servers such as
1.1.1.1(Cloudflare) or8.8.8.8(Google). This will help bypass provider blocking and speed up loading sites. - ๐ก๏ธ VPN with traffic filtering: services like ProtonVPN or AdGuard VPN block advertising and trackers at the network level.
- ๐ฑ Ad blocking applications: AdAway (requires root) or Blokada (works without root via VPN).
- ๐ง Firewall applications: NetGuard or AFWall+ allow you to block access to individual applications to the network.
The advantage of these methods is that they do not require intervention in system files and are less risky. For example, changing DNS takes less than a minute and does not cause failures.
| Method | Required. root | Blocks advertising | Bypasses blocking | Impact on speed |
|---|---|---|---|---|
| Editing hosts | โ (optional) | โ | โ | No |
| DNS change | โ No | โ (partially) | โ | Can speed up |
| VPN with filtering | โ No | โ | โ | May slow down |
| AdAway | โ Yes | โ | โ | No |
If your goal is ad blocking, it is easier and safer to use specialized applications (for example, Blokada) instead of manual editing hosts.
FAQ: Frequently asked questions about the hosts file on Android
Is it possible to change hosts on Android without root and ADB?
Yes, but with limitations. data-i="226">allow you to block sites and ads without root, but they work through a VPN or changing DNS, and do not edit the file itself Blokada or DNS Changer allow you to block sites and ads without root, but they work through a VPN or DNS change, rather than editing the file itself hosts. A full change hosts without root is only possible on older versions of Android (up to 7.0).
Why are there no changes after editing hosts? are applied?
Probable reasons:
- The file was saved with incorrect rights (must be
644). - The system uses cached DNS records (clear the cache with the command
ndc resolver flushdefaultif). - On Android 10+ file
hostscan be protected from changes even with root. - The application you are using ignores the system one
hosts(for example, some browsers have their own DNS cache).
How to return the original hosts file?
If you made a backup a copy, just restore it. If not, download the standard file hosts for your version of Android (for example, from the source. AOSP) and replace the current one with it. You can also reset the network settings in Settings โ System โ Reset, but this will delete all saved Wi-Fi networks.
Will hosts work if I use a VPN?
No, if the VPN redirects all traffic through its servers In this case, the rules are from hosts are ignored, since requests go to the DNS servers of the VPN provider. However, some VPNs (such as Blokada) allow you to combine your own filters with the system one. hosts.
Is it possible to block applications through hosts?
No, the file hosts works only with domain names. To block application access to the network, use firewalls like AFWall+ (requires root) or NetGuard (works without root via VPN).