Depends on which version of Android you have. Newer versions will use the right
build.prop entry. Well, that is to say, Android reads the
build.prop as it's normal boot process. Once the Connectivity Service runs, it checks to see if net.hostname is set in the Settings, then if empty, then it uses the "android_" + (permanent) android ID. So that's all you need to do. Add
/system/build.prop. Leave a blank line at the end of the file.
Older versions, Gingerbread, Froyo, etc, just clobber it. It doesn't bother to check. It will set net.hostname to android_24412414... no matter what. So you will need to change it after that Connectivity Service has finished loading. Luckily, it only runs the startup once, not on every new connection. So we just need to run
setprop net.hostname HOSTNAMEHERE after that for it to stick. Unfortunately, it runs fairly late in the boot process, so you need something that will make the changes on boot_complete. Most likely an App that runs by itself.
But then there is another issue. The net.hostname setting, is not copied to the entire system! If you use a console/terminal application, you might not get the same hostname. My phone, a Samsung Sidekick 4G (semi-Galaxy S based) has an init.rc which runs
hostname localhost, so all underneath commands will not see either your build.prop hostname or the android_id hostname! So you need to set that too.
hostname HOSTNAMEHERE or
echo HOSTNAMEHERE > /proc/sys/kernel/hostname
Note: Depending on how you are doing it, you'll need to run the above command as root in order for it to work. Init.rc is typically on the read only system partition, so root access is needed to edit it.
The dhcpcd command, which is run to get a dhcp address, will not update to a hostname provided by the server (That can be fixed by adding the right dhcpcd-run-hooks and dhcpcd.conf), and it will not provide a hostname to the dhcp server if $(hostname) is blank or localhost, and it does not internally use net.hostname. libnetutils is used for calling dhcpcd with -h "net.hostname", but if for some reason it decides not to call with -h, DHCPCD WILL STILL SEND THE SYSTEM HOSTNAME via gethostname(), as long as it's not "(none)","localhost", or empty. On Stock Froyo anyway. Samsung screwed the pooch on some devices like mine. No hostname pass through, forced network time, etc.
The last thing you can do is edit /etc/dhcpcd/dhcpcd.conf. If you add
hostname YOURHOSTNAME to the file, it will use that, unless a hostname is given on the commandline. This won't fix the android_234etc issue, but will if the hostname is localhost (My problem, since Samsung screwed libnetutils and localhost in init.rc). You will need Root, but this works across reboots.