Bug 221951 - hostname does not update /etc/rc.conf with new hostname
Summary: hostname does not update /etc/rc.conf with new hostname
Status: Closed Not A Bug
Alias: None
Product: Base System
Classification: Unclassified
Component: arm (show other bugs)
Version: 11.1-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-arm (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-31 09:50 UTC by Tarjei Jensen
Modified: 2017-08-31 21:33 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tarjei Jensen 2017-08-31 09:50:13 UTC
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
Comment 1 Emmanuel Vadot freebsd_committer freebsd_triage 2017-08-31 09:56:51 UTC
This is intended.
Please see sysrc(8) to configure hostname or other rc.conf variable.
Comment 2 Tarjei Jensen 2017-08-31 21:33:42 UTC
See man page for hostname command.

It does not say that the change is temporary.