[CentOS] Prevent network setup from changing the hostname

Mon Apr 27 00:57:03 UTC 2015
Peter Larsen <peter at peterlarsen.org>

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:

send dhcp-client-identifier = hardware;
request subnet-mask, broadcast-address, time-offset, routers,
                domain-search, domain-name, domain-name-servers, host-name;

Just take out the host-name and you won't get (a new) one. You should
however make sure that all your servers have a hostname configured
before you do that. /etc/sysconfig/network is where you do that on CentOS6.

> Making my wireless connection a system connection increases the
> exposure of my WPA key and doesn't solve the problem of the network
> configuration changing, perhaps because I connected or disconnected
> an ethernet cable or the machine went to sleep on one WLAN and woke
> up on another.

So your key isn't visible and only root can change a system device.  A
system device gets activated before the desktop. So you're not depending
on having access to gconf etc.
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/sec-User_and_System_Connections.html
>
> Do you know of a place I can set a static name that NetworkManager
> won't override?  That would be ideal.  I just doesn't make sense
> that the machine's internal relationships would depend on its
> external connections.
>

See above. It's standard dhclient options.

-- 
Regards
  Peter Larsen