System file hosts is a fundamental element of network configuration in operating systems, including Android. It works like a local phone book that takes precedence over your ISP's DNS servers. When you try to open a website or connect to an application server, the system first checks this particular file to find out which IP address corresponds to the domain name.

Under standard conditions on smartphones, this file is hidden from the average user and protected by system access rights. Its main purpose is to redirect network requests or block them at the operating system level. Many enthusiasts are looking for a way to change its contents to block ads in browsers and games, as well as disable telemetry.

However, tampering with system files requires caution and an understanding of the structure of the Android file system. Incorrect editing can lead to unstable Internet operation or even the inability to load the operating system. In this article, we will look in detail at where exactly this file is located, what tools are needed to change it, and how to protect the device from errors.

Location of the hosts file in the file system

By default, the file hosts is located in the root section of the Android file system, which is reserved for system processes. The path to it is always standard and does not change depending on the version of the operating system or smartphone manufacturer. The full address looks like this:

/system/etc/hosts

This is where a text document without an extension is stored, containing domain mapping rules. In its default state, it contains only one active line pointing to the local host, and a few commented out examples. Access to the folder /system/etc/ is closed to normal applications for security reasons.

To access this directory, the user must have superuser rights, known as root. Without these rights, the file manager simply will not show the contents of the folder /system or will give an error when trying to read it. This is a protective mechanism that prevents accidental damage to critical system files by malware or inexperienced actions.

โš ๏ธ Attention: The partition /system is often mounted in Read-Only mode. Even if you have root access, to make changes you may need to remount the partition in Read-Write mode through a special file manager or terminal.

There is also an alternative path that some system utilities can use to temporarily store or cache network settings, but the main and only working file for permanent configuration remains the path indicated above. Changes made to other copies of files named hosts will not have an effect on the entire system.

๐Ÿ’ก

The hosts file is located along the path /system/etc/hosts and requires root access for access, since it is located in a protected system partition.

The need for root access for editing

The Android operating system is built on the Linux kernel, where there is a strict hierarchy of access rights. The file hosts is owned by the user root and group root, and the access rights are usually set to 644 or 655. This means that everyone can read it, but only the owner, the superuser, has the right to make changes.

An attempt to edit a file without superuser rights is doomed to failure. Standard text editors simply will not be able to save changes, and file managers will not allow you to open a file for writing. There are several ways to bypass this limitation, but all of them require elevated privileges in one way or another.

  • ๐Ÿ”“ Full Root: The classic method gives full control over the file system, allowing you to mount partitions and change the rights of any files.
  • ๐Ÿ› ๏ธ ADB (Android Debug Bridge): a debugging tool that in some cases allows you to make changes through the computer, but often also requires an unlocked bootloader.
  • ๐Ÿ“ฑ Specialized applications: apps like AdAway, which themselves request root access and manage the hosts file automatically.

Obtaining root access (for example, through Magisk) is a process that violates the integrity of the boot process and can lead to loss of warranty on the device. In addition, many highly secure banking applications and services (Google Pay, banking clients) may refuse to work on rooted devices.

If you do not plan to constantly modify system files, using root just once may not be advisable. In such cases, it is better to consider alternative methods, such as using Private DNS or installing local VPN filters that do not require deep intervention into the system.

๐Ÿ“Š Do you have root access on Android?
Yes, I use Magisk
I had it, but I removed it
I never have and donโ€™t want to
I plan to get

Tools for working with system files

For safe and efficient file editing hosts a regular text editor is not enough. You will need specialized software that can work with superuser rights and correctly process file encoding. The most popular and reliable solution is the file manager Root Explorer or its modern analogues, such as MiXplorer or Solid Explorer (with the root plugin).

These applications can request root access at startup and automatically switch the file manager to the editing mode of system partitions. It is important that the selected manager supports the function of switching the partition state /system between read (R/O) and write (R/W) modes. Without this function, it will not be possible to save changes, even if root access is granted.

There are also specialized hosts editors, which are add-ons to system files. They often have built-in advertising lists and allow you to add domains in one click. An example would be an application Hosts Editor or functionality included AdAway. These tools take care of the technical part of working with access rights and syntax.

When choosing a tool, make sure that it supports working with UTF-8 text without BOM. Having a BOM (Byte Order Mark) at the beginning of the file can cause the system to ignore the first line or, worse, not recognize the hosts file at all, considering it corrupt.

๐Ÿ’ก

Always make a backup copy of the original hosts file before making any changes. Just copy it to the same folder named hosts.bak.

Step-by-step guide for changing hosts

The process of editing the hosts file requires care and strict adherence to the algorithm of actions. Any typo in the syntax may cause the rules to not apply. Below are universal instructions for users with root access.

First you need to open the selected file manager with superuser rights. Go to the root of the file system (usually indicated as /) and sequentially open the folders system, then etc. Find the file named hosts. Before opening, click the access mode switch button in the top menu to change the status from R/O (Read Only) to R/W (Read Write).

Open the file with the built-in text editor. You will see lines starting with a hash character #. These are comments that the system ignores. To add a blocking rule, you need to enter an IP address and domain name. The standard format looks like this:

127.0.0.1 example.com

This entry redirects all requests to the domain example.com to the local address of the device, effectively blocking the connection. You can also use the address 0.0.0.0, which in some cases works faster since it does not require localhost processing. After making all the necessary changes, save the file and be sure to switch the access mode back to R/O for security.

โ˜‘๏ธ Checklist before saving

Completed: 0 / 4

