sudo nano /etc/hostname

Change ‘raspberrypi’ to your custom hostname. -x to exit. 'Y' to save.

sudo /etc/init.d/hostname.sh
sudo reboot

via: How-To Geek