Script to set IP Address

#!/bin/bash
echo “Would you like DHCP or STATIC”
read CHOICE
if [ “$CHOICE” == “DHCP” ]; then
echo “DHCP is being set”
echo “source /etc/network/interfaces.d/*” > interfaces
echo “auto lo” >> interfaces
echo “iface lo inet loopback” >> interfaces
echo “auto enp0s3” >> interfaces
echo “iface enp0s3 inet dhcp” >> interfaces
elif [ “$CHOICE” == “STATIC” ]; then
echo “STATIC is being set”
echo “What is the IP?”
read IP
echo “What is the netmask?”
read NETMASK
echo “What is the gateway”
read GATEWAY
echo “source /etc/network/interfaces.d/*” > interfaces
echo “auto lo” >> interfaces
echo “iface lo inet loopback” >> interfaces
echo “auto enp0s3”>> interfaces
echo “iface enp0s3 inet static” >> interfaces
echo “address $IP” >> interfaces
echo “netmask $NETMASK” >> interfaces
echo “gateway $GATEWAY” >> interfaces
echo “dns-nameservers 8.8.8.8” >> interfaces
fi
sudo cp interfaces /etc/network/interfaces
sleep 2
sudo ip addr flush enp0s3
sleep 2
sudo service networking restart
sleep 2

 

 

script