Navigation

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

    [HowTo] Automatischer PPPOE Reconnect bei Paketverlust

    Deutsch
    howto pppoe script
    3
    5
    6191
    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.
    • S
      s0nic last edited by JeGr

      Moin,

      ich habe aus gegebenen Anlass das Script von @BennTech (https://forum.pfsense.org/index.php?topic=51714.msg276614#msg276614) überarbeitet, damit es folgende Aufgaben durchführt:

      • Automatischer Reset der PPPOE-Verbindung bei Paketverlust

      • Eigener Interface Down und Up Sound (wird nur zwischen 08:00-22:00 Uhr gespielt)

      • Separater E-Mail Hinweis, sobald die Verbindung erfolgreich wiederhergestellt wurde

      • Nutzung des Systemlogs

      Hintergrund
      Obwohl ich die aktuelle 2.4.2-RELEASE-p1 einsetze, habe ich jeden Tag einige Probleme mit meiner PPPOE-Verbindung zum Provider. Laut Statusübersicht ist die Verbindung während der Störung up & running, aber es gehen keine Datenpakete durch die Leitung.  ??? Mit diesem angepassten Skript kann ich diesen Zombiestatus erkennen und die Verbindung automatisch zurücksetzen. 8) Alles kein Hexenwerk, aber es hilft mir die Downtime von mehreren Stunden auf ca. 2 Minuten zu begrenzen. Anscheinend kann die pfSense dieses Problem nicht von alleine erkennen und lösen. Meinen Provider interessiert diese Störung leider nicht.

      
      #!/bin/sh
      
      #=====================================================================
      # pingtest.sh, v1.0.2
      # Created 2009 by Bennett Lee 
      # Modified by s0nic
      # 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. (currently deactivated)
      #
      # History
      # 1.0.2   Added interface status sound, mail notification, systemlog and PPPOE reset. Disabled reboot.
      # 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 8.8.8.8"
      
      # Interface to reset, usually your WAN
      BOUNCE=WAN
      
      # Log file
      LOGFILE=/root/pingtest.log
      
      ZEIT=$(date +%k%M)
      #=====================================================================
      COUNT=1
      
      while [ $COUNT -le 2 ]
      do
      
      	for DEST in $ALLDEST
      	do
                      echo "PINGTEST: Pinging $DEST" | logger
      		ping -c1 $DEST >/dev/null 2>/dev/null
      
      		if [ $? -eq 0 ]
      		then
      			echo "PINGTEST: Ping $DEST OK." | logger
      			exit 0
      		fi
      	done
      
      	if [ $COUNT -le 1 ]
      	then
      		echo "PINGTEST: All pings failed. Resetting interface $BOUNCE." | logger  
      
      		# Interface RESET
      		/usr/local/sbin/pfSctl -c 'interface reload wan' >/dev/null 2>&1
      
      		# Interface DOWN
      		#/sbin/ifconfig $BOUNCE down | logger
      
      		# Notification
      		if [ "$ZEIT" -ge 800 ] && [ "$ZEIT" -le 2200 ]
      		then
      			/usr/local/bin/beep -p 1000 25
      			/usr/local/bin/beep -p 900 25 
      			/usr/local/bin/beep -p 800 25 
      			/usr/local/bin/beep -p 700 25 
      			/usr/local/bin/beep -p 600 25 
      			/usr/local/bin/beep -p 500 25 
      			/usr/local/bin/beep -p 400 25 
      			/usr/local/bin/beep -p 300 25 
      			/usr/local/bin/beep -p 200 50  
      		fi
      
      		# Give interface time to reset before bringing back up
      		#sleep 10
      
      		# Interface UP
      		#/sbin/ifconfig $BOUNCE up | logger
      
      		# Give WAN time to establish connection
      		sleep 15
      
      		# Notifications
      		for DEST in $ALLDEST
      		do
      			ping -c1 $DEST >/dev/null 2>/dev/null
      		done
      			if [ $? -eq 0 ]
      			then
      			MOMENT=`date +%d.%m.%Y@%H:%M:%Sh`
      			printf "PINGTEST: Interface $BOUNCE has been successfully resetted.\n\nReconnect: $MOMENT" | /usr/local/bin/php -q -c"/usr/local/etc/php.ini" /usr/local/bin/mail.php -s"pfSense.name - Reconnect"
      			echo "PINGTEST: Interface $BOUNCE has been successfully resetted." | logger 
      				if [ "$ZEIT" -ge 800 ] && [ "$ZEIT" -le 2200 ]
      				then
      		    			/usr/local/bin/beep -p 200 25
      					/usr/local/bin/beep -p 300 25 
      					/usr/local/bin/beep -p 400 25 
      					/usr/local/bin/beep -p 500 25 
      					/usr/local/bin/beep -p 600 25 
      					/usr/local/bin/beep -p 700 25 
      					/usr/local/bin/beep -p 800 25 
      					/usr/local/bin/beep -p 900 25 
      					/usr/local/bin/beep -p 1000 50
      				fi
      
      			fi
      
      	else
      		echo "PINGTEST: All pings failed twice." | logger
      		#echo "PINGTEST: All pings failed twice. Rebooting..." | logger
      		#/sbin/shutdown -r now | logger
      		exit 1
      	fi
      
      COUNT=`expr $COUNT + 1`
      done
      
      
      1 Reply Last reply Reply Quote 0
      • JeGr
        JeGr LAYER 8 Moderator last edited by

        Darf ich ergänzend kommentieren?

        Ich würde das Log nach /var/log schreiben, nicht /root. Das ist ggf. ein TMPFS oder Ramdisk Target, /root nie. Deshalb wäre es kontraproduktiv auf Geräten, die ggf. den Schreibzugriff minimieren möchten. :)

        Don't forget to upvote 👍 those who kindly offered their time and brainpower to help you!

        If you're interested, I'm available to discuss details of German-speaking paid support (for companies) if needed.

        1 Reply Last reply Reply Quote 0
        • S
          s0nic last edited by

          Na klar :-) Die Variable wurde von mir eh nicht mehr verwendet, da alles ins Systemlog geht. Habe die Chance gleich genutzt und noch weitere "Features" eingebaut…

          • Traceroute: Wenn ICMP Pakete verloren gehen, muss nicht immer die Leitung schuld sein. Manchmal liegt das Problem hinter dem POP/ersten HOP und ein nachgelagerter Router des Providers leitet die Pakete nicht ordnungsgemäß weiter. Um diesen Grund erkennen zu können, habe ich einen Traceroute während der Störung eingebaut.

          • Log Export: In der Statusmail sind jetzt die Zeiten der letzten Down- & Uptimes aus dem Systemlog enthalten, damit man auch längere Downtimes einfacher nachvollziehen und bei Bedarf dem Provider in Rechnung stellen kann.

          • WAN IP: Manchmal hat DDNS einfach zu viel Zeit gebraucht, deshalb ist jetzt die neue WAN IP in der Statusmail enthalten.

          Wer möchte kann auch wieder die ursprünglichen Befehle von Bennett Lee zum Interface Reset aktivieren oder z.B. einen Neustart durchführen lassen. Viel Spaß damit  ;)

          
          #!/bin/sh
          
          #=====================================================================
          # pingtest.sh, v1.0.3
          # Created 2009 by Bennett Lee 
          # Modified by s0nic
          # 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. (currently deactivated)
          #
          # History
          # 1.0.3   Added traceroute during downtime, WAN IP and log export for the status mail.
          # 1.0.2   Added interface status sound, mail notification, systemlog and PPPOE reset. Disabled reboot.
          # 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 8.8.8.8"
          
          # Interface to reset, usually your WAN
          BOUNCE=WAN
          
          # Log file (disabled)
          #LOGFILE=/root/pingtest.log
          
          #Timestamp
          ZEIT=$(date +%k%M)
          #=====================================================================
          COUNT=1
          
          while [ $COUNT -le 2 ]
          do
          
          	for DEST in $ALLDEST
          	do
                          echo "PINGTEST: Pinging $DEST" | logger
          		ping -c1 $DEST >/dev/null 2>/dev/null
          
          		if [ $? -eq 0 ]
          		then
          			echo "PINGTEST: Ping $DEST OK." | logger
          			exit 0
          		fi
          	done
          
          	if [ $COUNT -le 1 ]
          	then
          		echo "PINGTEST: All pings failed. Resetting interface $BOUNCE." | logger  
          
          		# Checking downtime reason
          		TRACE=`traceroute -w 3 -q 1 -m 10 8.8.8.8`
          
          		# Interface RESET
          		/usr/local/sbin/pfSctl -c 'interface reload wan' >/dev/null 2>&1
          
          		# Interface DOWN
          		#/sbin/ifconfig $BOUNCE down | logger
          
          		# Notification
          		if [ "$ZEIT" -ge 800 ] && [ "$ZEIT" -le 2200 ]
          		then
          			/usr/local/bin/beep -p 1000 25
          			/usr/local/bin/beep -p 900 25 
          			/usr/local/bin/beep -p 800 25 
          			/usr/local/bin/beep -p 700 25 
          			/usr/local/bin/beep -p 600 25 
          			/usr/local/bin/beep -p 500 25 
          			/usr/local/bin/beep -p 400 25 
          			/usr/local/bin/beep -p 300 25 
          			/usr/local/bin/beep -p 200 50  
          		fi
          
          		# Give interface time to reset before bringing back up
          		#sleep 10
          
          		# Interface UP
          		#/sbin/ifconfig $BOUNCE up | logger
          
          		# Give WAN time to establish connection
          		sleep 15
          
          		# Notifications
          		for DEST in $ALLDEST
          		do
          			ping -c1 $DEST >/dev/null 2>/dev/null
          		done
          			if [ $? -eq 0 ]
          			then
          			#MOMENT=`date +%d.%m.%Y@%H:%M:%Sh`
          			WANIP=`curl -s http://whatismyip.akamai.com/`
                                  echo "PINGTEST: Interface $BOUNCE has been successfully resetted." | logger
                                  SYSLOG=`clog /var/log/system.log | grep -e "PINGTEST: All" -e "PINGTEST: Interface"`
          			printf "PINGTEST: Interface $BOUNCE has been successfully resetted.\n\nThe new WAN address is: $WANIP\n\nSyslog:\n$SYSLOG\n\nDowntime traceroute:\n$TRACE" | /usr/local/bin/php -q -c"/usr/local/etc/php.ini" /usr/local/bin/mail.php -s"pfSense.name - Reconnect"
          				if [ "$ZEIT" -ge 800 ] && [ "$ZEIT" -le 2200 ]
          				then
          		    			/usr/local/bin/beep -p 200 25
          					/usr/local/bin/beep -p 300 25 
          					/usr/local/bin/beep -p 400 25 
          					/usr/local/bin/beep -p 500 25 
          					/usr/local/bin/beep -p 600 25 
          					/usr/local/bin/beep -p 700 25 
          					/usr/local/bin/beep -p 800 25 
          					/usr/local/bin/beep -p 900 25 
          					/usr/local/bin/beep -p 1000 50
          				fi
          
          			fi
          
          	else
          		echo "PINGTEST: All pings failed twice." | logger
          		#echo "PINGTEST: All pings failed twice. Rebooting..." | logger
          		#/sbin/shutdown -r now | logger
          		exit 1
          	fi
          
          COUNT=`expr $COUNT + 1`
          done
          
          
          M 1 Reply Last reply Reply Quote 0
          • JeGr
            JeGr LAYER 8 Moderator last edited by

            Ich pinne das einfach mal oben an, damits nicht verloren geht.

            Don't forget to upvote 👍 those who kindly offered their time and brainpower to help you!

            If you're interested, I'm available to discuss details of German-speaking paid support (for companies) if needed.

            1 Reply Last reply Reply Quote 0
            • M
              Misaal @s0nic last edited by

              @s0nic Hallo, eine Frage, wenn ich versuche das Script auszuführen bekomme ich:
              /usr/local/bin/pingtest.sh: Command not found.
              muss man da noch berücksichtigen? Danke und schöne Grüsse

              1 Reply Last reply Reply Quote 0
              • Referenced by  T thiasaef 
              • Referenced by  T thiasaef 
              • Referenced by  T thiasaef 
              • First post
                Last post