After editing, it is recommended to reboot the device or at least reset the DNS cache. There's no easy button to reset DNS on Android, so rebooting is the most reliable way to apply the new rules. In some cases, turning airplane mode on and off helps.

โš ๏ธ Attention: The interfaces of file managers may differ. If you don't find the R/O button, look for a lock icon or the "Mount Read/Write" menu item. Without this step, the file will not be saved.

Using ADB to manage hosts

For users who do not want to install root access on a permanent basis, or for advanced administrators, there is a modification method via ADB (Android Debug Bridge). This method requires connecting the smartphone to the computer via a USB cable and having a set of platform tools installed on the PC.

The essence of the method is to send commands from the computer to the device. However, it is worth noting an important nuance: on most modern devices without an unlocked bootloader and root access, ADB works in user mode, which also allows writing to the partition. Therefore, this method is often applicable only on devices that already have root access, but are controlled remotely, or on emulators. shell, which is also does not have rights to register in the section /system. Therefore, this method is often only applicable on devices that already have root access, but are controlled remotely, or on emulators.

If you have root access, the command to overwrite the file may look like this. First you need to make a backup, then write down new data:

adb shell

su

echo "127.0.0.1 badsite.com" >> /system/etc/hosts

reboot

Using ADB is convenient because it allows you to quickly apply scripts and massively change the configuration on several devices. Also, via ADB, you can extract the original hosts file to your computer, edit it in a convenient editor (for example, Notepad++ or VS Code) and upload it back with the command adb push.

This means that all your changes in the hosts file will be lost, and the procedure will have to be repeated again. Some custom recoveries allow you to freeze changes, but this requires deep knowledge.

What to do if ADB does not see the device?

Make sure that "USB Debugging" is enabled on your phone in the "For Developers" menu. Also check if the ADB driver is installed on the computer and if you are using a quality USB cable that supports data transfer and not just charging.

Alternatives: DNS and VPN without root

Since rooting is a risky and difficult step, most users prefer modern alternatives to editing the file hosts. Private DNS (DNS-over-TLS) technologies built into Android 9 and above allow you to redirect requests to third-party servers that filter ads and trackers.

Another effective method is to use local VPN applications such as Blokada, AdGuard or DNS66. These apps create a virtual network interface through which all traffic passes. They analyze requests in real time and block connections to known ad servers using their own updated lists, which is much more effective than a static hosts file.

The advantage of such solutions is that they do not require root access, are easy to enable and disable, and their block lists are automatically updated by developers. The hosts file in this context becomes a relic of the past, relevant only for specific debugging tasks or on very old versions of Android.

Method Requires Root Complexity Efficiency
Hosts file Yes High Medium (static list)
Private DNS No Low High (encryption + filtering)
VPN filters (AdGuard) No Medium Maximum (dynamic lists)
Modified firmware Yes (in the system) Very high High (system level)

The choice of method depends on your goals. If you just need to remove ads from your browser and apps, use DNS or VPN. If you are a developer and testing domain redirection for your application, then editing the hosts file will be the only correct solution.

Common problems and ways to solve them

When working with Android network settings, users often encounter a number of common problems. One of the most common is the lack of effect after editing. This often happens if there is a syntax error in the file, for example, extra spaces or missing indentation between the IP address and the domain.

Another problem is conflicts with security applications or antiviruses, which can block changes to system files or mark modified hosts as a threat. It is also worth considering that some applications use their own DNS bypass methods and can ignore the system hosts file by accessing IP addresses directly or using encrypted channels.

  • โŒ The file is not saved: Check if the mode is switched to R/W and if there is free space in the system section.
  • ๐ŸŒ The Internet disappeared completely: Most likely, a critical one is blocked by mistake system domain (for example, google.com or time server).
  • ๐Ÿ”„ Changes were reset: the system was updated or the recovery partition was overwritten.

If the Internet stopped working after the edits, the first thing you need to do is restore the original hosts file from backup. If there is no backup, you can try to delete the hosts file completely (only if you have root), and the system will create a new default one upon reboot, or return the standard content manually.

โš ๏ธ Attention: Blocking system update domains or Google Play services can lead to incorrect operation of the application store, contact synchronization and other important functions. Block only what you are sure of.

๐Ÿ’ก

Restoring the original hosts file is the first action in case of any problems with connecting to the network after editing.

FAQ: Frequently asked questions

Is it possible to edit hosts on Android without root access?

There is no direct way to change the system file /system/etc/hosts without root access due to security restrictions of the Linux kernel. However, you can achieve a similar effect (ad blocking) through Private DNS settings or local VPN applications that do not require superuser rights.

Where is hosts on Android 12, 13, 14?

The location of the file has not changed since earlier versions of Android. The path remains the same: /system/etc/hosts. The changes concern only access methods and memory protection mechanisms, which become stricter with each OS version.

How to reset the hosts file to factory settings?

To reset, you need to open the file with any text editor with root access and leave only one line: 127.0.0.1 localhost. All other entries should be deleted or commented out with the #symbol. After this, the device must be rebooted.

Why does the hosts file not block advertising on YouTube?

YouTube and many modern services use complex mechanisms for delivering advertising from the same domains as the main content, or via a CDN. Blocking such domains via hosts will disrupt the operation of the application itself. To block ads in such cases, modified versions of applications or complex traffic filtering rules are required.

Is it safe to download a ready-made hosts file from the Internet?

Downloading ready-made hosts files from unverified sources is dangerous. Attackers can implement rules there that redirect banking application traffic to phishing servers. Use only verified lists (for example, from the AdAway community) or create them yourself.