PfSense & Mikrotik IPsec Tunnel Guide
Mastering pfSense and Mikrotik IPsec Tunnels: A Comprehensive Guide
Hey guys! Today, we’re diving deep into the world of secure networking by setting up IPsec tunnels between two powerhouses: pfSense and Mikrotik . If you’re looking to connect different networks securely over the internet, maybe for remote access or site-to-site VPNs, you’ve come to the right place. We’ll break down everything you need to know, from the nitty-gritty configuration steps to common troubleshooting tips. So, grab your favorite beverage, and let’s get this tunnel built!
Table of Contents
Why IPsec Tunnels? The Security Backbone of Your Network
So, why bother with IPsec tunnels , especially when you’ve got pfSense and Mikrotik devices ready to go? IPsec (Internet Protocol Security) is a suite of protocols used to secure internet protocol (IP) communications by authenticating and encrypting each IP packet of a communication session. Think of it as a highly secure, encrypted highway for your data traveling across the public internet. In today’s world, where cyber threats are more sophisticated than ever, encrypting your traffic is not just a good idea; it’s essential. IPsec tunnels provide a robust solution for creating secure connections between your networks, ensuring that sensitive data remains confidential and intact. This is especially critical for businesses that need to connect branch offices, allow remote employees secure access to the corporate network, or simply protect their internal communications from prying eyes. The pfSense IPsec tunnel configuration and Mikrotik IPsec tunnel setup are the cornerstones of building these secure links. When you successfully establish an IPsec tunnel, you create a virtual private network (VPN) that behaves as if your remote networks were directly connected. This allows devices on one network to communicate with devices on the other network as if they were in the same physical location, all while their data is protected by strong encryption and authentication mechanisms. The flexibility and security offered by IPsec make it a go-to solution for network administrators worldwide. Whether you’re a small business owner trying to save on expensive dedicated leased lines or a large enterprise looking to enhance your security posture, implementing IPsec tunnels between your firewalls like pfSense and Mikrotik is a strategic move that pays dividends in terms of security, cost-effectiveness, and operational flexibility. We’ll cover the setup for both pfSense and Mikrotik, ensuring you have the knowledge to secure your digital pathways.
Getting Started: Prerequisites and Planning
Before we jump into the actual configuration, let’s ensure you’ve got everything you need. First off, you’ll need two devices capable of running IPsec – in our case, a
pfSense
firewall and a
Mikrotik
router. Make sure both devices have stable internet connections and can reach each other publicly (or at least via a routable IP address). You’ll also need to decide on your IP addressing scheme. It’s crucial that the
local networks
you intend to connect do not have overlapping IP address ranges. For example, if your pfSense network is
192.168.1.0/24
and your Mikrotik network is
192.168.1.0/24
, you’re going to have a bad time. You’ll need to re-IP one of them to something unique, like
192.168.2.0/24
. Planning this out ahead of time will save you a massive headache later. Think about what traffic you want to send through the tunnel. Do you need to access servers, internal resources, or just general internet traffic from the remote site? This will influence your firewall rules and IPsec policy settings. Also, consider your
Phase 1 and Phase 2
settings. These are the crucial encryption and authentication parameters that your devices will use to establish and maintain the tunnel. Common choices include AES-256 for encryption and SHA256 for hashing, with DH groups like 14 or 19. You’ll need to ensure these settings are
identical
on both your pfSense and Mikrotik devices. It’s like agreeing on a secret handshake; both sides have to use the same one! For authentication, you can use Pre-Shared Keys (PSK) or certificates. PSK is simpler to set up initially but less secure and scalable than certificates. For this guide, we’ll focus on PSK for ease of understanding, but keep certificates in mind for more robust deployments. Finally, know the public IP addresses of both your pfSense and Mikrotik devices. These will be used as endpoints for your IPsec tunnel. Having a clear understanding of your network topology, IP addressing, and desired security parameters is key to a successful
pfSense Mikrotik IPsec tunnel
implementation. Don’t rush this planning phase; a little foresight now will prevent a lot of troubleshooting later. It’s the foundation upon which your secure connection will be built.
Configuring IPsec on pfSense: The First Step
Alright, let’s get our hands dirty with the
pfSense IPsec tunnel
configuration. Log into your pfSense web interface. Navigate to
VPN > IPsec
. First, we need to set up
Phase 1
. Click
‘Add P1’
. For
Interface
, select your WAN interface.
Remote Gateway
is the
public IP address
of your Mikrotik router. For
Authentication Method
, choose
‘Mutual PSK’
(Pre-Shared Key) if you plan to use a shared secret, or ‘Mutual RSA’ if you’re using certificates. We’ll stick with PSK for this example. Now, for the
Pre-Shared Key
, enter a strong, complex secret key. Make sure this is something you can remember or store securely, as you’ll need the exact same key on your Mikrotik.
Encryption Algorithm
should be set to something strong like
AES
with a
256-bit key
.
Hash Algorithm
could be
SHA256
.
DH Group
should be set to a reasonably strong group, like
14
or higher.
Lifetime
is typically set to
28800
seconds (8 hours). Once Phase 1 is configured, click
‘Save’
.
Now, we need to configure
Phase 2
. After saving Phase 1, you’ll see an option to add Phase 2. Click
‘Show Phase 2 Entries’
and then
‘Add P2’
. For
Mode
, select
‘Tunnel IPv4’
.
Local Network
should be your pfSense LAN subnet (e.g.,
192.168.1.0/24
).
Remote Network
will be your Mikrotik LAN subnet (e.g.,
192.168.2.0/24
). Ensure the
Protocol
is set to
ESP
. For the encryption and hash algorithms in Phase 2, it’s best practice to match Phase 1 settings (e.g.,
AES 256-bit
and
SHA256
), though sometimes simpler options are used here.
PFS key group
should ideally match the Phase 1 DH group or be set to ‘off’ if you don’t need Perfect Forward Secrecy for Phase 2 (though enabling it is recommended).
Lifetime
for Phase 2 is typically
3600
seconds (1 hour). Click
‘Save’
.
Finally, you’ll need to configure
Firewall Rules
. Go to
Firewall > Rules > IPsec
. You need to allow traffic
from
your remote network
to
your local network, and vice versa. Add a rule to permit traffic from your Mikrotik subnet (e.g.,
192.168.2.0/24
) to your pfSense subnet (e.g.,
192.168.1.0/24
). Also, add a rule to permit traffic from your pfSense subnet to your Mikrotik subnet. Ensure these rules are placed correctly in your firewall rule order. Don’t forget to
Apply Changes
at the top of the page. The
pfSense IPsec tunnel
setup is almost complete! Your pfSense box is now prepped to establish a secure link.
Setting up IPsec on Mikrotik: The Other Half of the Tunnel
Now, let’s configure the Mikrotik IPsec tunnel . Log in to your Mikrotik router’s web interface (Winbox is generally preferred for Mikrotik). Navigate to IP > IPsec .
First, let’s define the Peer . Click the ‘Peers’ tab and then the ’+’ button to add a new peer.
- Address: Enter the public IP address of your pfSense firewall.
- Profile: Usually, you’ll create a new profile here or use the ‘default’. For simplicity, let’s create a new one. Click the dropdown and select ‘new’.
- Exchange Mode: Set this to ‘IKEv2’ (preferred) or ‘main’ for IKEv1.
- Authentication Method: Choose ‘Pre shared key’ .
- Secret: Enter the exact same strong, complex Pre-Shared Key you used on pfSense.
-
Proposal:
Click the ‘+’ to create a new proposal. We’ll call it ‘PFSense-Proposal’.
- Auth Algorithms: Select SHA256 .
- Encr. Algorithms: Select AES-256-CBC .
- DH Group: Select the same DH group as Phase 1 on pfSense (e.g., modp2048 which corresponds to DH group 14).
-
Lifetime:
Set this to
1d 0h 0m 0s(24 hours) or match your pfSense Phase 1 lifetime. Click OK to save the proposal and select it.
- NAT Traversal: Enable this if either end of the tunnel is behind NAT. Click OK to save the peer.
Next, we need to define the Policies . Click the ‘Policies’ tab and then the ’+’ button.
- Peer: Select the peer you just created.
-
Src. Address:
This is your
local
Mikrotik LAN subnet (e.g.,
192.168.2.0/24). -
Dst. Address:
This is your
remote
pfSense LAN subnet (e.g.,
192.168.1.0/24). - Protocol: Set this to ‘esp’ .
- Action: Set this to ‘encrypt’ .
- Level: Set to ‘require’ .
- IPsec Protocols: Select ‘esp’ .
- Proposal: Select the proposal you created earlier (e.g., ‘PFSense-Proposal’).
- Tunnel: Check this box if you are creating a tunnel. Click OK to save the policy.
Finally, you need to ensure your Firewall Rules allow traffic to pass. Go to Firewall > Filter Rules .
-
Add a rule to accept traffic coming
from
your pfSense LAN subnet (e.g.,
192.168.1.0/24) to your Mikrotik LAN subnet (e.g.,192.168.2.0/24). Ensure theIPsecprotocol is selected in the advanced options if needed, or that the general IP traffic is allowed. - Add another rule to accept traffic from your Mikrotik LAN subnet to your pfSense LAN subnet. Make sure these rules are placed appropriately, typically in the ‘forward’ chain, and before any general ‘drop’ rules. The Mikrotik IPsec tunnel setup is now complete! You should see the tunnel establish shortly.
Verifying the Tunnel and Troubleshooting Common Issues
So, you’ve gone through the configurations on both your pfSense and Mikrotik devices. How do you know if it’s actually working? Let’s check!
On pfSense , go to Status > IPsec . You should see your tunnel listed with a green