You are not logged in.

#1 2017-04-30 02:22:23

ErSoul
Member
Registered: 2012-01-26
Posts: 54

Changing hostname when activating a NetworkManager connection

I'm trying to change my hostname when connected to a specified network with NM, but without success. I've placed my script in /etc/NetworkManager/dispatcher.d/pre-up.d/10-myscript, and it contains the following:

#!/bin/bash

HOST=someothername

if [ "$CONNECTION_UUID" = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx" ]; then
        hostname $HOST
        XID=$(xauth list | cut -d ' ' -f 5)
        xauth add "$HOST/:0 MIT-MAGIC-COOKIE-1 $XID"
fi

The permissions are setted as the wiki says: 755, and the owner is root:root.

The hostname never get changed...

Offline

#2 2017-04-30 07:55:50

woodape
Member
Registered: 2015-03-25
Posts: 159

Re: Changing hostname when activating a NetworkManager connection

You could check if the script is actually running by adding, for instance:

echo "is running" > /tmp/test

inside your if statement. In any case, shouldn't you need to change the value of /etc/hostname. Maybe try putting the following in the if block once you know its being executed:

echo "$HOST" > /etc/hostname

Offline

#3 2017-04-30 15:29:48

ErSoul
Member
Registered: 2012-01-26
Posts: 54

Re: Changing hostname when activating a NetworkManager connection

Hi woodape! It is indeed executing the script and entering the if-statement (good tip), nevertheless, it won't change the hostname.

Tried with

sysctl kernel.hostname=$HOST

Your proposal on changing the content of the file, is not what I'm looking for (and didn't work either). I just want to change the hostname on-the-fly, and when disconnecting from the specified network, change it to its normal value.

Last edited by ErSoul (2017-04-30 15:30:22)

Offline

Board footer

Powered by FluxBB