Configuration Manual: Site-to-Site IPsec VPN on pfSense
The main aspect we need to look at is the IKE endpoint configuration, Phase 1 Proposal peer keys, phase 1 proposal, expiration and...
2 pfSense VPN Tunnel
Sección titulada «2 Túnel de VPN de PFsense»The main aspect we must look at is the configuration of the IKE endpoint, the Phase 1 Proposal peer keys, the phase 1 proposal, and the expiration and replacement to establish a secure connection.
This is a classic configuration of Site-to-Site VPN (Site to Site). For the IPsec tunnel to be established, the 'Phase 1' is responsible for authenticating the two teams and establishing an initial secure channel.
The golden rule is: The encryption configuration must be IDENTICAL on both sides, but the IP addresses and identifiers are crossed (are mirrors).
Here we will see how to configure each field in pfSense 1 and in pfSense 2.
Example Scenario
Sección titulada «Escenario de Ejemplo»- pfSense 1 (Local): Public IP
1.1.1.1 - pfSense 2 (Remote): Public IP
2.2.2.2
Phase 1 Configuration (General and Authentication)
Sección titulada «Configuración Fase 1 (General y Autenticación)»This section defines who connects with whom.
| Field (Options) | Configuration in pfSense 1 | Configuration in pfSense 2 |
|---|---|---|
| IKE Endpoint Configuration | ||
| Key exchange version | IKEv2 (Recommended) | IKEv2 |
| Internet Protocol | IPv4 | IPv4 |
| Interface | WAN | WAN |
| Remote gateway | 2.2.2.2 (pfSense 2 Public IP) | 1.1.1.1 (pfSense 1 Public IP) |
| Phase 1 Proposal (Authentication) | ||
| Authentication method | Mutual PSK | Mutual PSK |
| My identifier | My IP address | My IP address |
| Peer identifier | Peer IP address | Peer IP address |
| Pre-Shared Key | ClaveSecretaMuyLarga123! | ClaveSecretaMuyLarga123! |
Phase 1 Configuration (Encryption Algorithms)
Sección titulada «Configuración Fase 1 (Algoritmos de Encriptación)»This section defines the tunnel security. It must be EXACTLY THE SAME on both sides. If even a single parameter differs, the tunnel will not connect.
We have selected a modern, fast, and secure configuration (compatible with recent hardware):
| Field | Configuration (Same on both pfSense) | Reason |
|---|---|---|
| Encryption algorithm | AES256-GCM | GCM is faster and more secure than CBC. |
| Key length | 128 bits (or 256 bits) | 128 is sufficient for GCM and very fast. |
| Hash | (Hidden or ignored if using GCM) | If we don't use GCM, we choose SHA256. |
| DH Group | 14 (2048 bit) or 21 (NIST ecp521) | Group 14 is the minimum standard today. 2, 5, or 1024 are insecure. |
Remaining Configuration (Timers and Advanced)
Sección titulada «Configuración Restante (Tiempos y Avanzado)»Generally, the default values work well, but we will ensure they match.
- Life Time:
28800(It is the standard for Phase 1). - Advanced Options -> Child SA Start Action:
- On pfSense 1: Initiate the connection.
- On pfSense 2: Responder Only.
- Note: We can set both to “Initiate” or “Default”, but defining one as the initiator helps avoid collisions.
- Dead Peer Detection (DPD): Enable DPD. This is crucial so that if the internet is cut off, the tunnel knows how to reconnect automatically.
- Delay:
10 - Maximum number of failures:
5
- Delay:
Summary of Critical Steps
Sección titulada «Resumen de Pasos Críticos»- We will copy the Pre-Shared Key into a notepad and paste it exactly the same on both. An extra blank space will cause it to fail.
- We will ensure that the Firewall rules (IPsec Tab) on both pfSense allow traffic (ESP Protocol and UDP ports 500 and 4500).
- Once Phase 1 is saved, we will be asked to configure Phase 2 (which are the local LAN networks we are going to connect, e.g.: 192.168.1.0/24 <-> 192.168.2.0/24).
Would you like to proceed with the “Phase 2” configuration to define the LAN networks?
This document details the procedure to interconnect two sites (Site A and Site B) using pfSense and validate the connection with Linux clients.
1. Scenario and Topology
Sección titulada «1. Escenario y Topología»Before configuring, we define the data. It is vital not to confuse local IPs with remote ones.
pfSense A (Site 1)
Sección titulada «pfSense A (Sede 1)»- WAN IP (Public):
1.1.1.1(Example) - LAN IP (Gateway):
192.168.61.1 - LAN Subnet:
192.168.61.0/24
pfSense B (Site 2)
Sección titulada «pfSense B (Sede 2)»- WAN IP (Public):
2.2.2.2(Example) - LAN IP (Gateway):
192.168.62.1 - LAN Subnet:
192.168.62.0/24
2. pfSense A Configuration (Site 1)
Sección titulada «2. Configuración de pfSense A (Sede 1)»We will navigate to VPN > IPsec > Tunnels.
Step 2.1: Phase 1 (Authentication)
Sección titulada «Paso 2.1: Fase 1 (Autenticación)»Click on “Add P1”
- General Information:
- Key Exchange version: IKEv2
- Internet Protocol: IPv4
- Interface: WAN
- Remote Gateway:
2.2.2.2(pfSense B WAN IP)
- Phase 1 Proposal (Authentication):
- Authentication Method: Mutual PSK
- My identifier: My IP address
- Peer identifier: Peer IP address
- Pre-Shared Key:
TuClaveSecretaMuySegura123(Must be identical on both sides)
- Phase 1 Proposal (Encryption):
- Algorithm: AES256-GCM
- Key Length: 128 bits
- Hash: SHA256 (If we use GCM, the hash is ignored, but we will include it just in case)
- DH Group: 14 (2048 bit)
- We will save.
Step 2.2: Phase 2 (Networks)
Sección titulada «Paso 2.2: Fase 2 (Redes)»We will click on “Show Phase 2 Entries” below the created Phase 1, then “Add P2”
- General Information:
- Mode: Tunnel IPv4
- Local Network:
- Type: LAN subnet (Automatically selects
192.168.61.0/24)
- Type: LAN subnet (Automatically selects
- Remote Network:
- Type: Network
- Address:
192.168.62.0/24(The LAN network of pfSense B)
- Phase 2 Proposal (SA/Key Exchange):
- Protocol: ESP
- Encryption Algorithms: AES256-GCM (128 bits)
- PFS Key Group: 14 (2048 bit)
- We will save and apply changes.
3. pfSense B Configuration (Site 2)
Sección titulada «3. Configuración de pfSense B (Sede 2)»We will navigate to VPN > IPsec > Tunnels. The configuration is a "mirror" of the previous one.
Step 3.1: Phase 1 (Authentication)
Sección titulada «Paso 3.1: Fase 1 (Autenticación)»Click on “Add P1”
- General Information:
- Remote Gateway:
1.1.1.1(pfSense A WAN IP)
- Remote Gateway:
- Phase 1 Proposal (Authentication):
- Pre-Shared Key:
TuClaveSecretaMuySegura123(Exactly the same)
- Pre-Shared Key:
- Phase 1 Proposal (Encryption):
- Exactly the same as in pfSense A (AES256-GCM, DH 14, etc).
Step 3.2: Phase 2 (Networks)
Sección titulada «Paso 3.2: Fase 2 (Redes)»We will click on “Add P2”
- Local Network:
- Type: LAN subnet (Will automatically be
192.168.62.0/24)
- Type: LAN subnet (Will automatically be
- Remote Network:
- Type: Network
- Address:
192.168.61.0/24(The pfSense A LAN network)
- Phase 2 Proposal:
- Exactly the same as in pfSense A.
- We will save and apply changes.
4. Enable the Firewall (Both pfSense)
Sección titulada «4. Habilitar el Firewall (Ambos pfSense)»By default, pfSense blocks VPN traffic. We must allow it on both routers.
- We will go to Firewall > Rules.
- We will click on the IPsec tab.
- We will click on Add.
- Action: Pass
- Interface: IPsec
- Protocol: Any
- Source: Any
- Destination: Any
- We will save and apply changes.
5. Client Configuration (Trinux/Linux)
Sección titulada «5. Configuración de Clientes (Trinux/Linux)»We will configure the machines within the LAN networks.
Client A (Behind pfSense A)
Sección titulada «Cliente A (Detrás de pfSense A)»- IP:
192.168.61.10 - Subnet Mask:
/24(or255.255.255.0) - Gateway:
192.168.61.1
Commands (if not using DHCP):
# Configurar IP y Máscara (Correcta)ip addr add 192.168.61.10/24 dev eth0ip link set eth0 up
# Opción A (Recomendada): Configurar Gateway por defectoip route add default via 192.168.61.1
# Opción B (Solo si no puedes cambiar el default gateway): Ruta estática# IMPORTANTE: Usar "via", NUNCA usar solo "dev" para redes remotasip route add 192.168.62.0/24 via 192.168.61.1Client B (Behind pfSense B)
Sección titulada «Cliente B (Detrás de pfSense B)»- IP:
192.168.62.10 - Subnet Mask:
/24(or255.255.255.0) - Gateway:
192.168.62.1
Commands:
ip addr add 192.168.62.10/24 dev eth0ip link set eth0 upip route add default via 192.168.62.1# O ruta estática específica:# ip route add 192.168.61.0/24 via 192.168.62.16. Verification Tests
Sección titulada «6. Pruebas de Verificación»Test 1: Tunnel Status
Sección titulada «Prueba 1: Estado del Túnel»- In pfSense, we will go to Status > IPsec.
- Phase 1 must say Established.
- Phase 2 must show the subnets and the “Connected” button.
Test 2: Ping from pfSense (Internal Diagnosis)
Sección titulada «Prueba 2: Ping desde pfSense (Diagnóstico interno)»This verifies that the tunnel is working without involving the clients.
- In pfSense A, we will go to Diagnostics > Ping.
- Host:
192.168.62.1(Remote LAN IP). - Source Address: LAN (Crucial).
- If it responds, the tunnel is working perfectly.
Test 3: Client-to-Client Ping
Sección titulada «Prueba 3: Ping de Cliente a Cliente»From Client A terminal (61.10):
ping 192.168.62.10If it fails, we will check:
- Windows/Linux firewall on the destination client (iptables/ufw).
- That the client subnet mask is
/24. - That the client gateway is the pfSense IP.
7. Appendix: Using pfctl -d
Sección titulada «7. Anexo: Uso de pfctl -d»The pfctl command is the Packet Filter control tool (the pfSense BSD system firewall).
What is pfctl -d used for?
Sección titulada «¿Para qué sirve pfctl -d?»The -d flag means Disable.
This command completely turns off the firewall and Network Address Translation (NAT). It allows all traffic to pass without restrictions.
Usage: We will access pfSense via console (SSH or direct terminal) and execute:
pfctl -dWe will see the message: pf disabled.
When to use it?
Sección titulada «¿Cuándo usarlo?»We will use it only for diagnostics when we suspect a firewall rule is blocking traffic and we cannot find which one it is.
- If, upon performing
pfctl -d, the VPN ping starts working magically, we will confirm that our problem was a rule in Firewall > Rules. - If it still doesn't work after doing so, the problem is routing or tunnel configuration, not rules.
How to reactivate it?
Sección titulada «¿Cómo reactivarlo?»To turn the firewall back on without restarting:
pfctl -e(Set the -e flag to Enable). We will see pf enabled.
WARNING
Do not use it in a production environment directly connected to the Internet for a long time, as we leave the network completely exposed.

