Last active
November 1, 2016 10:26
-
-
Save jnikolak/a16e423760b37f134a428719cc92a380 to your computer and use it in GitHub Desktop.
send new ifcfg
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 | |
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