VirtualBox NAT port forwarding allows you to map host ports to guest services, while a Host-Only adapter provides direct internal network access. By configuring the NAT adapter’s port rules and adding a second Host-Only interface, you can securely expose specific applications without compromising the guest’s isolation from the broader local network.
Understanding the Network Architecture
Before modifying settings, it is crucial to understand how VirtualBox handles traffic. The NAT (Network Address Translation) adapter acts as a gateway, allowing the guest to access the internet through the host’s IP address while keeping the guest hidden from other devices on your local LAN. However, by default, incoming connections from the host are blocked for security reasons. Port forwarding overrides this restriction for specific ports. The Host-Only adapter creates a private virtual network between the host and the guest. Unlike NAT, it does not provide internet access by default unless routed, but it offers a stable, low-latency connection ideal for development or file sharing. Combining these two adapters gives you the best of both worlds: external connectivity via NAT and secure, direct access via Host-Only.Configuring NAT Port Forwarding
To forward ports, you must edit the network settings for the specific virtual machine. Open VirtualBox and select your Windows 10 guest, then click Settings. Navigate to the Network tab. Ensure that Adapter 1 is enabled and set to NAT. Under the advanced section of Adapter 1, click the Port Forwarding button. This opens the NAT Rules dialog. Click the plus icon to add a new rule. You will need to define four key parameters:- Name: A descriptive label, such as "Web Server" or "SSH".
- Protocol: Select TCP or UDP depending on the service. For web servers, use TCP.
- Host IP: Leave blank to bind to all host interfaces, or specify
127.0.0.1to restrict access to localhost only. - Host Port: The port on your physical Windows 10 machine that clients will connect to (e.g., 8080).
- Guest IP: Usually left blank, which assigns the rule to the first available guest IP.
- Guest Port: The port inside the guest VM where the service is running (e.g., 80 for HTTP).
http://localhost:8080.
If you encounter issues with SSH connections, ensure your account has sufficient privileges, as detailed in our guide on unable to establish SSH connection from Windows 10 to Ubuntu 22.04 guest with non-admin account. Administrative rights are often required to bind to privileged ports or manage network interfaces correctly.
Adding a Host-Only Adapter
While NAT port forwarding is useful for specific services, it can be cumbersome for general access. Adding a Host-Only adapter creates a separate network interface within the guest. Go back to Settings > Network. Enable Adapter 2 and change the attachment type to Host-Only Adapter. VirtualBox typically creates a virtual network namedvboxnet0 by default. If it is not listed, go to the File menu, select Tools, and then Host Network Manager to create a new host-only network. Assign this network to Adapter 2 in the VM settings.
Once the guest boots up, it will receive an IP address from the DHCP server associated with the Host-Only network. On a Windows 10 guest, you can find this IP by opening Command Prompt and running ipconfig. Look for the IPv4 address under the VirtualBox Host-Only Ethernet Adapter section. You can now ping this IP directly from your host machine, providing a stable endpoint for development workflows.
Note that creating multiple adapters can sometimes lead to confusion if Windows automatically generates random network interfaces. To maintain stability, refer to our article on how to prevent Windows 10 from creating random new network adapters to keep your virtual networking environment clean and predictable.
Troubleshooting Connectivity
If port forwarding fails, verify that the firewall on your Windows 10 host is not blocking the inbound traffic. Add an inbound rule for the specific host port you configured. Inside the guest, ensure the service is listening on the correct port and not bound exclusively to localhost if you expect external access. For Host-Only issues, check that the guest’s network interface is actually connected. Sometimes, disabling and re-enabling the adapter in the guest OS resolves IP assignment glitches. If you are using linked clones for testing environments, remember that their network configurations might inherit settings differently, so review understanding VirtualBox linked clones for Windows 10 to avoid configuration conflicts.Frequently Asked Questions
Can I use both NAT and Host-Only adapters simultaneously?
Yes, VirtualBox supports multiple active network adapters per VM. NAT handles outbound internet traffic, while Host-Only provides a private link to the host. This setup is common for development environments where you need external dependencies but also direct local access.Why does my host firewall block forwarded ports?
Windows Firewall may block incoming connections on non-standard ports. You must manually create an inbound rule in Windows Defender Firewall for the specific host port you mapped in VirtualBox, allowing TCP traffic on that port.How do I find the IP address assigned by the Host-Only adapter?
Inside the guest OS, runipconfig on Windows or ifconfig / ip addr on Linux. Look for the adapter labeled "VirtualBox Host-Only Ethernet Adapter" or similar. The IPv4 address listed there is what you use to connect from the host.
Is it safe to expose guest ports to the entire network?
No, exposing ports via NAT can make the guest visible to other devices on your LAN if the host IP is used instead of localhost. Restricting the Host IP field to127.0.0.1 ensures only the host machine can access the forwarded ports, maintaining better security.