pfSense and OPNsense on a VPS: virtualization, network interfaces and use cases
pfSense and OPNsense are FreeBSD-based distributions that turn a machine into a full firewall and router with a web interface: filtering rules, NAT, VLANs, corporate IPsec and WireGuard tunnels, traffic monitoring. On a VPS they are installed to put your servers in a data centre behind a firewall, to link the cloud with the office, or to build a training lab. The table above lists hosts that have one of these distributions among their templates; below is what to check if there is no template or the network is set up in a non-standard way.
Virtualization and installing from your own ISO
Both distributions need a full virtual machine with its own kernel, that is KVM or an equivalent. They will not run on OpenVZ or LXC containers. If there is no ready template, installation is done from the official image: upload the ISO through the host's panel and go through the installer in the VNC console. Plans with this option are collected on the VPS with a custom ISO page. Before installing, write down the IP address, netmask and gateway from the panel: if the host does not hand out addresses via DHCP, you will have to enter them by hand.
The distributions differ in resource needs. pfSense CE formally requires a 64-bit processor, 1 GB of memory and an 8 GB disk, but with packages and logs it is more comfortable from 2 GB. OPNsense states a minimum of 3 GB of memory and recommends 8 GB and a bigger disk for the full feature set. Intrusion detection systems and a caching proxy use CPU and disk more heavily than filtering itself.
One or two cores are enough for routing and rules. Tunnel throughput is determined by encryption: if hundreds of megabits will flow through IPsec or WireGuard, you need fast cores with AES-NI support, which the virtual machine must be able to see. You can check this after installation in the system information section.
Network: virtio and a second interface
On KVM the network card is usually emulated as virtio, and FreeBSD sees it as vtnet0. The driver is built in, but there is a known quirk: hardware checksum offloading on virtual adapters can cause packet loss and dropped connections. Disable it right after installation: in pfSense under System → Advanced → Networking, in OPNsense in the interface settings.
A firewall comes into its own when there are two interfaces:
- WAN: the public address assigned by the host;
- LAN: the host's private network or VLAN, to which your other servers without public addresses are connected.
Then all traffic to the servers passes through the pfSense rules, and databases and internal services are not visible from outside. Before ordering, ask the host whether you can add a second interface and join machines into a private network: not everyone supports this. With a single interface pfSense protects only itself and is suitable as a corporate tunnel gateway or a lab. Also keep in mind filtering on the host's side: usually only the assigned IPs and MACs are allowed, so do not run a DHCP server in the public segment and do not assign other people's addresses.
What a firewall in the cloud is used for
- An edge firewall for a group of your own servers: common rules, NAT, a connection log and port forwarding in one interface.
- Linking the office with the data centre: a site-to-site IPsec or WireGuard tunnel between the office router and the cloud pfSense, after which internal servers are reachable at private addresses.
- Remote access for employees to the company's internal network through a corporate VPN with user accounts and certificates.
- A lab: practising rules, routing, VLANs and monitoring before rolling them out in the office.
If the office runs MikroTik routers, the central node can be built on RouterOS as well; compare with the VPS for MikroTik CHR selection. Those used to the command line rather than a web interface will be fine with plain FreeBSD on a VPS with pf.
Typical mistakes
- The web interface is open to everyone on WAN. Allow access to it only from your own addresses or through a tunnel.
- A rule that locks out the administrator. Keep the host's VNC console at hand: from it you can reset the rules and regain access.
- Updating without a backup. Before updating, export the configuration to XML and take a server snapshot: rolling back will take minutes.
- The default administrator password. Change it before scanners find the interface.
- Empty logs. Send firewall logs to a separate monitoring server: on a small VPS disk they are overwritten quickly, and there is nothing left to investigate an incident with.