first commit
This commit is contained in:
36
debian/debian-set-ip.sh
vendored
Executable file
36
debian/debian-set-ip.sh
vendored
Executable file
@@ -0,0 +1,36 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ask to set static ip address
|
||||
if [[ ! -d /etc/cloud ]]
|
||||
then
|
||||
if [[ ! -f /etc/network/interfaces.bak ]]
|
||||
then
|
||||
read -r -p "Set Static IP address? <y/N> " prompt
|
||||
if [[ "${prompt,,}" =~ ^(y|yes)$ ]]
|
||||
then
|
||||
read -r -p "Enter Static IP Address with subnet prefix: " staticip
|
||||
read -r -p "Enter Gateway IP Address: " gatewayip
|
||||
read -r -p "Enter Primary DNS IP Address: " dnsip1
|
||||
read -r -p "Enter Secondary DNS IP Address: " dnsip2
|
||||
name=$(basename /sys/class/net/e*)
|
||||
if [[ ! -f /etc/network/interfaces.bak ]]
|
||||
then
|
||||
cp /etc/network/interfaces /etc/network/interfaces.bak
|
||||
fi
|
||||
rm /etc/network/interfaces
|
||||
cp /etc/network/interfaces.bak /etc/network/interfaces
|
||||
sed -i "s,^iface $name inet dhcp*,iface $name inet static," /etc/network/interfaces
|
||||
echo " address $staticip" >> /etc/network/interfaces
|
||||
echo " gateway $gatewayip" >> /etc/network/interfaces
|
||||
if [[ ! -f /etc/resolv.conf.bak ]]
|
||||
then
|
||||
cp /etc/resolv.conf /etc/resolv.conf.bak
|
||||
fi
|
||||
rm /etc/resolv.conf
|
||||
echo "nameserver $dnsip1" >> /etc/resolv.conf
|
||||
echo "nameserver $dnsip2" >> /etc/resolv.conf
|
||||
ifdown $name
|
||||
ifup $name
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
Reference in New Issue
Block a user