Zum Inhalt springen

Fritz!Box 7490 7.27 IPsec VPN to PFsense

Settung up VPN connections with a Fritz!Box is not complicated. Though this took me a while to figure out which proposals and hashing algorithms work in a IKEv1 IPsec between a FritzBox 7490 with FritzOS 7.27 and a PFsense 2.5…. And still these connections are far from beeing stable….
Unfortunatelly a proper and secure setup with modern settings is not documented well by AVM – the vendor of the Fritz!Box equipment. One can find a list of proposals on the internet – but these two documents seem to be outdated.

I read somewhere that modern Hashing-Algorithms are supported – like DH 14 and DH 15 – but they do not work for me yet …

Update 2021/06/06: I changed the key lifetime in Phase 1 to 3600 because with 28800 the tunnel broke after 102 minutes :-/ Hours later i recognized that also with 3600s lifetime the tunnel was torn down after 102 minutes …

Update 2021/06/07: So it turned out, after a couple more research on the net, things should not have been that “difficult”… The pfsense in version 2.5 had serious issues regarding ipsec – i wanted to stay with this version to have wireguard tunnels. But right now IPsec is more important to me so i cleared the wireguard config and updated to 2.5.1 and testing starts over. If this proves to be stable, The tunnels are stable again and running for about 36 hours – several renegoations survived. Maybe i can now re-evaluate a more secure setup with DH groups 14 or 15 …

Right now the following setup works quite good – not with the best parameters in terms of security ( only DH Group 2):

Update 2021/06/08: Finally after patching pfsense i found my sweet spot. AES-256 / SHA512 with DH 15 (3072) works stable and uses current algorithms. Parameters in pfsense screenshots reflect the old settings – just modify them to the DH 15 settings in phase 2 (PFS key group).

PFsense settings

Phase 1 on PFsense:

Key exchange version: IKEv1
Remote Gateway: DynDns-Name of the FritzBox
Authentication method: Mutual PSK
Negotiation mode: Aggressive
My identifier: DynDns-Name of the PFsense
Peer identifier: DynDns-Name of the Fritzbox
Encryption Algorithms: AES 256 bits Hash SHA512 DH Group 2
LifeTime: 28800 3600

Phase 2 on PFsense:

Protocol: ESP
Encryption Algorithms: AES 256 bits
Hash Algorithms: SHA512
PFS Key Group: 2
Lifetime: 3600

Fritz!Box vpn.cfg – DH2 – LT3600

vpncfg {
    //--------------------------------------------
    // 
    // FB 7490 FritzOS 7.27
    // Pfsense:
    // IKEv1 Aggressive Mode
    // Phase 1 AES 256 bit SHA512 DH 2 LT3600
    // Phase 2 AES 256 bit SHA512 DH 2 LT3600
    // DPD on
    // 
    //--------------------------------------------	
   connections { 		
	enabled = yes;
	editable = yes;
	conn_type = conntype_lan; 		
	name = "Name_of_the_VPN"; 		// Change to your name	
	boxuser_id = 0;							
	always_renew = yes;
	reject_not_encrypted = no;
	dont_filter_netbios = yes; 		
	localip = 0.0.0.0; 		
	local_virtualip = 0.0.0.0; 		
	remoteip = 0.0.0.0;  // Public IP of your PFsense 		
	remote_virtualip = 0.0.0.0; 		
	remotehostname = "somename.ddnss.de"; //Hostname of your PFsense 		
	keepalive_ip = 192.168.1.1; 		
	localid { 			
		fqdn = "fritzbox.ddnss.de";  //Hostname of your FritzBox		
		} 
	remoteid {
		fqdn = "somename.ddnss.de";  	//Hostname of your PFsense 		
		} 	
        mode = phase1_mode_aggressive;	
        // mode = phase1_mode_idp;
	phase1ss  = "all/all/all";
	keytype = connkeytype_pre_shared; 	
	key = "SomeSuperRandomKey";  // pre-shared-key - the longer the better 	
	cert_do_server_auth = no; 		
	use_nat_t = yes; 		
	use_xauth = no; 		
	use_cfgmode = no; 		
	phase2localid 	{ 			
	     ipnet 	{ 				
		ipaddr = 192.168.178.0;  	// Local Subnet of your fritzbox
		mask = 255.255.255.0; 			
			} 		
        		} 		
	phase2remoteid { 			
	      ipnet 	{ 			
		ipaddr = 192.168.1.0;  	// Subnet of the remote fritzbox			
		mask = 255.255.255.0; 			
			}
			} 
	phase2ss = "esp-aes256-3des-sha/ah-no/comp-lzs-no/pfs";						
	accesslist = "permit ip any 192.168.1.0 255.255.255.0";  // Permit only these nets or hosts
	} 	
	ike_forward_rules = "udp 0.0.0.0:500 0.0.0.0:500",
	"udp 0.0.0.0:4500 0.0.0.0:4500";
}

