$ sudo ./customHostname.sh myHostname myDomain myIP
$ sudo ./customHostname.sh vito remibarbe.fr 45.132.12.35
Rémi Barbe (Remiii)
#!/bin/bash | |
if [ ${#} == 3 ] | |
then | |
echo "Updating..." | |
MY_HOSTNAME=${1} | |
MY_DOMAIN=${2} | |
MY_IP=${3} | |
echo "Hostname: "${MY_HOSTNAME} | |
echo "DOMAIN: "${MY_DOMAIN} | |
echo "IP: "${MY_DOMAIN} | |
# Set the hostname | |
sudo hostname ${MY_HOSTNAME} | |
sudo echo ${MY_HOSTNAME} > /etc/hostname | |
# Add fqdn to hosts file | |
sudo cat<<EOF > /etc/hosts | |
# This file is automatically genreated by customHostname.sh script | |
127.0.0.1 localhost | |
${MY_IP} ${MY_HOSTNAME}.${MY_DOMAIN} ${MY_HOSTNAME} | |
# The following lines are desirable for IPv6 capable hosts | |
::1 ip6-localhost ip6-loopback | |
fe00::0 ip6-localnet | |
ff00::0 ip6-mcastprefix | |
ff02::1 ip6-allnodes | |
ff02::2 ip6-allrouters | |
ff02::3 ip6-allhosts | |
EOF | |
else | |
echo "Bad number of arguments" | |
fi |