This blog post will guide you through configuring port forwarding in Oracle VirtualBox. We’ll address a common performance bottleneck experienced with bridged networking and demonstrate how to achieve better network speeds using NAT (Network Address Translation) with Paravirtualized Networking and strategic port forwarding.
Our setup involves a Windows 11 host and an Ubuntu 24.10 LTS guest operating system.
The Initial Challenge: Bridged Networking and Slow Speeds
Initially, the environment was configured using bridged networking. While straightforward, this approach resulted in unacceptably low network speeds (0.6 Mbps upload, 25 Mbps download). This performance degradation motivated a shift to a NAT-based configuration with port forwarding.
Low Performance is due to the generic driver used on the Virtual Box for Bridge network.
Solution: NAT with Paravirtualized Network and Port Forwarding
The chosen solution involves leveraging NAT in conjunction with a Paravirtualized Network adapter and specific port forwarding rules. This approach offers a balance between network isolation and accessibility of services running on the guest OS.
VirtualBox Network Configuration Steps
-
Access Network Settings: Open Oracle VirtualBox, select your Ubuntu 24.10 LTS virtual machine, and click on “Settings.” Navigate to the “Network” section.
-
Adapter 1 Configuration: Ensure you’re configuring “Adapter 1.”
- Attached To: Set this to “NAT.”
- Adapter Type: Choose “Paravirtualized Network.”
-
Port Forwarding Rules: Click on “Port Forwarding.” This is where we’ll define the rules to allow traffic from the host machine to reach specific services on the guest machine.
-
Click the “+” button to add a new rule. For SSH access, configure the following:
- Name: SSH (you can name it as you wish)
- Protocol: TCP
- Host IP: Leave this blank. This tells VirtualBox to listen on all available host interfaces.
- Host Port:
9999
(You can choose any available port on your host machine.9999
is just an example.) - Guest IP: Leave this blank.
- Guest Port:
22
(Standard SSH port)
-
Click “OK” to save the port forwarding rule and then “OK” again to close the network settings.
-
With this configuration, any connection to port 9999 on the host machine will be forwarded to port 22 on the guest machine, effectively allowing you to SSH into the Ubuntu guest.
Setting up the SSH server on the Guest
First, ensure that the SSH server is installed on your Ubuntu guest. If it’s not already installed, you can install it with the following command:
sudo apt update
sudo apt install openssh-server
After installation, the SSH service should start automatically. You can check its status with:
sudo systemctl status ssh
If it is not running, start it with:
sudo systemctl start ssh
Connecting to the Guest via SSH
Now, you can connect to your Ubuntu guest from your Windows 11 host using the following SSH command in your terminal or SSH client (like PuTTY):
ssh <username>@localhost -p 9999
Replace <username>
with your actual username on the Ubuntu guest. You’ll be prompted for your password.
Troubleshooting
- Firewall: Ensure that your host firewall (Windows Defender Firewall) isn’t blocking connections to the specified host port (9999 in this example).
- Guest SSH Server: Verify that the SSH server is running correctly on the Ubuntu guest and listening on port 22.
- Port Conflicts: Make sure that the chosen host port (9999) is not already in use by another application on your Windows 11 host. You can use
netstat -ano
in the command prompt to list active connections and listening ports. - VirtualBox Networking Issues: If you’re still experiencing issues, try restarting the VirtualBox virtual machine and even your host machine.
Conclusion
By switching to NAT with a Paravirtualized Network adapter and carefully configuring port forwarding, you can often overcome the network speed limitations encountered with bridged networking in VirtualBox. This setup enables you to efficiently access services running on your guest operating system while maintaining a secure and isolated environment. Remember to adjust the port numbers and guest IP addresses according to your specific needs and environment.