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

    PFSENSE NAO RENOVA IP WAN AUTOMATICAMENTE

    Scheduled Pinned Locked Moved Portuguese
    6 Posts 2 Posters 1.3k 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.
    • H Offline
      hugoteleco
      last edited by

      Pessoal, eu vi este mesmo tópico no fórum em inglês: https://forum.pfsense.org/index.php/topic,17243.msg89348.html#msg89348, porém estou com um problema neste script.

      Segui o procedimento mas acabou que estou perdendo conexão direto e após completar o script de verificações ele reinicia meu pfsense. Acredito que o tempo limite do ping para o google.com ou 8.8.8.8 esteja curto, fazendo com que o script entenda que deve reinciar a interface e depois reiniciar o firewall.

      Alguém sabe me ajudar a entender o script? Está de acordo para uso com o provedor NET??

      #!/bin/sh

      #=====================================================================

      pingtest.sh, v1.0.1

      Created 2009 by Bennett Lee

      Released to public domain

      (1) Attempts to ping several hosts to test connectivity.  After

      #    first successful ping, script exits.

      (2) If all pings fail, resets interface and retries all pings.

      (3) If all pings fail again after reset, then reboots pfSense.

      History

      1.0.1  Added delay to ensure interface resets (thx ktims).

      1.0.0  Initial release.

      #=====================================================================

      #=====================================================================

      USER SETTINGS

      Set multiple ping targets separated by space.  Include numeric IPs

      (e.g., remote office, ISP gateway, etc.) for DNS issues which

      reboot will not correct.

      ALLDEST="google.com yahoo.com 24.93.40.36 24.93.40.37"

      Interface to reset, usually your WAN

      BOUNCE=re0

      Log file

      LOGFILE=/root/pingtest.log
      #=====================================================================

      COUNT=1
      while [ $COUNT -le 2 ]
      do

      for DEST in $ALLDEST
      do
      #echo date +%Y%m%d.%H%M%S "Pinging $DEST" >> $LOGFILE
      ping -c1 $DEST >/dev/null 2>/dev/null
      if [ $? -eq 0 ]
      then
      #echo date +%Y%m%d.%H%M%S "Ping $DEST OK." >> $LOGFILE
      exit 0

      fi
      done

      if [ $COUNT -le 1 ]
      then
      echo date +%Y%m%d.%H%M%S "All pings failed. Resetting interface $BOUNCE." >> $LOGFILE
      /sbin/ifconfig $BOUNCE down

      Give interface time to reset before bringing back up

      **sleep 10
      /sbin/ifconfig $BOUNCE up

      Give WAN time to establish connection

      sleep 60**
      else
      echo date +%Y%m%d.%H%M%S "All pings failed twice. Rebooting…" >> $LOGFILE
      /sbin/shutdown -r now >> $LOGFILE
      exit 1
      fi

      COUNT=expr $COUNT + 1
      done

      1 Reply Last reply Reply Quote 0
      • L Offline
        lucaspolli
        last edited by

        ele esta pingando para 4 enderecos: google.com yahoo.com 24.93.40.36 24.93.40.37 e usando a placa re0, isso esta de acordo com a sua estrutura? sua placa é essa mesmo? o que o arquivo de log diz?

        1 Reply Last reply Reply Quote 0
        • H Offline
          hugoteleco
          last edited by

          @Lucas:

          ele esta pingando para 4 enderecos: google.com yahoo.com 24.93.40.36 24.93.40.37 e usando a placa re0, isso esta de acordo com a sua estrutura? sua placa é essa mesmo? o que o arquivo de log diz?

          Testei todos os endereços, inclusive mudei para somente o ip do google (8.8.8.8). A placa WAN é esta mesma re0. No log "/root/pingtest.log" ele mostra apenas a mensagem descrita no script indicando o que está fazendo… All pings failed twice. Rebooting...

          Tem outro arquivo de log? Minha conexão tem perdas, mas são mínimas, tipo 1 salto.

          Desde já agradeço a ajuda.

          1 Reply Last reply Reply Quote 0
          • L Offline
            lucaspolli
            last edited by

            substitua os comandos de down, up e reboot por variaveis de log e para ver se o script esta sendo executado corretamente, e teste na mao..

            1 Reply Last reply Reply Quote 0
            • H Offline
              hugoteleco
              last edited by

              @Lucas:

              substitua os comandos de down, up e reboot por variaveis de log e para ver se o script esta sendo executado corretamente, e teste na mao..

              Lucas, como eu faço isso? Não entendo muito de programação. Ficaria assim?(desculpa minha ignorância rs)

              #!/bin/sh

              #=====================================================================

              pingtest.sh, v1.0.1

              Created 2009 by Bennett Lee

              Released to public domain

              (1) Attempts to ping several hosts to test connectivity.  After

              #    first successful ping, script exits.

              (2) If all pings fail, resets interface and retries all pings.

              (3) If all pings fail again after reset, then reboots pfSense.

              History

              1.0.1  Added delay to ensure interface resets (thx ktims).

              1.0.0  Initial release.

              #=====================================================================

              #=====================================================================

              USER SETTINGS

              Set multiple ping targets separated by space.  Include numeric IPs

              (e.g., remote office, ISP gateway, etc.) for DNS issues which

              reboot will not correct.

              ALLDEST="google.com yahoo.com 24.93.40.36 24.93.40.37"

              Interface to reset, usually your WAN

              BOUNCE=re0

              Log file

              LOGFILE=/root/pingtest.log
              UP=/root/log_up.log
              DOWN=/root/log_down.log
              REBOOT=/root/log_reboot.log
              #=====================================================================

              COUNT=1
              while [ $COUNT -le 2 ]
              do

              for DEST in $ALLDEST
              do
              #echo date +%Y%m%d.%H%M%S "Pinging $DEST" >> $LOGFILE
              ping -c1 $DEST >/dev/null 2>/dev/null
              if [ $? -eq 0 ]
              then
              #echo date +%Y%m%d.%H%M%S "Ping $DEST OK." >> $LOGFILE
              exit 0
              fi
              done

              if [ $COUNT -le 1 ]
              then
              echo date +%Y%m%d.%H%M%S "All pings failed. Resetting interface $BOUNCE." >> $LOGFILE
              /sbin/ifconfig $BOUNCE >> $DOWN

              Give interface time to reset before bringing back up

              sleep 10
              /sbin/ifconfig $BOUNCE >> $UP

              Give WAN time to establish connection

              sleep 60
              else
              echo date +%Y%m%d.%H%M%S "All pings failed twice. Rebooting…" >> $LOGFILE
              /sbin/shutdown -r now >> $LOGFILE
              exit 1
              fi

              COUNT=expr $COUNT + 1
              done

              1 Reply Last reply Reply Quote 0
              • L Offline
                lucaspolli
                last edited by

                faca o seguinte, execute o codigo abaixo do jeito que esta, depois altere a variavel ALLDEST="8.8.8.8" para ALLDEST="1.1.1.1" e execute denovo, apos isso poste aqui o log

                obs: nao se preocupe que nao ira reiniciar seu server

                #!/bin/sh

                #=====================================================================

                pingtest.sh, v1.0.1

                Created 2009 by Bennett Lee

                Released to public domain

                (1) Attempts to ping several hosts to test connectivity.  After

                #    first successful ping, script exits.

                (2) If all pings fail, resets interface and retries all pings.

                (3) If all pings fail again after reset, then reboots pfSense.

                History

                1.0.1  Added delay to ensure interface resets (thx ktims).

                1.0.0  Initial release.

                #=====================================================================

                #=====================================================================

                USER SETTINGS

                Set multiple ping targets separated by space.  Include numeric IPs

                (e.g., remote office, ISP gateway, etc.) for DNS issues which

                reboot will not correct.

                ALLDEST="8.8.8.8"

                Interface to reset, usually your WAN

                BOUNCE=re0

                Log file

                LOGFILE=/root/pingtest.log
                #=====================================================================

                COUNT=0
                while [ $COUNT -le 1 ]
                do
                  for DEST in $ALLDEST
                  do
                      echo date +%Y%m%d.%H%M%S "Pinging $DEST" >> $LOGFILE
                      ping -c1 $DEST >/dev/null 2>/dev/null
                      if [ $? -eq 0 ]
                      then
                        echo date +%Y%m%d.%H%M%S "Ping $DEST OK." >> $LOGFILE
                        exit 0
                      fi
                  done
                  if [ $COUNT -le 0 ]
                  then
                      echo date +%Y%m%d.%H%M%S "All pings failed. Resetting interface $BOUNCE." >> $LOGFILE
                      #/sbin/ifconfig $BOUNCE down
                      # Give interface time to reset before bringing back up
                      sleep 10
                  echo date +%Y%m%d.%H%M%S "Passou sleep 10 $BOUNCE." >> $LOGFILE
                      #/sbin/ifconfig $BOUNCE up
                      # Give WAN time to establish connection
                      sleep 60
                  echo date +%Y%m%d.%H%M%S "Passou sleep 60 $BOUNCE." >> $LOGFILE
                  else
                      echo date +%Y%m%d.%H%M%S "All pings failed twice. Rebooting…" >> $LOGFILE
                      #/sbin/shutdown -r now >> $LOGFILE
                      exit 1
                  fi
                  COUNT=expr $COUNT + 1
                done

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