You are not logged in.
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
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
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