Last active
January 26, 2016 17:19
-
-
Save McKay1717/2c748cfb4b1d89d47ebc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/bash | |
if [ "$#" -ne 3 ]; then | |
echo "Illegal number of parameters" | |
echo "Usage: autoconfig.sh ip block hostame" | |
echo "Exemple: autoconfig.sh 177.20.20.4 172.20.20.0 tpreseau4" | |
exit 1 | |
fi | |
ip=$1 | |
block=$2 | |
hostname=$3 | |
exec > /tmp/interface.tmp | |
d1=$(echo "$block" | cut -d'.' -f1) | |
d2=$(echo "$block" | cut -d'.' -f2) | |
d3=$(echo "$block" | cut -d'.' -f3) | |
d4=$(echo "$block" | cut -d'.' -f4) | |
echo "# The loopback network interface" | |
echo "auto lo " | |
echo "iface lo inet loopback " | |
echo "# The primary network interface " | |
echo "iface eth0 inet static " | |
echo " address ${ip} " | |
echo " netmask 255.255.255.0" | |
echo " network ${block}" | |
echo " broadcast ${d1}.${d2}.${d3}.255" | |
echo " gateway ${d1}.${d2}.${d3}.254" | |
mv /tmp/interface.tmp /etc/network/interface | |
echo $hostname > /etc/hostname | |
/etc/init.d/hostname.sh | |
/sbin/ifconfig eth0 down && /sbin/ifconfig eth0 up |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment