Ir al contenido

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...

0views

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.

  • 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 1Configuration in pfSense 2
IKE Endpoint Configuration
Key exchange versionIKEv2 (Recommended)IKEv2
Internet ProtocolIPv4IPv4
InterfaceWANWAN
Remote gateway2.2.2.2 (pfSense 2 Public IP)1.1.1.1 (pfSense 1 Public IP)
Phase 1 Proposal (Authentication)
Authentication methodMutual PSKMutual PSK
My identifierMy IP addressMy IP address
Peer identifierPeer IP addressPeer IP address
Pre-Shared KeyClaveSecretaMuyLarga123!ClaveSecretaMuyLarga123!

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):

FieldConfiguration (Same on both pfSense)Reason
Encryption algorithmAES256-GCMGCM is faster and more secure than CBC.
Key length128 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 Group14 (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
  1. 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.
  2. We will ensure that the Firewall rules (IPsec Tab) on both pfSense allow traffic (ESP Protocol and UDP ports 500 and 4500).
  3. 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.

Before configuring, we define the data. It is vital not to confuse local IPs with remote ones.

  • WAN IP (Public): 1.1.1.1 (Example)
  • LAN IP (Gateway): 192.168.61.1
  • LAN Subnet: 192.168.61.0/24
  • WAN IP (Public): 2.2.2.2 (Example)
  • LAN IP (Gateway): 192.168.62.1
  • LAN Subnet: 192.168.62.0/24

We will navigate to VPN > IPsec > Tunnels.

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.

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)
  • 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.

We will navigate to VPN > IPsec > Tunnels. The configuration is a "mirror" of the previous one.

Click on “Add P1”

  • General Information:
    • Remote Gateway: 1.1.1.1 (pfSense A WAN IP)
  • Phase 1 Proposal (Authentication):
    • Pre-Shared Key: TuClaveSecretaMuySegura123 (Exactly the same)
  • Phase 1 Proposal (Encryption):
    • Exactly the same as in pfSense A (AES256-GCM, DH 14, etc).

We will click on “Add P2”

  • Local Network:
    • Type: LAN subnet (Will automatically be 192.168.62.0/24)
  • 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.

By default, pfSense blocks VPN traffic. We must allow it on both routers.

  1. We will go to Firewall > Rules.
  2. We will click on the IPsec tab.
  3. We will click on Add.
    • Action: Pass
    • Interface: IPsec
    • Protocol: Any
    • Source: Any
    • Destination: Any
  4. We will save and apply changes.

We will configure the machines within the LAN networks.

  • IP: 192.168.61.10
  • Subnet Mask: /24 (or 255.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 eth0
ip link set eth0 up
# Opción A (Recomendada): Configurar Gateway por defecto
ip 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 remotas
ip route add 192.168.62.0/24 via 192.168.61.1
  • IP: 192.168.62.10
  • Subnet Mask: /24 (or 255.255.255.0)
  • Gateway: 192.168.62.1

Commands:

ip addr add 192.168.62.10/24 dev eth0
ip link set eth0 up
ip 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.1
  1. In pfSense, we will go to Status > IPsec.
  2. Phase 1 must say Established.
  3. Phase 2 must show the subnets and the “Connected” button.

This verifies that the tunnel is working without involving the clients.

  1. In pfSense A, we will go to Diagnostics > Ping.
  2. Host: 192.168.62.1 (Remote LAN IP).
  3. Source Address: LAN (Crucial).
  4. If it responds, the tunnel is working perfectly.

From Client A terminal (61.10):

ping 192.168.62.10

If it fails, we will check:

  1. Windows/Linux firewall on the destination client (iptables/ufw).
  2. That the client subnet mask is /24.
  3. That the client gateway is the pfSense IP.

The pfctl command is the Packet Filter control tool (the pfSense BSD system firewall).

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 -d

We will see the message: pf disabled.

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.

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.