Skip to content

Instantly share code, notes, and snippets.

@jnikolak
Last active November 3, 2016 07:42
Show Gist options
  • Save jnikolak/48a2f148cd845061cbc8df0b0ab2dede to your computer and use it in GitHub Desktop.
Save jnikolak/48a2f148cd845061cbc8df0b0ab2dede to your computer and use it in GitHub Desktop.
Create Static Network Configuration
#!/bin/bash
set -x
### TODO DETERMINE HOW MANY INTERFACE ACTIVE AND WHICH ONE YOU WOULD LIKE TO CONFIGURE
curipaddr=$(ip link | egrep -v "lo|link" | awk -F ': ' '{print $2}')
curgateway=$(ip r s table all | egrep 'default v' | awk '{print $3}')
curdns=$(dig $(hostname -f) | egrep SERVER | awk -F '(' '{print $2}'| sed 's/)//')
#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
echo "DEVICE=$intName" > $ifcfgfile
echo "ONBOOT=yes" >> $ifcfgfile
read -p "Static or dhcp?" yoursetup
if [ $yoursetup = "static" ];then
echo "BOOTPROTO=static" >> $ifcfgfile
read -p "What is your Ip Address : " yourip
echo "IPADDR=$yourip" >> $ifcfgfile
read -p "What is your Gateway : " yourgw
echo "GATEWAY=$yourgw" >> $ifcfgfile
read -p "What is your subnet/prefix? : " yourprefix
echo "PREFIX=$yourprefix" >> $ifcfgfile
read -p "What is your dns? : " yourdns
echo "DNS=$yourdns" >> $ifcfgfile
echo "NMCONTROLLED=no" >> $ifcfgfile
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