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

    Use ipv4 default gateway as variable in a script

    Scheduled Pinned Locked Moved General pfSense Questions
    8 Posts 4 Posters 507 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.
    • GPz1100G
      GPz1100
      last edited by

      Needing to add some lines to /etc/rc.gateway_alarm .

      Don't want to reference the wan interface directly as that may change. Is there a built in variable for the interface used for the default wan_dhcp (ipv4) gateway?

      The interface in question is igb0.2 and sure I can reference it that way, but prefer a more elegant way in case that changes.

      GertjanG K 2 Replies Last reply Reply Quote 0
      • GertjanG
        Gertjan @GPz1100
        last edited by

        @GPz1100

        The very fist variable in that file called '$GW' !

        GW="$1"
        

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

        GPz1100G 1 Reply Last reply Reply Quote 0
        • GPz1100G
          GPz1100 @Gertjan
          last edited by

          @Gertjan You missed the question. I don't need the gateway name, I need the interface name.

          1 Reply Last reply Reply Quote 0
          • stephenw10S
            stephenw10 Netgate Administrator
            last edited by

            The script can apply to any gateway it just depends what is passed to it.

            There are functions to find the real interface name from the internal interface or gateway though. Like: https://github.com/pfsense/pfsense/blob/master/src/etc/inc/interfaces.inc#L5956

            GPz1100G 1 Reply Last reply Reply Quote 0
            • K
              Konstanti @GPz1100
              last edited by

              @GPz1100

              Hi
              If you need dpinger to call a script with the real interface name, you need to make changes to the gwlb.inc file.

              It is in this file that a string of parameters is formed with which dpinger is called (the identifier parameter "-i").

              I am not a developer, but I would personally try to change the line (by making a backup copy of the source file)

              $params .= "-i {$gateway['name']} ";

              on

              $params .= "-i “ . convert_friendly_interface_to_real_interface_name({$gateway['name']) . “ “;

              1 Reply Last reply Reply Quote 0
              • GPz1100G
                GPz1100 @stephenw10
                last edited by GPz1100

                Thanks for the suggestions. Using these functions is outside my skill level (barely familiar with bash, let alone php).

                The problem I'm trying to resolve is every 2 weeks (14 days) + a few min, I loose connectivity. This is related to my att bypass - original install using external ont+bgw, now sfp straight to switch, with certs.

                There's a few other things to try but if I can't fix it properly, connectivity is restored at the next dhcp renewal (lease time of 3600s) of 0-30min following the loss. Connectivity is also restored if a manual renewal is done using /sbin/dhclient -c /var/etc/dhclient_wan.conf {INTERFACE}. I've verified this works on several times now - issue ongoing since I implemented the sfp bypass.

                File /var/etc/dhclient_wan.conf references the needed interface right there in the first line, so using some shell commands its possible to extract that.

                WAN_INTERFACE_TO_RENEW=$(cat /var/etc/dhclient_wan.conf | head -n 1 | cut -f 2 -d '"' -s)

                /sbin/dhclient -c /var/etc/dhclient_wan.conf $WAN_INTERFACE_TO_RENEW

                Not sure how this would work in a multiwan arrangement, but such is not the case here.

                GPz1100G 1 Reply Last reply Reply Quote 0
                • GPz1100G
                  GPz1100 @GPz1100
                  last edited by

                  The code below is what I came up with in the /etc/rc.gateway_alarm

                  .
                  .
                  .
                  # after above signal the check_reload_status process calls the following scripts simultaneously.:
                  # - "/etc/rc.dyndns.update", "dyndns=%s"
                  # - "/etc/rc.ipsec", "interface=%s"
                  # - "/etc/rc.openvpn", "interface=%s"
                  # - "/etc/rc.filter_configure_sync"
                  
                  ################# addition below.
                  
                  #ip used to verify internet connectivity
                  testip="8.8.8.8"
                  
                  #obtain wan interface
                  
                  WAN_INTERFACE_RENEW=$(cat /var/etc/dhclient_wan.conf | head -n 1 | cut -f 2 -d '"' -s)
                  #GW="WAN_DHCP"
                  
                  if [ $GW = "WAN_DHCP" ] && ! ping -c 2 -W 1000 $testip >/dev/null 2>&1      ; then
                    logger -s -t "ATT14DAY" "Forced dhcp renew due to 14 day outage" >/dev/null 2>&1
                  #  sleep 10
                    /sbin/dhclient -c /var/etc/dhclient_wan.conf $WAN_INTERFACE_RENEW
                    sleep 2
                    logger -s -t "ATT14DAY" "$WAN_INTERFACE_RENEW Interface DHCP renewal complete" >/dev/null 2>&1
                  else
                     exit $?
                  fi
                  
                  

                  Hard to simulate a wan loss while wan is still plugged in. Toggled sfp vlan on the switch for testing, effectively disconnecting the sfp while keeping the wan ethernet link up.

                  GPz1100G 1 Reply Last reply Reply Quote 2
                  • GPz1100G
                    GPz1100 @GPz1100
                    last edited by

                    The above got put into action this evening. Apparently it's been 2 weeks already since the last disconnect. Entire outage lasted about 6 s while dhcp renewed and other services refreshed.

                    Im quite confident this is not a pfsense issue but rather att. I will post a thread on reddit, perhaps someone knows something I don't.

                    The other option is to reconnect the att provided ONT back into the loop instead of the third party sfp stick. Wait 2 weeks to see if it disconnects too.

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