Changing default gateway leaves 2 default gateways in config



  • This has been a "feature" for as long as I have been involved in pfSense. On a simple system, LAN, WAN, OPT1, WAN is default gateway. Edit OPT1 gateway, select "Default gateway", and save. The default route switches to the OPT1 gateway IP (good). But in the config both WAN and OPT1 are enabled as default gateway. They both show (default) on the GUI. The user has to also edit WAN, uncheck "Default Gateway" and save.
    There should only ever be 1 default gateway, shouldn't there?
    When editing a gateway and "Default Gateway" is checked, the code should automatically deselect "Default Gateway" on the gateway that is currently the default gateway?
    Or am I missing something?
    (Sometimes when I do this change of default gateways I have end up with no default route in the routing table - it happened to me this morning. But now I can't reproduce it on a test system, I have swapped back and forth a few times and the default route in the routing table is faithfully following the latest gateway selected as default route.)



  • I've heard that before but we've never been able to replicate it. When you mark some other gateway as default, it un-marks the previous default gateway. There's apparently some unusual circumstance in which it doesn't but no idea what that might be or how to replicate it. If you can find the magic circumstance where it's replicable that'd be helpful.



  • I think it is because 1 gateway is DHCP and the other has static IPv4. I guess the same problem would happen if both gateways are DHCP. Quickly looking at the code in system_gateways_edit.php, it only does the unset if both the gateway being modified and the gateway being checked in the loop have a proper IPv4 address. If the gateway setting is "dynamic" then that test won't work. It needs looking at to then see how to work out if the gateway is an IPv4 or IPv6 gateway_item (or can 1 gateway_item have both an IPv4 and IPv6 address? I haven't looked into all that). Looks like the same issue will happen for IPv6 gateways that are one of the "dynamic/DHCP" types.

    			/* remove the default gateway bits for all gateways with the same address family */
    			foreach($a_gateway_item as $gw) {
    				if(is_ipaddrv4($gateway['gateway']) && is_ipaddrv4($gw['gateway'])) {
    					unset($config['gateways']['gateway_item'][$i]['defaultgw']);
    					if ($gw['interface'] != $_POST['interface'] && $gw['defaultgw'])
    						$reloadif = $gw['interface'];
    				}
    				if(is_ipaddrv6($gateway['gateway']) && is_ipaddrv6($gw['gateway'])) {
    					unset($config['gateways']['gateway_item'][$i]['defaultgw']);
    					if ($gw['interface'] != $_POST['interface'] && $gw['defaultgw'])
    						$reloadif = $gw['interface'];
    				}
    				$i++;
    			}
    			$gateway['defaultgw'] = true;
    


  • All my pfsense 2.1 have this.

    I thought it's for load balancing:

    Allow default gateway switching
    If the link where the default gateway resides fails switch the default gateway to another available one.

    Does that means that load balacing switch to any gateway?
    Does it switch back?

    I asked this question once befor.



  • I have an issue where my openvpn gateway interface is acting as default gateway even though my wan is set as default.  Is this the same problem?  I just switched from 2.0.



  • In System->Routing you should be able to edit the gateways that you do NOT want to be the default, uncheck "Default Gateway", save. That should get rid of the extra default gateways. Make sure to leave 1 useful default gateway ;)



  • well, i faced this and reported also earlier, might not be exactly same but its related to default gateway switching etc

    http://forum.pfsense.org/index.php/topic,59697.0.html



  • @phil.davis:

    I think it is because 1 gateway is DHCP and the other has static IPv4. I guess the same problem would happen if both gateways are DHCP. Quickly looking at the code in system_gateways_edit.php, it only does the unset if both the gateway being modified and the gateway being checked in the loop have a proper IPv4 address. If the gateway setting is "dynamic" then that test won't work. It needs looking at to then see how to work out if the gateway is an IPv4 or IPv6 gateway_item

    Yeah that's it. It shouldn't be checking IP, it should check <ipprotocol>within that gateway entry. If any other gateway with the same <ipprotocol>has defaultgw set, unset it. I think the reason for that is a bug left over from before <ipprotocol>existed in the gateways entries.</ipprotocol></ipprotocol></ipprotocol>



  • @phil.davis:

    In System->Routing you should be able to edit the gateways that you do NOT want to be the default, uncheck "Default Gateway", save. That should get rid of the extra default gateways. Make sure to leave 1 useful default gateway ;)

    I know.  My wan gateway is the only marked at default, but it's not be using as default.  It will only default when I disable my the other gateway.


Log in to reply