{"id":1617,"date":"2022-06-19T20:41:37","date_gmt":"2022-06-19T20:41:37","guid":{"rendered":"https:\/\/www.dev-metal.ch\/?p=1617"},"modified":"2022-06-20T08:47:39","modified_gmt":"2022-06-20T08:47:39","slug":"opnsense-reboot-wenn-wan-nicht-erreichbar","status":"publish","type":"post","link":"https:\/\/www.dev-metal.ch\/?p=1617","title":{"rendered":"OpnSense &#8211; Reboot wenn WAN nicht erreichbar"},"content":{"rendered":"\n<p>Ich betreibe meine OpnSense Firewall hinter einer UPC Giga Connect Box. Diese ist auf Bridge-Modus gestellt, so dass alle Requests direkt an die OpnSense Firewall gelangen.<\/p>\n\n\n\n<p>Hin und wieder scheint UPC etwas zu maintainen. In der Folge verliert OpnSense die connectivity auf dem WAN-Port. Je nachdem wie h\u00e4ufig die UPC Unterhalt betreibt, fliegt die connectivity 1 &#8211; 2x pro Monat raus. Einzig ein Reboot l\u00f6st dann das Problem.<\/p>\n\n\n\n<p>Um dies zu automatisieren, habe ich ein Script <a rel=\"noopener\" href=\"https:\/\/forum.opnsense.org\/index.php?topic=18865.msg86224#msg86224\" target=\"_blank\">hier abgekupfert<\/a>. <\/p>\n\n\n\n<p>Ich \u00fcberpr\u00fcfe die connectivity, indem ich die DNS-Server von Switch und DigitaleGesellschaft anpinge. Die Pings werden nach \/root\/pingtest.log geschrieben &#8211; und NICHT gel\u00f6scht &#8211; Wenn alles sauber funktioniert, kann das logfile auch jeweils gel\u00f6scht werden.<br>Als erstes ein Config-File &#8220;actions_pingcheck.conf&#8220; mit folgenden Inhalt erstellen.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;start]\ncommand:\/usr\/local\/etc\/rc.d\/ping_check.sh\nparameters:\ntype:script\nmessage:starting ping_check\ndescription:ping_check<\/code><\/pre>\n\n\n\n<p>Kopiere das File nach<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/usr\/local\/opnsense\/service\/conf\/actions.d<\/code><\/pre>\n\n\n\n<p>Jetzt das Bash-Script &#8222;ping_check.sh&#8220; erstellen:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/sh\n\n#=====================================================================\n# USER SETTINGS\n#\n# Testing uptime to run script only xx seconds after boot \n#\n# Log file\nLOGFILE=\/root\/pingtest.log\n#\n#=====================================================================\n\n\n# Current time\ncurtime=$(date +%s)\n\n# Bootime in seconds\nuptime=$(sysctl kern.boottime | awk -F'sec = ' '{print $2}' | awk -F',' '{print $1}')\n\n# Uptime in seconds\nuptime=$(($curtime - $uptime))\n\n# If boot is longer than 120 seconds ago...\nif &#91; $uptime -gt 120 ]; then\n\n# A message to the console (I like feedback -if you don't then comment out the echo, wall and rm lines) \n    echo \"Testing Connection at\" `date +%Y-%m-%d.%H:%M:%S` \"uptime:\" $uptime \"seconds\" &gt;&gt; $LOGFILE\n    wall $LOGFILE \n    #rm $LOGFILE \n\n    # Try 1 or 2 minutes worth of very short pings to googles DNS servers - In this case I am only using 10 seconds worth which is the -c 10 value. change this to suit.\n    # eg a value of 60 would be pne minute.\n    # Quit immediately if we get a single frame back.\n    # If neither server responds at all then reboot the firewall.\n    counting=$(ping -o -s 0 -c 10 185.95.218.42 | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }' )\n\n    if &#91; $counting -eq 0 ]; then\n\n        counting=$(ping -o -s 0 -c 10 130.59.31.248 | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }' )\n\n        if &#91; $counting -eq 0 ]; then\n            # trying to just restart NIC\n            # echo \"ping_check: ping fail - trying interface down\/up\" &gt;&gt; $LOGFILE \n            # wall $LOGFILE \n            # rm $LOGFILE \n            # ifconfig igb0 down\n            # ifconfig igb0 up\n            sleep 20\n            # echo \"ping_check: ping fail - Interface reset - trying pings again.\" &gt;&gt; $LOGFILE \n            #wall $LOGFILE  \n            # rm $LOGFILE \n            counting=$(ping -o -s 0 -c 10 185.95.218.42 | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }' )\n            if &#91; $counting -eq 0 ]; then\n                # network down\n                echo \"Network down - restart Firewall...\" &gt;&gt; $LOGFILE\n                wall $LOGFILE\n                # Save RRD data &amp;&amp; clean reboot\n                \/usr\/local\/etc\/rc.reboot\n            fi\n        fi\n    fi\nfi<\/code><\/pre>\n\n\n\n<p>Kopiere das Bash-Script nach \/usr\/local\/etc\/rc.d und stelle sicher, dass es \u00fcber das execute-flag verf\u00fcgt<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chmod 755 \/usr\/local\/etc\/rc.d\/ping_check.sh<\/code><\/pre>\n\n\n\n<p>Nun noch das neu erstellte Script im System als Cron-Job einrichten. Ich f\u00fchre den Ping alle zwei Minuten durch:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.dev-metal.ch\/wp-content\/uploads\/2022\/06\/Cron-OpnSense.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"524\" src=\"https:\/\/www.dev-metal.ch\/wp-content\/uploads\/2022\/06\/Cron-OpnSense-1024x524.png\" alt=\"\" class=\"wp-image-1625\" srcset=\"https:\/\/www.dev-metal.ch\/wp-content\/uploads\/2022\/06\/Cron-OpnSense-1024x524.png 1024w, https:\/\/www.dev-metal.ch\/wp-content\/uploads\/2022\/06\/Cron-OpnSense-300x154.png 300w, https:\/\/www.dev-metal.ch\/wp-content\/uploads\/2022\/06\/Cron-OpnSense-768x393.png 768w, https:\/\/www.dev-metal.ch\/wp-content\/uploads\/2022\/06\/Cron-OpnSense-2x1.png 2w, https:\/\/www.dev-metal.ch\/wp-content\/uploads\/2022\/06\/Cron-OpnSense.png 1363w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Links<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li><a rel=\"noreferrer noopener\" href=\"https:\/\/forum.netgate.com\/topic\/64563\/pfsense-auto-reboot-script-when-google-is-unreachable\/17\" target=\"_blank\">https:\/\/forum.netgate.com\/topic\/64563\/pfsense-auto-reboot-script-when-google-is-unreachable\/17<\/a><\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li><a rel=\"noreferrer noopener\" href=\"https:\/\/forum.opnsense.org\/index.php?topic=18865.msg86224#msg86224\" target=\"_blank\">https:\/\/forum.opnsense.org\/index.php?topic=18865.msg86224#msg86224<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Ich betreibe meine OpnSense Firewall hinter einer UPC Giga Connect Box. Diese ist auf Bridge-Modus gestellt, so dass alle Requests direkt an die OpnSense Firewall gelangen. Hin und wieder scheint UPC etwas zu maintainen. In der Folge verliert OpnSense die connectivity auf dem WAN-Port. Je nachdem wie h\u00e4ufig die UPC Unterhalt betreibt, fliegt die connectivity [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[10],"tags":[],"class_list":["post-1617","post","type-post","status-publish","format-standard","hentry","category-techdocs"],"modified_by":"ralph","_links":{"self":[{"href":"https:\/\/www.dev-metal.ch\/index.php?rest_route=\/wp\/v2\/posts\/1617","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dev-metal.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dev-metal.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dev-metal.ch\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dev-metal.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1617"}],"version-history":[{"count":11,"href":"https:\/\/www.dev-metal.ch\/index.php?rest_route=\/wp\/v2\/posts\/1617\/revisions"}],"predecessor-version":[{"id":1636,"href":"https:\/\/www.dev-metal.ch\/index.php?rest_route=\/wp\/v2\/posts\/1617\/revisions\/1636"}],"wp:attachment":[{"href":"https:\/\/www.dev-metal.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dev-metal.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1617"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dev-metal.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}