File hosts is a system text document that the Android operating system uses to map domain names to IP addresses. Unlike a regular DNS request that is sent to the provider, the system first checks this file. If it contains an entry that blocks a malicious domain, the connection simply will not be established, which allows you to effectively cut off advertising trackers and unwanted content.
However, standard access rights in Android prohibit regular applications from making changes to system files. This is why editing hosts often becomes a difficult task for untrained users. You will need to either gain superuser rights (Root) or use more complex methods via a computer and USB debugging.
Before you begin modifying system files, you need to clearly understand the risks. Incorrect syntax or deleting critical lines can cause the smartphone to stop connecting to the Internet or even go into endless loading. The source hosts file in Android is usually located along the path /system/etc/hosts and has no extension.
Why do you need to edit hosts on a smartphone?
The main reason why advanced users interfere with the operation of the system hosts file is to combat intrusive advertising. By blocking ad network domains at the system level, you prevent banners from loading not only in the browser, but also inside most free applications. This significantly saves traffic and speeds up the interface.
Another important aspect is security. By adding the addresses of known phishing sites or servers that distribute malware to the file, you create an additional barrier. Even if you accidentally click on a dangerous link, the device simply will not be able to connect to the hacker resource, as it will be redirected to nowhere.
โ ๏ธ Attention: Some applications, especially banking and gaming applications with online license verification, may block their operation if they detect a modified hosts file or the presence of root access. Be prepared for the fact that some services will no longer function correctly.
Editing hosts is also useful for developers. It allows you to redirect requests from real servers to local machines for testing APIs or emulating the operation of a website without Internet access. This is standard practice when debugging network applications.
Preparation: root access and editor selection
To make changes to the system memory area of the device, superuser rights are required. Without them, any attempt to save the file will fail with an access error. The most popular and reliable tool for rights management is Magisk. If your smartphone is already rooted, make sure that the rights manager is active and working correctly.
For the editing process itself, you will need a specialized text editor that can work with Root access. Standard notepads from Google Play often do not have the necessary permissions. It is recommended to use Root Explorer, Solid Explorer or MT Manager. These applications are able to mount the system partition in write mode.
Before starting any manipulations, it is critical to create a backup copy of the original file. Android system partitions are sensitive to errors, and having a copy will allow you to quickly restore the device's functionality in the event of a failure. Copy the hosts file to the internal memory or SD card.
โ๏ธ Preparing for editing
Method 1: Editing through a file manager with Root
This is the most direct method, requiring a minimum amount of equipment. You only need the smartphone itself and an installed file manager application. The process involves manually opening the file, making edits, and saving the changes with elevated privileges.
After opening the file, you will see a list of IP addresses and domains. A standard blocking entry looks like 127.0.0.1 domain.com. This means that all requests to the specified domain will be redirected to the local address of the device, that is, they will not go anywhere. It is important to follow the syntax: there must be a space or tab between the IP and the domain.
After making all the necessary changes, the file must be saved. The file manager will ask for confirmation to write to the system partition - agree. In some cases, you may need to reboot the device for the changes to take effect, although often Android picks up the new hosts instantly.
What to do if the file is not saved?
If an error appears after pressing the save button, check whether R/W (read/write) mode is enabled in your file manager. Often the system partition is mounted read-only. Find the "Mount R/W" button or similar in the application settings, switch the mode and try again. If this does not help, perhaps your method of obtaining root access does not provide full access to the /system partition, and you will need to use Magisk modules.
Method 2: Using specialized applications
There is a category of applications created specifically for managing the hosts file. They automate the process by providing a user-friendly interface with lists of popular ad blockers. One of the most famous tools is AdAway. This is an open source application that does not just edit a file, but manages lists of hosts.
The principle of operation of such apps is to download ready-made lists (hosts files) from trusted sources. You don't have to manually search for ad network domains. The application itself will download the latest databases, combine them and apply them to your hosts file. This saves time and reduces the risk of syntax errors.
When you first launch AdAway, it will ask for superuser rights. After obtaining root access, you must go to the menu and click the โApplyโ or โUpdate hostsโ button. The app will create a backup copy of the old file and replace it with the new one. The interface of such utilities usually contains tabs for managing white and black lists.
Use the "Whitelist" function in blocking applications to add exceptions for important domains. This will help avoid problems with the operation of your favorite applications that may be blocked by aggressive filters.
No Root method: Using ADB and a computer
If you do not want to root the device, you can use the debugging tool ADB (Android Debug Bridge). This method is more difficult, as it requires a computer, a USB cable and installed drivers. The essence of the method is to temporarily replace the system file through the command line.
First you need to enable USB debugging in the "For Developers" menu on your smartphone. Connect your device to your PC and open Command Prompt. Using the command adb pull /system/etc/hosts copy the original file to your computer. Edit it in any text editor (for example, Notepad++).
Then the file needs to be uploaded back. However, since the /system partition is write-protected, a direct command adb push will not work without root. The workaround is to use the command adb remount (works on some firmware) or temporarily remap the paths if the device allows it. On modern versions of Android (11+), this method may not work without an unlocked bootloader and custom recovery.
The method without Root via ADB on modern versions of Android is often limited by SELinux security policies. If the remount command returns an error, it means that your method without obtaining root access will not work, and you will have to look for alternatives.
File structure and syntax of entries
Understanding the structure of the hosts file is necessary for its competent editing. The file consists of lines, where each line represents a rule. Comments begin with the character # and are ignored by the system. Empty lines are also ignored.
Basic record format: IP_address domain_name. For example, the line 0.0.0.0 doubleclick.net will block the double click server. Using the address 0.0.0.0 is often preferable to 127.0.0.1, as it prevents any network connection attempts, including local ones.
The table below shows examples of common entries and their effect:
| File entry | Result | Status |
|---|---|---|
| 127.0.0.1 google.com | Blocking access to Google | Active |
| #127.0.0.1 test.com | Line ignored (comment) | Inactive |
| 0.0.0.0 ads.server.com | Complete blocking of the advertising server | Active |
| 192.168.1.5 myserver.local | Redirection to local IP | Active |
It is important not to delete the line 127.0.0.1 localhost, if it is present in the original file. This is a system entry necessary for the correct operation of some network services within Android itself. Violation of the basic localhost configuration can lead to unpredictable errors.
Possible problems and ways to solve them
After editing the hosts, you may encounter a situation where the Internet is completely lost or only some sites are working. This often occurs due to a syntax error in the file, such as an extra space or missing line break. In this case, the first thing you need to do is check the file for typos.
Another common problem is the DNS cache. Android aggressively caches DNS queries to speed things up. Even if you changed the file correctly, the system may continue to use the old data. To reset the cache, you can use airplane mode: turn it on for 10 seconds, then turn it off.
โ ๏ธ Attention: If after editing the hosts the smartphone stops booting (bootloop), you will need access to Recovery Mode. Through the file manager in recovery (if you have access to the file system) or through ADB in recovery mode, you must return the original copy of the hosts file.
It is also worth considering that many modern applications use HTTPS and check certificates. Blocking domains through hosts can cause certificate errors instead of silently blocking ads, which can annoy the user with constant pop-ups.
Why do ads still appear?
Advertising networks are constantly changing domain names. The lists in the hosts file may become out of date. In addition, some applications use IP addresses directly or encrypt requests, bypassing the hosts check. In such cases, it is more effective to use system blockers like AdGuard or personal DNS.
Frequently asked questions (FAQ)
Do I need to reboot the phone after changing hosts?
In most cases, it is enough to turn airplane mode on and off or just close and open the browser. However, to ensure that changes are applied to all applications, especially those running in the background, a complete reboot of the device will be the most reliable solution.
Will this method work on Android 13 or 14?
The principle of the hosts file remains the same in all versions of Android. However, security mechanisms are becoming stricter. On new versions without root access, it is almost impossible to change the system file. With root access, the method works stably, but requires care when choosing tools.
Is it possible to use hosts to bypass site blocking?
Theoretically, yes, by registering the correct IP address of the blocked resource. However, the IP addresses of sites change frequently, and this method is extremely unstable. To bypass blocking, it is much more effective and convenient to use a VPN or DNS services, such as DNS-over-HTTPS.
Where can I get current lists of domains to block?
The best sources are developer communities and projects like StevenBlack/hosts on GitHub. These lists are regularly updated by volunteers and contain thousands of ad and tracker server addresses. Applications like AdAway can download these lists automatically.