Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    OpenVPN como Rota Backup

    Scheduled Pinned Locked Moved Portuguese
    1 Posts 1 Posters 357 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      Chinaina
      last edited by

      Olá!

      Me deparei com a necessidade de ter uma conexão backup via OpenVPN, onde a conexão point-to-point default, é realizada através de um link MPLS.

      Consegui contornar o problema através de um Shell Script, executado via cron e gostaria de saber se isso pode implicar em alguma queda de desempenho do servidor ou algum outro problema.

      Segue script para contextualizar.

      #!/bin/sh
      
      # Gateway MPLS Matriz
      GATEWAY="10.x.x.x"
      
      # Quantidade de Requisições
      PING=10
      
      for myGATEWAY in $GATEWAY
      do
      	# Armazenar quantidade de requisições com respostas OK
      	counting=$(ping -c $PING $myGATEWAY | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }' )
      	
      	# Armazenar Status do Cliente OpenVPN
      	status=`/usr/local/sbin/pfSsh.php playback svc status openvpn client 1 | grep 'Service'`
      	
      	# MANTER GATEWAY MPLS
      
      	# Teste de condição para verificar se PING é maior que 80% E se status do cliente OpenVPN é diferente de PARADO
      	if [ $counting -ge 8 -a "$status" != "Service openvpn is stopped." ]; then
      		# Parar Cliente OpenVPN
      		/usr/local/sbin/pfSsh.php playback svc stop openvpn client 1
      
      		# Deletar Rota VPN para Matriz
      		route del -net 192.168.x.x/24 172.x.x.x
      
      		# Deletar Rota VPN para Escritório
      		route del -net 192.168.x.x/25 172.x.x.x
      
      		# Adicionar Rota MPLS para Matriz
      		route add -net 192.168.x.x/24 10.x.x.x
      
      		# Adicionar Rota MPLS para Escritório
      		route add -net 192.168.x.x/24 10.x.x.x
      
      		# Adicionar Rota Default
      		route add default 192.168.x.x
      
      		# Limpar estado das conexões
      		pfctl -F states
      
      		exit
      	
      	# MANTER GATEWAY OPENVPN	
      
      	# Teste de condição para verificar se PING é menor que 80% E se status do cliente OpenVPN é igual PARADO	
      	elif [ "$status" = "Service openvpn is stopped." -a $counting -le 7 ]; then
      
      		# Iniciar cliente OpenVPN
      		/usr/local/sbin/pfSsh.php playback svc start openvpn client 1
      
      		# Deletar rota MPLS para Matriz
      		route del -net 192.168.x.x/24 10.x.x.x
      
      		# Deletar rota MPLS para Escritório
      		route del -net 192.168.x.x/24 10.x.x.x
      
      		# Adicionar rota VPN para Matriz
      		route add -net 192.168.x.x/24 172.x.x.x
      
      		# Adicionar rota VPN para Escritório
      		route add -net 192.168.x.x/24 172.x.x.x
      
      		# Adicionar rota Default
      		route add default 192.168.x.x
      
      		# Limpar estado das conexões
      		pfctl -F states
      
      		exit
      	
      	# CONEXÃO OK
      	
      	else
      		exit
      	fi
      done
      

      Obrigado!

      Atenciosamente,
      Douglas Ferreira

      1 Reply Last reply Reply Quote 0
      • First post
        Last post
      Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.