#!/bin/bash
if [ -z "$1" ]
then
echo "" | mail -s "PXE Dedi Install - done $HOSTNAME - $ipaddr - failed no IP found." [email protected]
exit
fi
ipaddress=$1
if [[ "$ipaddress" == *.1 ]]
then
echo "" | mail -s "PXE Dedi Install - $HOSTNAME Network setup failed - The IP ends in .1 VERY BAD, check conf." [email protected]
exit
fi
if [[ $ipaddress == *"50.31.98"* ]] || [[ $ipaddress == *"50.31.99"* ]] ; then
ipgateway=50.31.98.1
ipnetmask=255.255.254.0
elif [[ $ipaddress == *"216.185.212"* ]] || [[ $ipaddress == *"216.185.213"* ]] || [[ $ipaddress == *"216.185.214"* ]] || [[ $ipaddress == *"216.185.215"* ]] ; then
ipgateway=216.185.212.1
ipnetmask=255.255.252.0
elif [[ $ipaddress == *"198.175.24"* ]] || [[ $ipaddress == *"198.175.25"* ]] || [[ $ipaddress == *"198.175.26"* ]] || [[ $ipaddress == *"198.175.27"* ]] ; then
ipgateway=198.175.24.1
ipnetmask=255.255.252.0
elif [[ $ipaddress == *"74.121.204"* ]] || [[ $ipaddress == *"74.121.205"* ]] || [[ $ipaddress == *"74.121.206"* ]] || [[ $ipaddress == *"74.121.207"* ]] ; then
ipgateway=74.121.204.1
ipnetmask=255.255.252.0
elif [[ $ipaddress == *"207.241.196"* ]] || [[ $ipaddress == *"207.241.197"* ]] || [[ $ipaddress == *"207.241.198"* ]] || [[ $ipaddress == *"207.241.199"* ]] ; then
ipgateway=207.241.196.1
ipnetmask=255.255.252.0
elif [[ $ipaddress == *"38.65.224"* ]] || [[ $ipaddress == *"38.65.225"* ]] || [[ $ipaddress == *"38.65.226"* ]] || [[ $ipaddress == *"38.65.227"* ]] ; then
ipgateway=38.65.224.1
ipnetmask=255.255.252.0
else
ipgateway=$(awk -F"." '{print $1"."$2"."$3".1"}'<<<"$ipaddress")
ipnetmask=255.255.255.0
fi
{
echo alias bond0 bonding
echo options bond0 miimon=100 mode=0 lacp_rate=1
} >> /etc/modprobe.d/bonding.conf
{
echo nameserver 1.1.1.1
echo nameserver 1.0.0.1
} > /etc/resolv.conf
sed -i 's/^/#/' /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i 's/^/#/' /etc/sysconfig/network-scripts/ifcfg-eth1
{
echo
echo DEVICE=eth0
echo TYPE=Ethernet
echo ONBOOT=yes
echo NM_CONTROLLED=no
echo MASTER=bond0
echo SLAVE=yes
} >> /etc/sysconfig/network-scripts/ifcfg-eth0
{
echo
echo DEVICE=eth1
echo TYPE=Ethernet
echo ONBOOT=yes
echo NM_CONTROLLED=no
echo MASTER=bond0
echo SLAVE=yes
} >> /etc/sysconfig/network-scripts/ifcfg-eth1
# ifcfg-bond0
{
echo DEVICE=bond0
echo IPADDR="$ipaddress"
echo NETMASK="$ipnetmask"
echo GATEWAY="$ipgateway"
echo TYPE=Bond
echo ONBOOT=yes
echo NM_CONTROLLED=no
echo BOOTPROTO=static
echo DNS1=1.1.1.1
echo DNS2=1.0.0.1
} >> /etc/sysconfig/network-scripts/ifcfg-bond0
##Copper
#nmcli connection add type bond con-name bond0 ifname bond0 bond.options "mode=0,miimon=1000"
#nmcli connection add type ethernet slave-type bond con-name bond0-port1 ifname eno1 master bond0
#nmcli connection add type ethernet slave-type bond con-name bond0-port2 ifname eno2 master bond0
#nmcli connection modify bond0 ipv4.addresses '69.162.171.152/25' ipv4.gateway '69.162.171.128' ipv4.dns '1.1.1.1' ipv4.method manual
#nmcli connection modify eno1 master bond0
#nmcli connection modify eno2 master bond0
#nmcli connection up bond0
##Fiber
#nmcli connection add type bond con-name bond1 ifname bond1 bond.options "mode=0,miimon=1000"
#nmcli connection add type ethernet slave-type bond con-name bond1-port1 ifname enp24s0f0 master bond1
#nmcli connection add type ethernet slave-type bond con-name bond1-port2 ifname enp24s0f1 master bond1
#nmcli connection modify bond1 ipv4.addresses '10.50.14.1/24' ipv4.gateway '10.50.14.1' ipv4.dns '1.1.1.1' ipv4.method manual
#nmcli connection modify enp24s0f0 master bond1
#nmcli connection modify enp24s0f1 master bond1
#nmcli connection up bond1