[CentOS] Prevent network setup from changing the hostname

Mon Apr 27 01:28:56 UTC 2015
Peter Larsen <peter at peterlarsen.org>

On 04/26/2015 09:19 PM, Robert Nichols wrote:
> On 04/26/2015 07:57 PM, Peter Larsen wrote:
>> On 04/26/2015 08:25 PM, Robert Nichols wrote:
>>> On 04/26/2015 06:31 PM, Peter Larsen wrote:
>>>> On 04/26/2015 07:26 PM, Robert Nichols wrote:
>>>>> How can I block network setup (via NetworkManager) from changing
>>>>> the machine's hostname whenever the network configuration changes?
>>>>
>>>> Make it a system connection instead of a user connection. Or give the
>>>> host a static name on install and don't allow dhcp to override it.
>>>
>>
>> If you move networks and you are slaving your hostname to the DHCP
>> offered name, then yes. But why do that?  In /etc/dhcp/dhclient.conf you
>> can configure exactly what you want and don't want from the server.
>> There's a lot of options (man dhclient.conf is very helpful) but here's
>> an example:
>
> NetworkManager invokes dhclient with a generated config file that
> ignores /etc/dhcp/dhclient.conf:
>
>      dhclient ... -cf /var/run/nm-dhclient-wlan0.conf ...

Well, true to a degree. Put the file in /etc/dhcp/dhclient.d and it'll
be executed. Just make sure the script out-puts to stdout what goes into
the dhclient configuration file used by NetworkManager.

>
> I ran across another report that suggests setting HOSTNAME to
> something other than "localhost.localdomain" in
> /etc/sysconfig/network would fix the problem.  For the moment,
> that seems to be working.
>
Strange - you may have a dhcp server that accepts host names from the
clients - which of course would fit your use case. Just realize that not
all dhcp servers are setup to be that "lenient" when it comes to
preserving the host name picked by a client.

But I am happy you got it working.

-- 
Regards
  Peter Larsen