
How to Install OPNsense on VirtualBox: A Complete Step-by-Step Guide
Building a secure network starts with a powerful, flexible firewall. Whether you’re a seasoned IT professional looking to test configurations or a student eager to dive into network security, creating a virtual lab is the perfect starting point. By installing OPNsense on VirtualBox, you can build a fully functional, enterprise-grade firewall and router without the need for dedicated hardware.
This guide will walk you through every step of the process, from initial virtual machine setup to accessing the OPNsense web interface for the first time.
Prerequisites: What You’ll Need
Before we begin, make sure you have the following two items ready:
- Oracle VM VirtualBox: The latest version of this free and powerful virtualization software should be installed on your computer.
- The OPNsense ISO Image: Download the latest stable version from the official OPNsense website. Choose the “dvd” image and the correct architecture for your system (usually amd64).
Step 1: Creating and Configuring the OPNsense Virtual Machine
First, we need to create a new virtual machine (VM) that will house our OPNsense installation.
- Open VirtualBox and click the “New” button.
- Name: Give your VM a descriptive name, such as “OPNsense Firewall”.
- Type: Select “BSD”.
- Version: Choose “FreeBSD (64-bit)”. OPNsense is based on FreeBSD, so this is a critical step.
- Memory Size: Allocate at least 2 GB (2048 MB) of RAM. While OPNsense can run on less, 2 GB provides a smooth experience, especially if you plan to use features like intrusion detection.
- Hard Disk: Select “Create a virtual hard disk now”. Choose “VDI (VirtualBox Disk Image)” and “Dynamically allocated”. For size, 20 GB is more than sufficient for the base installation and logging.
Step 2: Setting Up the Network Adapters
This is the most important part of the configuration. A firewall needs at least two network interfaces: one for the public-facing internet (WAN) and one for your private internal network (LAN).
In your new VM’s Settings, navigate to the “Network” section.
Adapter 1 (The WAN Interface):
- Enable this adapter.
- In the “Attached to” dropdown, select “Bridged Adapter”. This connects the VM’s WAN port directly to your physical network, allowing it to get an IP address from your main router, just like any other device in your home or office.
- Under “Name”, select the primary network adapter of your host computer (e.g., your Wi-Fi or Ethernet card).
Adapter 2 (The LAN Interface):
- Click on the “Adapter 2” tab.
- Enable this adapter.
- In the “Attached to” dropdown, select “Internal Network”. This creates a private, isolated network that only exists inside VirtualBox. Virtual machines connected to this same internal network will be able to communicate with each other through the OPNsense firewall.
- Give the network a name, such as
opnsense-lan.
Security Tip: This two-adapter setup isolates your virtual lab from your main network. Any test machines you create later will connect to the opnsense-lan internal network, forcing all their traffic through your new virtual firewall for analysis and control.
Step 3: Installing the OPNsense Software
With the VM configured, it’s time to install OPNsense.
- Go to the VM’s Settings > Storage.
- Under the “Controller: IDE” section, click the empty disc icon.
- On the right-hand side, click the disc icon again and select “Choose a disk file…”. Navigate to and select the OPNsense ISO file you downloaded earlier.
- Click “OK” to save the settings.
- Start the VM.
The virtual machine will now boot from the ISO image. After a short boot sequence, you will be prompted to log in.
- At the login prompt, enter the username
installerand the passwordopnsense.
The OPNsense installer will launch. For a standard setup, you can accept most defaults.
- Keymap Selection: Choose your preferred keyboard layout.
- Installation Type: Select “Guided installation” for the easiest setup.
- Select Disk: The installer will automatically detect the 20 GB virtual disk we created. Select it to proceed.
- Filesystem: Choose “ZFS” for a modern, robust filesystem.
- Confirmation: The installer will ask for a final confirmation before erasing the virtual disk. Select “Yes”.
The installation will now copy all the necessary files. Once complete, you will be prompted to set the root password. Choose a strong, secure password and then select “Complete Install”. The VM will shut down.
Important: Before starting the VM again, go back into Settings > Storage and remove the OPNsense ISO from the virtual CD/DVD drive. If you don’t, the VM will boot into the installer again.
Step 4: Initial Command-Line Configuration
Start the VM. It will now boot into your newly installed OPNsense system. After the boot process, you will be presented with a console menu. The first thing we need to do is tell OPNsense which network adapter is WAN and which is LAN.
- OPNsense will detect two interfaces (likely named
em0andem1). It will ask if you want to set up VLANs. Pressnfor No and hit Enter. - It will then ask you to enter the WAN interface name. This corresponds to Adapter 1 (the Bridged Adapter). Enter
em0and press Enter. - Next, it will ask for the LAN interface name. This is Adapter 2 (the Internal Network). Enter
em1and press Enter. - Confirm the assignments by pressing
y.
The system will now configure the interfaces. The WAN interface will get an IP from your main network, and the LAN interface will be assigned the default static IP address of 192.168.1.1.
Step 5: Accessing the Web Interface
You now have a running firewall! To manage it, you need to access its web-based graphical user interface (GUI). This must be done from a client machine on the LAN side of the firewall.
- Create another simple VM in VirtualBox (a lightweight Linux distro like Lubuntu is a great choice).
- In this new client VM’s network settings, set its only network adapter to “Internal Network” and select the same network name you used before (
opnsense-lan). - Start the client VM. It should automatically receive an IP address from your OPNsense firewall via DHCP (e.g., 192.168.1.100).
- Open a web browser in the client VM and navigate to
http://192.168.1.1.
You will be greeted with the OPNsense login page.
- Username:
root - Password: The secure password you set during installation.
Upon your first login, OPNsense will launch a setup wizard to help you with basic settings like hostname, domain, and DNS servers. Complete the wizard, and you will land on the main dashboard.
Congratulations! You have successfully installed and configured a powerful OPNsense firewall in VirtualBox. You now have a secure, isolated environment to learn about advanced networking, test firewall rules, set up a VPN, and explore the world of network security.
Source: https://kifarunix.com/how-to-install-opnsense-on-virtualbox/


