When I change the hostname of a server using "hostname NewHostName", the hostname entry in /etc/rc.conf is not updated to reflect the new name. This is likely to be highly confusing to both newbies and users with no previous experience with this behaviour. The script fragment below will do the job. And it might be executed from the hostname program, but it might not be paranoid enough since it contains no error detection. nl=$'\n' rcCont=`grep -v "^hostname=" /etc/rc.conf` rcCont="${rcCont}${nl}hostname=\"NewHostName\"${nl}" echo "${rcCont}" > /etc/rc.conf
This is intended. Please see sysrc(8) to configure hostname or other rc.conf variable.
See man page for hostname command. It does not say that the change is temporary.