Use ipv4 default gateway as variable in a script
-
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.
-
-
@Gertjan You missed the question. I don't need the gateway name, I need the interface name.
-
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
-
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']) . “ “;
-
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.
-
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.