standard

by thehousecat
2 deployments · 1 still active · last rev. 1 year ago

Set hostname and hosts (including ipv6 support)

Compatible with: Debian 7, Ubuntu 14.04 LTS, Ubuntu 12.04 LTS
						#!/bin/bash
# 
#<UDF name="hostname" label="Hostname">
# HOSTNAME= 
# 
#<UDF name="fqdn" label="FQDN">
# FQDN=

IPADDR=$(ip addr show dev eth0 | sed -e's/^.*inet \([^ ]*\)\/.*global.*$/\1/;t;d')
IP6ADDR=$(ip addr show dev eth0 | sed -e's/^.*inet6 \([^ ]*\)\/.*global.*$/\1/;t;d')
 
apt-get update 
apt-get upgrade -y
 
echo $HOSTNAME > /etc/hostname 
hostname -F /etc/hostname
 
echo $IPADDR $FQDN $HOSTNAME >> /etc/hosts
echo $IP6ADDR $FQDN $HOSTNAME >> /etc/hosts

echo "$HOSTNAME" > /etc/hostname
hostname -F /etc/hostname