Skip to content

Instantly share code, notes, and snippets.

@vMarkusK
Created May 2, 2016 14:58
Show Gist options
  • Save vMarkusK/90ed5d3594770f74d1e786b84ea2df54 to your computer and use it in GitHub Desktop.
Save vMarkusK/90ed5d3594770f74d1e786b84ea2df54 to your computer and use it in GitHub Desktop.
ubuntu 16.04 Guest Customization Shell Script
#!/bin/bash
HOSTNAME=$1
IP=$2
SUBNET=$3
GATEWAY=$4
DOMAIN=$5
SEARCH=$6
DNS1=$7
DNS2=$8
rm -rf /etc/udev/rules.d/70-persistent-net.rules
echo $HOSTNAME > /etc/hostname
echo "# # This file is created by vCO" > /etc/network/interfaces
echo "" >> /etc/network/interfaces
echo "source /etc/network/interfaces.d/*" >> /etc/network/interfaces
echo "# The loopback network interface" >> /etc/network/interfaces
echo "auto lo" >> /etc/network/interfaces
echo "iface lo inet loopback" >> /etc/network/interfaces
echo "" >> /etc/network/interfaces
echo "# The primary network interface" >> /etc/network/interfaces
echo "auto eth0" >> /etc/network/interfaces
echo "iface eth0 inet static" >> /etc/network/interfaces
echo " address $IP" >> /etc/network/interfaces
echo " netmask $SUBNET" >> /etc/network/interfaces
echo " gateway $GATEWAY" >> /etc/network/interfaces
echo " dns-search $SEARCH" >> /etc/network/interfaces
echo " dns-nameservers $DNS1 $DNS2" >> /etc/network/interfaces
echo "127.0.0.1 localhost" > /etc/hosts
echo "127.0.1.1 $HOSTNAME" >> /etc/hosts
echo "# The following lines are desirable for IPv6 capable hosts" >> /etc/hosts
echo "::1 localhost ip6-localhost ip6-loopback" >> /etc/hosts
echo "ff02::1 ip6-allnodes" >> /etc/hosts
echo "ff02::2 ip6-allrouters" >> /etc/hosts
resolvconf -u
rm -rf /etc/ssh/ssh_host_*
dpkg-reconfigure openssh-server
logrotate -f /etc/logrotate.conf
service rsyslog stop
rm -f /var/log/*
rm -f /var/log/apt/*.gz
rm -f /var/log/dist-upgrade/*.gz
rm -f /var/log/unattended-upgrades/*.gz
rm -f /var/log/installer/*
cat /dev/null > /var/log/wtmp
cat /dev/null > /var/log/lastlog
rm -f ~root/.bash_history
unset HISTFILE
touch /root/customization-complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment