[SOLVED] Make systemd change hostname without logging out
Linux - DesktopThis forum is for the discussion of all Linux Software used in a desktop context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
at n-1-th startup, environment variables are set at n-1-th value
reboot
n-th startup
n-1-th values are read in /etc/hostname and then hostname is set to name@n-1
correct n-th values are read with read_variables.service and put in environment_output
correct hostname is set in /etc/hostname
But hostname is not modified on the fly so I will have hostname@n-1 instead of hostname@n
So my question is how to run these scripts before systemd prints the line:
At this point I have to point out that on the server the hostname serves several purposes and the host can have only one. On the network the host name can be totally different, or it can even have more than one, and represents the interface it has onto the network. DHCP clients allow you to specify the hostname to be used on the network, and it need not be the same as the name by which the host knows itself.
I would really like to understand the purpose, so we can address the need instead of only the literal question.
Thank you, I have resolved using hostnamectl set-hostname script launched on a script referred by a systemd service, and adding some SELinux rules.
The need for such a task was due to a job assignment in order to know on ssh prompt the IP of the macchine connected to, even if It was a bit redundant with the fact that the IP can be known with ifconfig, but I had to do it so...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.