Further testings shall be proper DH Groups and maybe extended key lifetimes.

Fritz!Box vpn.cfg – DH15 – LT 3600 / 28800

I’m going to test this setting only on specifying the lifetime on pfsense … we’ll see lifetime will be stable

vpncfg {
    //--------------------------------------------
    // 
    // FB 7490 FritzOS 7.27
    // Pfsense:
    // IKEv1 Aggressive Mode
    // Phase 1 AES 256 bit SHA512 DH 15 LT3600 - should also tolerate 28800
    // Phase 2 AES 256 bit SHA512 DH 15 LT3600 
    // DPD on
    // 
    //--------------------------------------------  
   connections {        
    enabled = yes;
    editable = yes;
    conn_type = conntype_lan;       
    name = "Name_of_the_VPN";       // Change to your name  
    boxuser_id = 0;                         
    always_renew = yes;
    reject_not_encrypted = no;
    dont_filter_netbios = yes;      
    localip = 0.0.0.0;      
    local_virtualip = 0.0.0.0;      
    remoteip = 0.0.0.0;  // Public IP of your PFsense       
    remote_virtualip = 0.0.0.0;         
    remotehostname = "somename.ddnss.de"; //Hostname of your PFsense        
    keepalive_ip = 192.168.1.1;         
    localid {           
        fqdn = "fritzbox.ddnss.de";  //Hostname of your FritzBox        
        } 
    remoteid {
        fqdn = "somename.ddnss.de";     //Hostname of your PFsense      
        }   
        mode = phase1_mode_aggressive;  
        // mode = phase1_mode_idp;
    phase1ss  = "dh15/aes/sha";
    keytype = connkeytype_pre_shared;   
    key = "SomeSuperRandomKey";  // pre-shared-key - the longer the better  
    cert_do_server_auth = no;       
    use_nat_t = yes;        
    use_xauth = no;         
    use_cfgmode = no;       
    phase2localid   {           
         ipnet  {               
        ipaddr = 192.168.178.0;     // Local Subnet of your fritzbox
        mask = 255.255.255.0;           
            }       
                }       
    phase2remoteid {            
          ipnet     {           
        ipaddr = 192.168.1.0;   // Subnet of the remote fritzbox            
        mask = 255.255.255.0;           
            }
            } 
    phase2ss = "esp-aes256-3des-sha/ah-no/comp-lzs-no/pfs";                     
    accesslist = "permit ip any 192.168.1.0 255.255.255.0";  // Permit only these nets or hosts
    }   
    ike_forward_rules = "udp 0.0.0.0:500 0.0.0.0:500",
    "udp 0.0.0.0:4500 0.0.0.0:4500";
}

Bear in mind that having a good “key” is crucial having a secure tunnel. The longer and more random the key is, the better. But sometimes devices and firmware do have trouble using a key that is too long or has too many special characters. In this setup i used a key 56 chars long consisting of characters and numbers. Another consideration is to setup the tunnel in main mode to have the initiating of the connection encrypted.

To have traffic flow through the tunnel don’t forget to craft a firewall rule on the ipsec-interface to let desired traffic pass.

Update 2021/06/09: AVM kindly answered my request where to find the supported cipher and hashing algorithms. Thanks again to Andy P.

Generally Fritz!Boxes support IPsec with ESP with IKEv1 and pre-shared keys – AH and PFS are not supported.

For key exchange DH2 is initally used, later on all the DH groups mentioned below are supported. DH group for phase 2 is defined by phase 1.

Config entries for phase 1:

dh5/aes/sha;
dh14/aes/sha;
dh15/aes/sha;
def/all/all;
alt/all/all;
all/all/all;
LT8h/all/all/all;

Config entries for phase 2:

esp-3des-sha/ah-no/comp-no/pfs;
esp-3des-sha/ah-no/comp-no/no-pfs;
esp-aes256-3des-sha/ah-no/comp-lzs-no/pfs;
esp-aes-sha/ah-all/comp-lzjh-no/pfs;
esp-all-all/ah-all/comp-all/pfs;
esp-all-all/ah-all/comp-all/no-pfs;
esp-all-all/ah-none/comp-all/pfs;
esp-all-all/ah-none/comp-all/no-pfs;
LT8h/esp-all-all/ah-none/comp-all/pfs;
LT8h/esp-all-all/ah-none/comp-all/no-pfs;
esp-null-sha/ah-no/comp-no/no-pfs;