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
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
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