mirror of
https://gitlab.isc.org/isc-projects/dhcp
synced 2025-08-30 22:05:23 +00:00
[!99] replace hostname
with uname -n
& hostnamectl
The former belongs to package `inetutils`, which has some security implications, so let's use `uname` from `coreutils` to get the hostname. For *setting* the hostname things are more limited. Let's use `hostnamectl` from `systemd` if available. Fall back to `hostname`, then `sysctl`.
This commit is contained in:
@@ -113,7 +113,7 @@ set_hostname() {
|
||||
local current_hostname
|
||||
|
||||
if [ -n "$new_host_name" ]; then
|
||||
current_hostname=$(hostname)
|
||||
current_hostname=$(uname -n)
|
||||
|
||||
# current host name is empty, '(none)' or 'localhost' or differs from new one from DHCP
|
||||
if [ -z "$current_hostname" ] ||
|
||||
@@ -121,7 +121,13 @@ set_hostname() {
|
||||
[ "$current_hostname" = 'localhost' ] ||
|
||||
[ "$current_hostname" = "$old_host_name" ]; then
|
||||
if [ "$new_host_name" != "$old_host_name" ]; then
|
||||
hostname "$new_host_name"
|
||||
if command -v hostnamectl >/dev/null; then
|
||||
hostnamectl set-hostname --transient "$new_host_name"
|
||||
elif command -v hostname >/dev/null; then
|
||||
hostname "$new_host_name"
|
||||
else
|
||||
sysctl -w kernel/hostname="$new_host_name"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
Reference in New Issue
Block a user