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

    Solution for WAN disconnect upon modem IP change

    Scheduled Pinned Locked Moved General pfSense Questions
    1 Posts 1 Posters 221 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.
    • 0
      0sbbl
      last edited by 0sbbl

      Hi All,

      Thought I would post In case this may be of help to someone else out there with this scenario.

      In my setup, the WAN interface connects to a 5G router in Bridge mode, using DHCP. This works great, until the external IP changes, for some reason this isn't pushed back to Pfsense.
      As a result, when this happened (every day or so), I would need to manually release and renew the WAN and it would be back up again.

      As a workaround to this, I wrote the following basic script to drop and bring the interface back up when the connection drops.

      Certainly not perfect and I'm sure there are neater solutions out there, however this is working really well for me, so sharing just in case it can help anyone else!

      • save below as 'network_check.csh'
      • Modify to reflect your interface name and email address (if using the email section)
      • chmod +x 'network_check.csh'
      • Set up CRON job to run script every one minute

      This will then send out a notification email whenever the script takes action (if setup).

      #!/bin/tcsh 
      
      #This Script was written to resolve an issue with PFSense which can arise when using a modem via DHCP on the WAN interface. 
      #If the internet connection drops out on the modem / upstream router, the interface may not know it needs to re-establish the connection, resulting in the internet / WAN connection going down until manaully relased and renewed. 
      
      #I reccomend you add a CRON job to run this script every 1 min
      
      #you will probably need to allow this file to execute with 'chmod +x network_check.csh'.
      
      ping -c 5 1.1.1.1 #tries to echo cloudflare primary DNS 5 times to reduce chance of false trigger. Exit code will only be '2' if 100% of packets are dropped.
      if ( "$?" == "2" ) then
      
      ping -c 1 9.9.9.9 && if ( "$?" == "2" ) then  #failover to Quadd9 DNS - just in case cloudflare is not replying, despite the internet connection being okay for whatever reason.
      
        echo "restarting WAN interface"
        /etc/rc.linkup interface=<YOUR_WAN_INTERFACE_HERE> action=stop && /etc/rc.linkup interface=<YOUR_WAN_INTERFACE_HERE> action=start
        echo 'script has reset WAN interface as no internet connection was detected' | /usr/local/bin/mail.php -s"network_script" "YOUR_EMAIL_ADDRESS" #needs SMTP notifications to be setup
        sleep 5m    #this is to prevent a runway condition in the event of the internet actually being down on the modem side. Otherwise you would have a LOT of emails for this!
                    #without the sleep, you would have potentionally 1440 emails per day! - with a 5 min sleep this is reduced to 288, 15 mins would give 120.
                    #set this as desired - depending on your prefered balance of emails vs possible downtime.	
      	      #Alternatavely, just disable the email alert if you don't want to know when this script is acting
      
      else
       echo "conection okay, exiting"
      endif
      exit (0)
      
      1 Reply Last reply Reply Quote 0
      • First post
        Last post
      Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.