• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Can't find hosts file of a rooted phone

andfo

Member
May 26, 2015
75
18
I bought https://swappa.com/listing/MBS496/view

from Swappa.

It is Galaxy Nexus (Not just Nexus) used phone.

He said it was already rooted.

I just got the phone and opened the File Manager and ES File Explorer but I can't find hosts file!

This link (http://www.techrepublic.com/article/edit-your-rooted-android-hosts-file-to-block-ad-servers/) says the hosts file will be at system/etc

But I get zero results if I search for "hosts". If I search for "etc", the folder is in very strange place. I get zero results if I search for "system".


Can it be the case that this phone doesn't have hosts file?

The only purpose of buying this cheat-and-rooted phone was to gain access to hosts file to block useless websites like facebook.

I need to find and edit that hosts file.. Does anyone know a solution to this?
 
  • Like
Reactions: scary alien
But I get zero results if I search for "hosts". If I search for "etc", the folder is in very strange place.

Instead of doing a search, do you see a 'hosts' file if you actually use a file manager to navigate to the /system/etc directory? Also keep in mind you need to be looking at the root level partition. (A search probably didn't work because that partition normally isn't indexed.)
As far as the etc directory, there's actually going to be several. There's a main /etc directory for the Android operating system itself along with others that some individual system processes and some apps have inside their own directories. An etc directory is just common place to keep settings and configuration files.
 
Upvote 0
I cannot even find any folder named "system".

This is a used phone I bought from Swappa and the seller said "Unlocked and rooted running Cyanogenmod 10.2.1"

Is this the problem?

Instead of doing a search, do you see a 'hosts' file if you actually use a file manager to navigate to the /system/etc directory? Also keep in mind you need to be looking at the root level partition. (A search probably didn't work because that partition normally isn't indexed.)
As far as the etc directory, there's actually going to be several. There's a main /etc directory for the Android operating system itself along with others that some individual system processes and some apps have inside their own directories. An etc directory is just common place to keep settings and configuration files.
 
Upvote 0
I cannot even find any folder named "system".

This is a used phone I bought from Swappa and the seller said "Unlocked and rooted running Cyanogenmod 10.2.1"

Is this the problem?

Well, CyanogenMod is a modded version of Android and is not stock Android.

I think I wiped the CM I had installed on my test N5 the other day, so I can't look for the corresponding file for you in there.

If you do navigate to the root filesystem ("/") you should be able to see a "/system" partition regardless of what version of Android you're running.

Try doing the commands I posted above and see (and post) what is returns.
 
  • Like
Reactions: andfo and lunatic59
Upvote 0
@scary_alien

Thank you!. I did the code you told me.

Now the last two lines are

/system/etc/hosts
root@toro: / #


It reads like it has found hosts file. Now how can I open the hosts file like a text file and edit the hosts file?

Nice! :)

Yeah, that's a typical location for the hosts file (as @svim indicated).

A root file browser like Root Explorer should allow you to edit that (you may have to first remount /system in read-write mode (it may prompt you if that's necessary)).
 
  • Like
Reactions: andfo and lunatic59
Upvote 0
Are you conversant with the adb utility, @andfo?

(I wasn't sure how you did the find command above).

If so, it would be relatively straightforward to have you pull the file from your device down to your PC, edit it on your PC, remount /system in read-write mode, and replace the file.

Lemme know and I'll prep a quick tutorial for you.
 
  • Like
Reactions: andfo and svim
Upvote 0
Here's an adb tutorial if you need:

### first, grab a copy of the current hosts file

c:\> adb pull /system/etc/hosts hosts
2 KB/s (25 bytes in 0.009s)​

### now, grab it again for a safety, backup copy

c:\> adb pull /system/etc/hosts original-hosts # we won't mess with this one ;)
4 KB/s (25 bytes in 0.006s)​

### examine the current file

c:\> cat hosts
127.0.0.1 localhost

### I'm just going to add to the file from the shell prompt; you'll probably want to use and editor

c:\> echo "173.194.46.72 google.com" >> hosts

### check out what we've done

c:\> cat hosts
127.0.0.1 localhost
173.194.46.72 google.com

### now, let's send the updated file back to our SD card on the GNex

c:\> adb push hosts /sdcard/new-hosts
8 KB/s (68 bytes in 0.008s)​

### okay, now we need to muck-around in a shell prompt

c:\> adb shell

### first, become root

shell@android:/ $ su

### let's check to see how /system is currently mounted (likely ro (read-only))

root@android:/sdcard # mount | grep /system
/dev/block/platform/omap/omap_hsmmc.0/by-name/system /system ext4 ro,relatime,barrier=1,data=ordered 0 0

(note, you might not have the grep command installed; so you can just use the mount command and look for the line with the /system partition name on it)

### this command will actually remount the filesystem in read-write mode

root@android:/sdcard # mount -o remount,rw /system

### check it now to make sure /system is now mounted rw (read-write)

root@android:/sdcard # mount | grep /system
/dev/block/platform/omap/omap_hsmmc.0/by-name/system /system ext4 rw,relatime,barrier=1,data=ordered 0 0

### if you see "rw" now, let's go-ahead & make a backup and replace the hosts file w/our new one

root@android:/sdcard # cd /system/etc
root@android:/system/etc # ls -l hosts
-rw-r--r-- root root 25 2012-08-06 16:57 hosts

### rename the current to a backup/orignal name

root@android:/system/etc # mv hosts hosts-original

### replace the contents of the hosts with the one on the /sdcard

root@android:/system/etc # cat /sdcard/new-hosts > hosts

### make sure it's secured properly

root@android:/system/etc # chmod 644 hosts
root@android:/system/etc # cat hosts
127.0.0.1 localhost
173.194.46.72 google.com

root@android:/system/etc # ls -l hosts
-rw-r--r-- root root 68 2016-01-04 21:05 hosts
root@android:/system/etc #​

Questions?

:)
 
Last edited:
Upvote 0
Yeah, you can't see the internal memory (where the /system filesystem lives) using a Windows Explorer file manager...it's a protected area that's not visible via that way.

That's why you have use a rooted file browser on your device or follow the adb instructions I provided above.

I do think there are adb-based file browsers for your PC that might work, but I've no knowledge or personal experience.
 
  • Like
Reactions: andfo
Upvote 0
Thank you again.

I checked USB debugging but it still says "error: device not found"

So I did "cd system", "cd etc", so that it becomes

:/system/etc $

Then I typed

abd pull hosts

But it still said

error:device not found


So I decided to install the Naked Samsung driver as you have told me. I downloaded it and opened on my PC but.. how do I install it to my phone? I just see some files like androidwinusba64 and so on..
 
Upvote 0
Thank you very much @scary alien for your continued guidance! I do really!

But I can't find "Other devices" in the device manager. Windows instead says device cannot be recognized.

I clearly see the green android laying down like he's dead with his belly opened. I also see the red words "FASTBOOT MODE"

I put the "Universal_Naked_Driver_0.72" folder in C:
 
Upvote 0
Ugh, I wrote that post back in late 2011 :eek:...and I haven't installed a USB driver for quite a while myself :p.

Just for grins and to rule-out other issues, have you tried a different USB cable and/or port? (although as I write that I realized that you've already been navigating your SD card from your PC, so the port and cable are probably okay).

I think Koush has published some universal USB drivers...lemme do a quick search for that...brb!
 
  • Like
Reactions: andfo
Upvote 0
Thank you very much! I am impressed!

However, when I do

$ adb pull /system/etc/hosts hosts

it only says

* daemon not running. starting it now on port 5038 *
* daemon started successfully *
error: device not found
Are you doing this from inside an adb shell? If so, that's probably why you are seeing this error...

Open your command prompt in the folder containing adb and just say
Code:
adb pull /system/etc/hosts
 
  • Like
Reactions: scary alien
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones