Skip to content

Instantly share code, notes, and snippets.

@jnikolak
Last active November 1, 2016 10:26
Show Gist options
  • Save jnikolak/a16e423760b37f134a428719cc92a380 to your computer and use it in GitHub Desktop.
Save jnikolak/a16e423760b37f134a428719cc92a380 to your computer and use it in GitHub Desktop.
send new ifcfg
#!/bin/bash
set -x
#oldName=$(grep DEVICE /etc/sysconfig/network-scripts/ifcfg-ens3 | awk -F '"' '{print $2}')
intName=$(ip link | egrep -v "lo|link" | awk -F ': ' '{print $2}')
ifcfgfile="/etc/sysconfig/network-scripts/ifcfg-$intName"
mv /etc/sysconfig/network-scripts/ifcfg-$intName /etc/sysconfig/network-scripts/ifcfg-$intName.bak
touch $ifcfgfile
for i in "DEVICE=$intName" "ONBOOT=yes"
do
echo $i >> $ifcfgfile
done
read -p "Static or dhcp?" yoursetup
if [ $yoursetup = "static" ];then
read -p "What is your Ip Address : " yourip
read -p "What is your Gateway : " yourgw
read -p "What is your subnet/prefix? : " yourprefix
read -p "What is your dns? : " yourdns
for j in "BOOTPROTO=static" "IPADDR=$yourip" "GATEWAY=$yourgw" "PREFIX=$yourprefix" "DNS=$yourdns" "NMCONTROLLED=no"
do
echo $j >> $ifcfgfile
done
else
echo "BOOTPROTO=dhcp" >> $ifcfgfile
echo "NMCONTROLLED=no" >> $ifcfgfile
fi
systemctl disable NetworkManager
systemctl stop NetworkManager
service network stop
sleep 2
service network start
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment