7

For windows machine we got the hosts file to edit to redirect url's to other domains. Is there a file like that on android?

I'm looking to redirect a very long url to a shorter one using the hosts file, is this possible? This can also be used to redirect a list of known spam domains to nothing so the worst flash/gif adds are removed.

I'm running Android 2.1 on a rooted samsung galaxy S

1
  • It should be possible since there is the "AdFree" app for rooted users. It doesn't look to be open source, however...
    – Bryan Denny
    Commented Oct 6, 2010 at 15:33

1 Answer 1

6

The original link is dead. I pulled this short guide from way back machine, copied here:

With the first few official Pre-Alpha builds of CyanogenMod 7 being released, it’s worth noting that a new feature has been included that allows you to change the hostname on your device from the Settings menu. If you have a supported device, you can get the nightly builds from the TeamDouche Mirror System. Once you’ve flashed (I take no responsibility if you break something – make sure to read up on issues/pitfalls/requirements before flashing), open the Settings menu, then choose Applications, then Development, and select Device Hostname at the bottom. This setting persists between reboots and ROM upgrades (unless you wipe).

Warning: I accept no responsibility if you brick your phone while doing this.

I ditched my iPhone due to problems my local provider was having and got an HTC Dream instead. I promptly rooted it using the Cyanogen Mod, but noticed that by default, Android reports the hostname as ‘localhost’. I don’t really like this, so I set about finding an easy way to change it.

First off, even rooted, the / partition is mounted read-only when you boot normally, so you need to boot to Recovery Mode (Home+Power). In the recovery menu, choose to boot to console. From there, browse to /system/etc/init.d.

IMPORTANT: Make a backup of ’05userinit’ before continuing! You can do this by simply running the following command – ‘cp 05userinit /05userinit’ (without quotes). This will create a copy of it in the / directory. If you screw up your editing, you can just rm the messed up version and cp the backup back in.

To add the command to set the host name, we’re simply going to echo in the following two lines:

echo  >> 05userinit

echo hostname NEWHOSTNAME >> 05userinit

Note that there are two spaces after the first ‘echo’ command. This creates a blank line at the end of the file. The second echo adds the hostname command. This way, whenever your phone boots, the hostname is set. Also, be sure to use two greater-than signs (>), as that appends – if you only use one, it overwrites the contents of the file.

Make sure the edits are correct by typing ‘tail 05userinit’ – as long as it isn’t blank, and there’s more than just the hostname line, you’re golden. Reboot the phone by typing ‘reboot’ at the prompt and hitting ‘Enter’, and you’re done.

Once you’ve booted back up, open up your terminal emulator of choice and type ‘hostname’ (by itself, no parameters) – it should echo out whatever hostname you specified.

Update (April 6th, 2010): To change your hostname on Cyanogen 5.x, add the following line to the bottom of /system/etc/init.d/01sysctl — and make sure you make a backup of 01sysctl before editing it!

echo NEWHOSTNAME > /proc/sys/kernel/hostname
1
  • 3
    Just to clarify, this is only possible on rooted phones. should we add that to the tags? Commented Oct 6, 2010 at 21:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .