sorted
This commit is contained in:
37
files/bashscripts/debian/debian-change-ip.sh
Executable file
37
files/bashscripts/debian/debian-change-ip.sh
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ask to set static ip address
|
||||
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
|
||||
# get adapter name
|
||||
name=$(basename /sys/class/net/e*)
|
||||
# backup original interfaces file
|
||||
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
|
||||
# set static ip
|
||||
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
|
||||
# backup resolv.conf file
|
||||
if [[ ! -f /etc/resolv.conf.bak ]] ; then
|
||||
cp /etc/resolv.conf /etc/resolv.conf.bak
|
||||
fi
|
||||
rm /etc/resolv.conf
|
||||
# set primary dns ip
|
||||
echo "nameserver $dnsip1" >> /etc/resolv.conf
|
||||
# ask for secondary dns ip
|
||||
read -r -p "Set Secondary DNS IP Address? <y/N> " prompt
|
||||
if [[ "${prompt,,}" =~ ^(y|yes)$ ]] ; then
|
||||
read -r -p "Enter Secondary DNS IP Address: " dnsip2
|
||||
echo "nameserver $dnsip2" >> /etc/resolv.conf
|
||||
fi
|
||||
# restart the interface
|
||||
ifdown $name
|
||||
ifup $name
|
||||
fi
|
||||
Reference in New Issue
Block a user