Changing hostname and IP after setup

Hostname refuses to change after setup

Sometimes, i have very interesting circumstances whereby during a setup of a Mac cluster, i find that the hostname of the management node needs to be changed. However, after changing the computer name and the sharing name, the hostname command continues to provide the old hostname which is then wrong.

The below methods will then do the trick.

  • To change only the host name
    changeip - current-ip-address current-ip-address current-host-name new-host-name
    /System/Library/ServerSetup/serversetup -setComputername new-host-name
    /System/Library/ServerSetup/serversetup -setBonjourname new-host-name
    reboot
  • To change only the IP address
    changeip - current-ip-address new-ip-address
    /System/Library/ServerSetup/serversetup -setInfo en0 new-ip-address new-netmask new-router 
    reboot
  • Both
    changeip - current-ip-address new-ip-address current-host-name new-host-name
    /System/Library/ServerSetup/serversetup -setComputername new-host-name
    /System/Library/ServerSetup/serversetup -setBonjourname new-host-name
    /System/Library/ServerSetup/serversetup -setInfo en0 new-ip-address new-netmask new-router
    reboot