Why does my hostname keep changing
The computer's host name is the one you type in the "Sharing" system preferences, and while a change in the hostname should not affect the performance of the machine, it is nice to have it be consistent. The first thing to try is to use the "hostname" command to change the hostname:. After running this command, the terminal name will not change until you quit the current shell and log in again:. The hostname can be changed dynamically by routers and other network devices through DHCP requests, which can have the hostname keep changing every time your IP address and other DHCP information is renewed.
If this is the case, you may be able to set the router to never provide hostname information, or you can set the computer to never accept a hostname change. To do this, you will need to add a line to the computer's hostconfig file using the following procedure:.
You can rename a computer with the following PowerShell cmdlet:. First of all, any line in the hosts file that begins with is a comment and will be ignored. The file itself tells you this if you read it. Second, the hosts file has nothing to do with your computer's hostname. All you're doing is creating aliases that will only work on the machines you modify the hosts file on. You're not changing the hostname at all. Again, the hosts file tells you this if you read it. There's a "Rename this PC" button.
If you don't want to use that, then I recommend using the Rename-Computer Powershell command. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. So, What I'm trying to do is simply change the hostname permanently.
I can update the hostname but when a reboot is issued the original hostname is used! I update this file and issue a reboot, however the hostname is back to the previous setting! Why doesn't this work when connected to a remote server with SSH?
If you're trying to reach a host that's present there, it will use that record instead of querying DNS. Changing hostnames on Linux hosts can vary by distribution and release, so it's best to Google the procedure for your particular platform. Another reason why the host name gets reset could be the cloud-init package. This package is used to provision a host and can also be used to set the systems host name.
Setting this option to true , will let a newly set host name survive a reboot. Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? With that said, why does a machine need to have a hostname? Why does it care what it's hostname is if the DNS system will route requests to it anyway? Also, if I'm running a simple personal webserver, is it okay to just leave my hostname "local"?
Best practices dictate that you set your hostname to something meaningful - usually the FQDN of the server if the system has a role where it's associated with multiple FQDNs -- like a shared web hosting server -- you would typically set a hostname like webhosting As Nathan mentioned , some programs use the hostname for various purposes.
Having an unresolvable hostname can cause unpredictable behavior. When you are logged in to a machine its local hostname provides a convenient way to identify it. This is a good way to sanity check yourself before rebooting a host. It is also important in an environment with multiple machines -- systems all called local will get very confusing, but machines named web , mail , etc.
Also, a hostname makes identifying the box you're on easier. Adding a hostname is the best practice for any server. If you leave your host name to local, and you try to contact it's hostname via another computer, you might ping yourself as a result. Let me tell you, it made my life way harder than it should have been. If you don't do these right, your email will be marked as spam. Which matters, even for "simple" web servers that send mail.
Non-unique names are confusing, as others mentioned. It is NOT an absolute name for a machine.
0コメント