1. Download our Official Android App: Forums for Android!

Can't find hosts file of a rooted phone

Discussion in 'Android Rooting' started by andfo, Jan 4, 2016.

  1. andfo

    andfo Member
    Thread Starter
    Rank:
     #363
    Points:
    38
    Posts:
    55
    Joined:
    May 26, 2015

    May 26, 2015
    55
    14
    38
    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?
     

    Advertisement

    scary alien likes this.
  2. scary alien

    scary alien not really so scary
    Moderator
    Rank:
     #8
    Points:
    2,138
    Posts:
    22,295
    Joined:
    Mar 5, 2010

    Mar 5, 2010
    22,295
    23,674
    2,138
    Male
    space alien ;)
    Indy
    Lemme dig my GNex out when I get home and I'll have a peek on it for that.

    This rings a bell, but maybe it's just hidden/buried?

    Can you try:

    (using either an adb shell or Android Terminal Emulator):

    $ su
    # find / -name '*hosts*' 2> /dev/null
     
    codesplice, andfo and lunatic59 like this.
  3. svim

    svim Android Expert
    Rank:
     #45
    Points:
    608
    Posts:
    3,866
    Joined:
    Dec 19, 2013

    Dec 19, 2013
    3,866
    2,875
    608
    Illinois
    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.
     
  4. andfo

    andfo Member
    Thread Starter
    Rank:
     #363
    Points:
    38
    Posts:
    55
    Joined:
    May 26, 2015

    May 26, 2015
    55
    14
    38
    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?

     
  5. scary alien

    scary alien not really so scary
    Moderator
    Rank:
     #8
    Points:
    2,138
    Posts:
    22,295
    Joined:
    Mar 5, 2010

    Mar 5, 2010
    22,295
    23,674
    2,138
    Male
    space alien ;)
    Indy
    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.
     
    andfo and lunatic59 like this.
  6. andfo

    andfo Member
    Thread Starter
    Rank:
     #363
    Points:
    38
    Posts:
    55
    Joined:
    May 26, 2015

    May 26, 2015
    55
    14
    38
    @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?
     
    scary alien likes this.
  7. scary alien

    scary alien not really so scary
    Moderator
    Rank:
     #8
    Points:
    2,138
    Posts:
    22,295
    Joined:
    Mar 5, 2010

    Mar 5, 2010
    22,295
    23,674
    2,138
    Male
    space alien ;)
    Indy
    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)).
     
    andfo and lunatic59 like this.
  8. lunatic59

    lunatic59 Moderati ergo sum
    Moderator
    Rank:
     #2
    Points:
    4,238
    Posts:
    36,968
    Joined:
    Jun 12, 2010

    Jun 12, 2010
    36,968
    35,414
    4,238
    Male
    IT
    Pennsylvania
    And of course you are going to backup the original hosts file before you start editing it, right? *cough*
     
  9. andfo

    andfo Member
    Thread Starter
    Rank:
     #363
    Points:
    38
    Posts:
    55
    Joined:
    May 26, 2015

    May 26, 2015
    55
    14
    38
    It can't even connect to Play Store.. :(

    It's connected to Internet but it either can't open it or if it's lucky it displays Play Store after several minutes.

    I don't if this is because this is Galaxy Nexus which is an old phone...
     
  10. scary alien

    scary alien not really so scary
    Moderator
    Rank:
     #8
    Points:
    2,138
    Posts:
    22,295
    Joined:
    Mar 5, 2010

    Mar 5, 2010
    22,295
    23,674
    2,138
    Male
    space alien ;)
    Indy
    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.
     
    andfo and svim like this.
  11. scary alien

    scary alien not really so scary
    Moderator
    Rank:
     #8
    Points:
    2,138
    Posts:
    22,295
    Joined:
    Mar 5, 2010

    Mar 5, 2010
    22,295
    23,674
    2,138
    Male
    space alien ;)
    Indy
    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?

    :)
     
    #11 scary alien, Jan 4, 2016
    Last edited: Jan 6, 2016
    andfo, Lordvincent 90 and lunatic59 like this.
  12. andfo

    andfo Member
    Thread Starter
    Rank:
     #363
    Points:
    38
    Posts:
    55
    Joined:
    May 26, 2015

    May 26, 2015
    55
    14
    38
    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
     
  13. scary alien

    scary alien not really so scary
    Moderator
    Rank:
     #8
    Points:
    2,138
    Posts:
    22,295
    Joined:
    Mar 5, 2010

    Mar 5, 2010
    22,295
    23,674
    2,138
    Male
    space alien ;)
    Indy
    Ah, do you have USB debugging enabled (Settings -> Developer options -> USB debugging checked)?

    Also, you might need the proper adb USB drivers...see this post (the Naked Samsung driver will probably be your best bet).
     
    andfo and lunatic59 like this.
  14. andfo

    andfo Member
    Thread Starter
    Rank:
     #363
    Points:
    38
    Posts:
    55
    Joined:
    May 26, 2015

    May 26, 2015
    55
    14
    38
  15. scary alien

    scary alien not really so scary
    Moderator
    Rank:
     #8
    Points:
    2,138
    Posts:
    22,295
    Joined:
    Mar 5, 2010

    Mar 5, 2010
    22,295
    23,674
    2,138
    Male
    space alien ;)
    Indy
    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.
     
    andfo likes this.
  16. andfo

    andfo Member
    Thread Starter
    Rank:
     #363
    Points:
    38
    Posts:
    55
    Joined:
    May 26, 2015

    May 26, 2015
    55
    14
    38
    Oh I got your response now. I will try that.
     
  17. andfo

    andfo Member
    Thread Starter
    Rank:
     #363
    Points:
    38
    Posts:
    55
    Joined:
    May 26, 2015

    May 26, 2015
    55
    14
    38
    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..
     
  18. scary alien

    scary alien not really so scary
    Moderator
    Rank:
     #8
    Points:
    2,138
    Posts:
    22,295
    Joined:
    Mar 5, 2010

    Mar 5, 2010
    22,295
    23,674
    2,138
    Male
    space alien ;)
    Indy
    The link I posted above also has a "spoiler" tag with driver installation instructions (I can't believe I actually already had that in there :p).
     
    andfo likes this.
  19. andfo

    andfo Member
    Thread Starter
    Rank:
     #363
    Points:
    38
    Posts:
    55
    Joined:
    May 26, 2015

    May 26, 2015
    55
    14
    38
    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:
     
  20. scary alien

    scary alien not really so scary
    Moderator
    Rank:
     #8
    Points:
    2,138
    Posts:
    22,295
    Joined:
    Mar 5, 2010

    Mar 5, 2010
    22,295
    23,674
    2,138
    Male
    space alien ;)
    Indy
    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!
     
    andfo likes this.
  21. scary alien

    scary alien not really so scary
    Moderator
    Rank:
     #8
    Points:
    2,138
    Posts:
    22,295
    Joined:
    Mar 5, 2010

    Mar 5, 2010
    22,295
    23,674
    2,138
    Male
    space alien ;)
    Indy
  22. andfo

    andfo Member
    Thread Starter
    Rank:
     #363
    Points:
    38
    Posts:
    55
    Joined:
    May 26, 2015

    May 26, 2015
    55
    14
    38
    I installed it but still there is no Other Devices or Galaxy in the Device Manager. And Windows still can't recognize it..
     
  23. andfo

    andfo Member
    Thread Starter
    Rank:
     #363
    Points:
    38
    Posts:
    55
    Joined:
    May 26, 2015

    May 26, 2015
    55
    14
    38
    Where in my PC does this msi file install the driver?
     
  24. andfo

    andfo Member
    Thread Starter
    Rank:
     #363
    Points:
    38
    Posts:
    55
    Joined:
    May 26, 2015

    May 26, 2015
    55
    14
    38
    It seems it's still using old driver. Device Manager says it already has best driver so won't update driver. "The best driver software for your device is already installed"

    hmmm.. so strange..
     
  25. Lordvincent 90

    Lordvincent 90 ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
    Rank:
    None
    Points:
    583
    Posts:
    5,559
    Joined:
    Oct 5, 2011

    Oct 5, 2011
    5,559
    4,444
    583
    Male
    entertainer
    grand rapids,mi
    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 (Text):
    1. adb pull /system/etc/hosts
     
    scary alien likes this.

Share This Page

Loading...