Commit 0fb1eb59 authored by Joab Bremer's avatar Joab Bremer

rotas

parent e4f9a7bb
#!/usr/bin/bash
### Link 1
IF_LINK1="eth2"
MASK_LINK1="29"
IP_LINK1="177.101.123.202"
GW_LINK1="177.101.123.201"
NT_LINK1="177.101.123.200"
### Link 2
IF_LINK2="eth3"
MASK_LINK2="24"
IP_LINK2="192.168.2.240"
GW_LINK2="192.168.2.2"
NT_LINK2="192.168.2.0"
up_link1_default(){
logger "fail-over: Alterando para a rota padrão via $GW_LINK1"
ip route del default via $GW_LINK2
ip route add default via $GW_LINK1
}
up_link2_default(){
logger "fail-over: Alterando para a rota padrão via $GW_LINK1"
ip route del default via $GW_LINK1
ip route add default via $GW_LINK2
}
check_link() {
while [ "$1" != "stop" ]; do
#logger "fail-over: validando links"
if ping -c 1 -I $IF_LINK1 9.9.9.9 &> /dev/null; then
if ! ip route show default | grep -q "via $GW_LINK1"; then
up_link1_default
fi
fi
if ! ping -c 1 -I $IF_LINK1 9.9.9.9 &> /dev/null; then
if ip route show default | grep -q "via $GW_LINK1"; then
up_link2_default
fi
fi
sleep 15
done
logger "fail-over: Parando Servico"
}
main(){
logger "fail-over: Iniciando Servico"
#Definindo rotas link principal
ip route add $NT_LINK1/$MASK_LINK1 dev $IF_LINK1
ip route add $NT_LINK1/$MASK_LINK1 dev $IF_LINK1 table T1
ip route add default via $GW_LINK1 table T1
#Definindo rotas link Secundario
ip route add $NT_LINK2/$MASK_LINK2 dev $IF_LINK2
ip route add $NT_LINK2/$MASK_LINK2 dev $IF_LINK2 table T2
ip route add default via $GW_LINK2 table T2
#Validando se link dedicado esta ativo e fazendo failover
ip route add 9.9.9.9 via $GW_LINK1
ip route add 149.112.112.112 via $GW_LINK2
#Criando novos encaminhamentos das tabelas
ip rule add from $IP_LINK1 table T1
ip rule add from $IP_LINK2 table T2
# Marca pacotes para sairem pelo link2
ip rule add fwmark 2 table T2
#verifica o link e definindo rota default
check_link "$1"
}
main
####################################################################################
#Variaveis de instalação
RED='\033[0;31m'
NC='\033[0m' # No Color
DT=$(date +%d%m%Y_%H%M%S)
####################################################################################
disable_selinux(){
sed -i /etc/selinux/config -r -e 's/^SELINUX=.*/SELINUX=disabled/g'
}
creating_service_rotas(){
cat >/etc/systemd/system/rotas.service<<EOF
[Unit]
Description=Rotas e FailOver
After=network.target
[Service]
Type=simple
ExecStart=bash /etc/rc.d/rc.rotas
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
}
install_rota(){
cd /etc/rc.d/
wget http://git.usb.org.br/infra/scripts/raw/master/rc.rotas -P /etc/rc.d/ -O rc.rotas
}
starting_service_rota(){
systemctl enable rotas.service --quiet
systemctl start rotas.service --quiet
}
stty echo
echo -e "${RED}Iniciando Instalação${NC}"
echo -e "${RED}Desabilitando SE Linux${NC}"
disable_selinux
echo -e "${RED}Criando rotas.service${NC}"
creating_service_rotas
echo -e "${RED}instalando rc.rotas${NC}"
install_rota
echo -e "${RED}Iniciando rotas.service${NC}"
starting_service_rota
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment