Re: changing hostname
On Fri, 25 Mar 2005, Paul J. Lucas wrote:
... but 'uname -n' still prints the old hostname. Is a reboot
necessary?
Well, it seems that there's a sethostname(2) call, but
apparently no command for calling it; so I wrote as a quick
hack:
#include <unistd.h>
#include <string.h>
main() {
char *hostname = "new_hostname_goes_here";
int err = sethostname( hostname, strlen( hostname ) );
if ( err )
perror( "sethostname" );
}
Running it as root then doing 'uname -n' seems to have worked.
But is there a better/canonical way to do this?
- Paul
Reply to: