From 038edc961dbf6d265f5bce5dc2b4361a6740a917 Mon Sep 17 00:00:00 2001 From: DocRock3r Date: Wed, 23 Apr 2025 19:14:49 +0000 Subject: [PATCH] Add Scripts/change_hostname.sh Signed-off-by: DocRock3r --- Scripts/change_hostname.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Scripts/change_hostname.sh diff --git a/Scripts/change_hostname.sh b/Scripts/change_hostname.sh new file mode 100644 index 0000000..0c6be60 --- /dev/null +++ b/Scripts/change_hostname.sh @@ -0,0 +1,26 @@ +#! /bin/bash + +clear + +#get current hostname and set it as value of old_host +old_host=$(hostname) + +#make backups for hostname and hosts files +cp /etc/hostname /etc/hostname.bk +cd /etc/hosts /etc/hosts.bk + +#ask user for new host name and set it as value for new_host +printf "%s\n" "Hostname must be between 1-63 characters long" +printf "%s\n" "Valid characters are (lower case a-z), (0-9), and (-)" +printf "%s" "enter new hostname: " +read new_host + +#replace old_host with new_host in hostname and hosts files +#set hostname to new_host +sed -i 's/'$old_host'/'$new_host'/' /etc/hostname +sed -i 's/'$old_host'/'$new_host'/' /etc/hosts +hostname $new_host + +#confirm change and tell user to restart system +printf "%s\n" "Hostname changed from [$old_host] to [$new_host]" +printf "%s\n" "Reboot your system for the change to take effect" \ No newline at end of file