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

    Auto-renew DHCP after outage

    Scheduled Pinned Locked Moved DHCP and DNS
    53 Posts 21 Posters 28.4k 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.
    • O
      ohbobva @e4ch
      last edited by

      @e4ch Thanks for the script. Just what I needed. I modified it to log to system.log, which uses the clog system, so the log won't get big...

      #!/bin/sh
      wan="em5"
      
      currip=$(ifconfig $wan | grep "inet " | cut -d " " -f 2)
      if test -z "$currip"; then
      	logger `date +%Y%m%d.%H%M%S` "pingtest - Detected empty IP on $wan! Will try again in 120 seconds."
      	sleep 120
      	currip=$(ifconfig $wan | grep "inet " | cut -d " " -f 2)
      	if test -z "$currip"; then
      		logger `date +%Y%m%d.%H%M%S` "pingtest - 2nd try: Still empty IP on $wan! Will fix now."
      		ifconfig $wan down
      		sleep 10
      		ifconfig $wan up
      		sleep 20
      		dhclient $wan
      		logger `date +%Y%m%d.%H%M%S` "pingtest - Fixing done!"
      	else
      		logger `date +%Y%m%d.%H%M%S` "pingtest - 2nd try: $wan has IP $currip; ok"
      	fi
      else
      	logger `date +%Y%m%d.%H%M%S` "pingtest - $wan has IP $currip; ok"
      fi
      
      A E 2 Replies Last reply Reply Quote 3
      • A
        axxxxe @ohbobva
        last edited by

        Thank you @e4ch and @ohbobva! I am also on UPC in Switzerland and the script has fixed it for me.

        1 Reply Last reply Reply Quote 0
        • E
          EricE @ohbobva
          last edited by

          @ohbobva @e4ch thanks for your scripts! This just hit my parents pfSense install - stupid cable went out (and of course they insist nothing is wrong) and pfSense did not automatically reconnect the WAN. I had my mom manually refresh the WAN interface and it came right back up. How annoying! Hopefully they can permanently fix it now that the root cause appears to be evident; in the meantime hopefully this script will take care of it the next time they flake out and swear nothing is wrong but then it magically starts working right after they complain.

          1 Reply Last reply Reply Quote 0
          • GertjanG
            Gertjan
            last edited by

            @EricE : see https://forum.netgate.com/topic/148017/dhcp-client-issue

            No "help me" PM's please. Use the forum, the community will thank you.
            Edit : and where are the logs ??

            1 Reply Last reply Reply Quote 0
            • B
              Brian Smit
              last edited by

              Thank You for the scripts!!
              Are the scripts still needed in the latest version of PFsense or is this bug fixed?

              Regards

              Brian

              E 1 Reply Last reply Reply Quote 0
              • E
                EricE @Brian Smit
                last edited by

                @Brian-Smit

                @Brian-Smit said in Auto-renew DHCP after outage:

                Thank You for the scripts!!
                Are the scripts still needed in the latest version of PFsense or is this bug fixed?

                I still needed them for my parents firewall.

                1 Reply Last reply Reply Quote 1
                • B
                  Brian Smit
                  last edited by

                  Then i indeed also keep using them. I didn't have any issues anymore with Ziggo

                  1 Reply Last reply Reply Quote 0
                  • W
                    Wirepower
                    last edited by Wirepower

                    So I tried your script, works well.
                    Pings and says in log that IP is up. However gateway monitor still says down. Have changed monitor IP to Google and still says down. I would need to renew wan lease in order to get it back up. Keep in mind that when gateway monitor is down, the script can still ping and says it’s ok.

                    So I’m confused why on status/interface it says up but in gateway monitor it says down.
                    Is there a script that would automatically release and renew if either gateway monitor shows down or interface?

                    1 Reply Last reply Reply Quote 0
                    • A
                      axxxxe
                      last edited by

                      Can someone tell me if the patch to dhclient is still needed for 2.4.5? I just upgraded to 2.4.5 and am wondering if I now need to include the patch mentioned at the link below, or if the patch is already included in the 2.4.5 I just installed.

                      https://redmine.pfsense.org/issues/9267

                      1 Reply Last reply Reply Quote 0
                      • GertjanG
                        Gertjan
                        last edited by

                        Click on your own link, find the line that says :

                        Patch to pfSense-dhclient-script was applied on 2.4.5 as well
                        

                        That was 8 month ago.

                        No "help me" PM's please. Use the forum, the community will thank you.
                        Edit : and where are the logs ??

                        A 1 Reply Last reply Reply Quote 0
                        • A
                          axxxxe @Gertjan
                          last edited by

                          Yes, I was uncertain about if this meant it was included in version 2.4.5 or if he was reporting that when he applied the patch to 2.4.5 it worked. I assume from your response it's the former.

                          GertjanG 1 Reply Last reply Reply Quote 0
                          • GertjanG
                            Gertjan @axxxxe
                            last edited by

                            @axxxxe said in Auto-renew DHCP after outage:

                            uncertain

                            The patch was initially targeted for 2.5.0, but finally back ported to 2.4.5(-p1).
                            I had to read the patch story twice also ;)

                            No "help me" PM's please. Use the forum, the community will thank you.
                            Edit : and where are the logs ??

                            1 Reply Last reply Reply Quote 0
                            • T
                              tsmalmbe
                              last edited by

                              Setting timeouts and other options worked well on 2.4.5 but after updating to 2.6.0 my WAN does not survive even the first change in DHCP. It goes down and stays down until I reboot the modem. This really really sucks again.

                              Security Consultant at Mint Security Ltd - www.mintsecurity.fi

                              T 1 Reply Last reply Reply Quote 1
                              • T
                                tsmalmbe @tsmalmbe
                                last edited by

                                @tsmalmbe I tweaked and poked with the custom values and it sorta works again. That said, the ip changes very rarely (not even weekly) so it is hard do say if this works or not. Seems like something that nevertheless should be easy to fix.

                                Security Consultant at Mint Security Ltd - www.mintsecurity.fi

                                A 1 Reply Last reply Reply Quote 0
                                • A
                                  Afflicted4917 @tsmalmbe
                                  last edited by

                                  @tsmalmbe did you ever solve the problem?

                                  GertjanG 1 Reply Last reply Reply Quote 0
                                  • GertjanG
                                    Gertjan @Afflicted4917
                                    last edited by

                                    @Afflicted4917

                                    2.4.5 isn't used anymore.
                                    Most of the 2.6.0 is probably upgraded to 2.7.0
                                    Why don't you ?

                                    Can you packet capture the WAN interface, port 67 and 68.
                                    You'll see the DHCP (pfsense as a client) requests for sure.
                                    You'll see also the DHCP server, from your ISP router, or, if you use a bridge device, from an DHCP server located at the ISP site coming back. Do they make it to your pfSense ? If they don't : the uplink connection is bad ? ( ! )

                                    No "help me" PM's please. Use the forum, the community will thank you.
                                    Edit : and where are the logs ??

                                    1 Reply Last reply Reply Quote 0
                                    • A
                                      appleredwoodpancakes
                                      last edited by appleredwoodpancakes

                                      I'm not sure if my problem has something to do with the OPs initial problem. But I read the whole thread and I am seeing similar issues in my setup.
                                      Also the hardware and location match. I'm a customer of Magenta who took over UPC as some posters mentioned. I always had these connection problems followed by longer periods where everything worked. I always assumed the ISP hardware to be faulty. That's also the reason why I use Pfsense.

                                      My setup is:

                                      ISP modem (bridge mode)
                                      -> pfsense box (old thinkpad with built in nic for WAN and USB ethernet adapter for LAN) >
                                      -> 2 dumb APs for WiFi

                                      My entire network drops every couple of days. I can't connect via wifi nor via LAN. My devices and Pfsense GUI are not reachable. I can only access Pfsense shell via the PfSense box/thinkpad. I can ping to 8.8.8.8 but no device in my network is pingable (send to error).

                                      Both WAN and LAN gateway are assigned the usual IPs. Usually only a restart of the PfSense box helped. But today I observed something strange.

                                      I didn't want to reboot and replaced the WAN interface with a second USB Lan adapter and reassigned the interface via Pfsense shell. Suddenly the local network was reachable again and I had internet although with a slightly different public IP. Internet was very unstable. Pings resulted in packet losses until it completely died down. But the local network was pingable the whole time.

                                      Searched the logs for hints but I'm too inexperienced. Didn't recognize anything severe though.

                                      After tinkering around I assigned the WAN back to the original NIC. Unexpectedly internet came back with the old public ip.

                                      I know this will happen again but I have no clue why. I eliminated any hardware problems one after another also switched cables and tried a ton of gateway, routing and other settings. Nothing helps.

                                      This setup ran stable for months until I updated to version 2.7. that's when all this started. So I suspect Pfsense to be the problem here. 2.7.1 was worse with daily issues. 2.7.2 stays on 2-3 days. Shortly after the update even 6 days.

                                      I have no idea what to do. Tried many steps in this Reddit post but not everything https://www.reddit.com/r/PFSENSE/comments/n4miga/pfsense_doesnt_recover_if_wan_fails_solutions/

                                      Also flashed a fresh Pfsense without any additional packages to no avail.

                                      After that I can only go the way with a script and reboot. Im my case I have to execute the reboot when I can't ping to my local network.

                                      If anyone has an idea I'm all ears.
                                      Cheers

                                      GertjanG 1 Reply Last reply Reply Quote 0
                                      • GertjanG
                                        Gertjan @appleredwoodpancakes
                                        last edited by

                                        @appleredwoodpancakes said in Auto-renew DHCP after outage:

                                        I can't ping to my local network

                                        And your LAN uses a USB dongle device ....
                                        You are aware that an USB ethernet should be used for very temporary setups ?
                                        Don't fall for it if it seems to work for a short moment. An NIC draws a lot of current, far more as a classic USB thumb nail drive. The slights movement on the USB contacts will introduce a pwoer loss on the power hungry NIC chips and line drivers, and giess what : you didin't find the very big capacitor to even out the power, because there are non (to small). So the NIC gets a kick in the had after a power glitch, doesn't wake up in a good state.
                                        The OS isn't informed about the power down power up state, as it was to fast, to short.
                                        But the link will be 'bad'.
                                        Ok,this is me showing you what might happen when you use 'usb' ethernet stuff : it's a big messy, uncharted territory.
                                        This type of issues go all away as soon as you remove USB from the equitation.

                                        USB NICs is a typical "even if you can, you shouldn't" thing.

                                        No "help me" PM's please. Use the forum, the community will thank you.
                                        Edit : and where are the logs ??

                                        A 1 Reply Last reply Reply Quote 1
                                        • A
                                          appleredwoodpancakes @Gertjan
                                          last edited by

                                          Hi @Gertjan
                                          Thank you for your feedback. I read a lot about this USB ethernet topic that it is not a good idea but I never saw a detailed explanation. It makes sense. I never "believed" it because my setup was running so well until now. But I wanted to change the setup anyways so that I only run one LAN cable from the NIC and one cable from the WAN to a managed switch via VLANs. What do you think?

                                          I know I could get me the proper hardware with 2 NICs but I just don't want to give up the ThinkPad. I'm too stubborn for it.

                                          GertjanG 1 Reply Last reply Reply Quote 0
                                          • GertjanG
                                            Gertjan @appleredwoodpancakes
                                            last edited by Gertjan

                                            @appleredwoodpancakes said in Auto-renew DHCP after outage:

                                            I never saw a detailed explanation.

                                            Me neither.
                                            But way in the past, when computer stuff was more a 'electric' and 'electronic' thing, a lot has been found out the last 3, 4, 5 decades, power was an issue.
                                            See it like this :
                                            A NIC uses quiet a lot of power : the 2 pairs of ether cable wires uses (tens of) milli amps over the wire, and frequencies used are just phenomenal.
                                            As stated above, the electrical USB contacts are just plain 'bad' and power filtering is hard to do on such a small device. Or, the electrics used needs a real good stable power.
                                            USB can drive 'a lot of power (100+ millli mps)' but they were never designed for this. The power they offer is not enough stabilized, but ok for a charger or a light bulb.
                                            Another (silly) reason : USB NIC are created for one type users ^^ Let's say it like this : not the professional ones. So, what do you think of the quality of the USB NIC driver is ? (a NIC driver is as complex as your best Nvidia GPU driver ) : they probably stopped development as soon as it 'works' for 5 minutes.

                                            To make the she shorter : just don't use them. it's just isn't worth it.
                                            This also some what excludes the usage of a laptop as a router. The laptop still has a usage, though, use it as a dumb console terminal access device for your one and only router : a small devices with 2+ NIC"s build in, and a serial port, or, why, not HDMI+keyboard access.
                                            It will be using even less power also. And you've a rock solid connection.
                                            Yo can start with some 'old PC', remove (disable in BIOS) all stuff that you don't need such as 'sound', inspect the mother board NIC and if it says : "I'm a Realtek" then disable that one also.
                                            Get an Intel based 2 or 4 NIC 1 Gbits network card and you'll be good for the better part of your live.

                                            No "help me" PM's please. Use the forum, the community will thank you.
                                            Edit : and where are the logs ??

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