更新 simpleadmin/console/menu/change_hostname.sh

This commit is contained in:
sky 2024-12-13 21:28:40 +08:00
parent 9eb51b22be
commit 4b68890429

View File

@ -34,6 +34,26 @@ remount_rw
echo "$new_hostname" > /etc/hostname
sed -i "s/127.0.1.1.*$/127.0.1.1\t$new_hostname/g" /etc/hosts
hostname "$new_hostname"
# Create and enable the hostname service
cat > /lib/systemd/system/set-hostname.service << EOF
[Unit]
Description=Set system hostname at boot
After=network.target
[Service]
Type=oneshot
ExecStart=/bin/sh -c 'hostname \$(cat /etc/hostname)'
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable set-hostname.service
systemctl start set-hostname.service
remount_ro
echo -e "\033[0;32mHostname has been changed to: $new_hostname\033[0m"