File: //usr/local/sbin/seteth1
#!/bin/bash
read -p "Enter the interface name: " interface
while [ -z "$interface" ]
do
echo "The interface is required!"
read -p "Enter the interface: " interface
done
if ! ip link show | awk '{print $2}' | grep -wq $interface
then
echo "No such interface detected!"
exit 1
fi
ifdown $interface
echo "NAME=$interface
DEVICE=$interface
BOOTPROTO=static
ONBOOT=yes
TYPE=Ethernet
IPADDR=
NETMASK=255.255.255.0" > /etc/sysconfig/network-scripts/ifcfg-$interface
nano +6 /etc/sysconfig/network-scripts/ifcfg-$interface
address=$(grep "IPADDR" /etc/sysconfig/network-scripts/ifcfg-$interface | cut -c8-)
if [ $(echo $address | awk -F "." '{print $1}') == 10 ]
then
echo "10.255.255.0/24 dev $interface" > /etc/sysconfig/network-scripts/route-$interface
else
octets=$(echo $address | awk -F "." '{print $1"."$2"."$3}')
echo "172.31.255.0/24 via $octets.1" > /etc/sysconfig/network-scripts/route-$interface
fi
ifup $interface
/usr/bin/wget -q -O - --no-check-certificate "https://64.59.69.75/tempfiles/installs_do.php?type=I&hostname=$(hostname -s)&task=eth1&action=X"
rm -f /usr/local/sbin/seteth1