更新 simpleadmin/console/menu/change_hostname.sh
This commit is contained in:
parent
9eb51b22be
commit
4b68890429
@ -34,6 +34,26 @@ remount_rw
|
|||||||
echo "$new_hostname" > /etc/hostname
|
echo "$new_hostname" > /etc/hostname
|
||||||
sed -i "s/127.0.1.1.*$/127.0.1.1\t$new_hostname/g" /etc/hosts
|
sed -i "s/127.0.1.1.*$/127.0.1.1\t$new_hostname/g" /etc/hosts
|
||||||
hostname "$new_hostname"
|
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
|
remount_ro
|
||||||
|
|
||||||
echo -e "\033[0;32mHostname has been changed to: $new_hostname\033[0m"
|
echo -e "\033[0;32mHostname has been changed to: $new_hostname\033[0m"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user