NetworkManger to set the device's hostname
0
votes
0
answers
126
views
We have a dhcp server (linux) to serve a few printers Nuc devices.
It is configured to assign IPv4 address, gateway, dns1, dns2, dns3, dns4, ntp1, ntp2, dns-search domains, domain suffix and hostname based on the pool.
1 Pool: Printers
2 Pool: TV (Nuc devices)
3 Pool: guests
Each pool has an entry to assign a host name to a device like [p|tv|g]-lvl(n)-[NNN].
For the tv pool we have the following hostname pattern: tv-lvl(n)-[NNN] where (n) is the the floor level and [NNN] the last 1 to 3 digits of the IP address (ex.: tv-lvl1-180.
While installing linux we don't confiugre hostname and leave it to the default (localhost), then with a shell script we configure the network connection to get DHCP settings as configured from the dchp server. However the hostname of the device remains localhost.
Here is what the script does(Please note not the actual code):
nmcli connection modify id 'Wired Connection 1' ipv4.addresses ""
nmcli connection modify id 'Wired Connection 1' ipv4.gateway ""
nmcli connection modify id 'Wired Connection 1' ipv4.dns ""
nmcli connection modify id 'Wired Connection 1' ipv4.dns-search ""
nmcli connection modify id 'Wired Connection 1' ipv4.method auto
nmcli connection modify id 'Wired Connection 1' autoconnect yes
nmcli connection modify id 'Wired Connection 1' hostname.from-dhcp true
nmcli connection modify id 'Wired Connection 1' hostname.only-from-default true
nmcli connection modify id 'Wired Connection 1' hostname.from-dns-lookup true
then we reboot and the device get the correct IP settings.
I can ping the device from anywhere like
ping tv-lvl1-180
with no issues and I can even ssh the device ssh tv-lvl1-180
however the prompt remains as:
user@localhost: ~$
How to make the assigned hostname the actual hostname of the device?
From user@localhost: ~$
to user@tv-lvl1-180: ~$
In case that the following is needed here is what we get when we run:
user@localhost:~$ hostname
localhost
user@localhost:~$ hostnamectl
Static hostname: localhost
Pretty hostname: linuxmint <- We changed it for other reasons.
Icon name: computer-desktop
[...]
user@localhost:~$ cat /etc/hostname
localhost
user@localhost:~$
Asked by raism
(11 rep)
Nov 7, 2024, 06:18 PM
Last activity: Nov 8, 2024, 12:11 AM
Last activity: Nov 8, 2024, 12:11 AM