Hostname

Da PNLUG.

Questo piccolo script rendere facile ed interattivo il cambio del hostname

Debian Like

#!/bin/bash
#
#Assign existing hostname to $hostn
hostn=$(cat /etc/hostname)
#
#Display existing hostname
echo "Existing hostname is $hostn" 
#
#Ask for new hostname $newhost
echo "Enter new hostname: "
read newhost
#
#change hostname in /etc/hosts & /etc/hostname
sed -i "s/$hostn/$newhost/g" /etc/hosts
sed -i "s/$hostn/$newhost/g" /etc/hostname
#
#display new hostname
echo "Your new hostname is $newhost"