Apache on Ubuntu in VirtualBox: Forwarding Port 80 to Windows 11 Host (Port 22222)

Abstract: Configure VirtualBox NAT port forwarding to map host port 22222 to guest port 80 for accessing an Ubuntu Apache server from Windows 11.

Created: 2026-08-26 by
To forward port 80 from an Ubuntu Apache server in VirtualBox to your Windows 11 host on port 22222, configure the virtual machine’s network adapter as a NAT device. Within the Network Settings, navigate to Port Forwarding rules and add a new entry mapping host port 22222 to guest port 80. This setup allows you to access your local web server via http://localhost:22222 in any browser on the host machine without exposing the guest directly to the external network.

Configuring the VirtualBox Network Adapter

The foundation of this configuration lies in how VirtualBox handles network traffic for your virtual machine. By default, most installations use the "NAT" (Network Address Translation) mode, which isolates the guest OS from the host's local network while allowing outbound internet access. To enable port forwarding, you must interact with the specific settings of this NAT interface.

  1. Shut down your Ubuntu virtual machine completely if it is currently running. Changes to network adapters often require the VM to be powered off to apply correctly.
  2. Select the Ubuntu VM in the VirtualBox Manager list and click the Settings button (gear icon).
  3. In the left-hand menu, select Network.
  4. Ensure that the Attached to dropdown is set to NAT. If it is already set to NAT, proceed to the next step. Do not change this to Bridged or Host-only unless you have a specific reason to do so, as NAT is the simplest method for local development access.
  5. Click the Advanced section at the bottom of the panel to expand additional options.
  6. Locate the Port Forwarding button and click it to open the rule editor.

Creating the Port Forwarding Rule

Once the Port Forwarding dialog box is open, you will see a table listing existing rules. Typically, SSH (port 22) might already have a rule here if you previously configured remote access. You need to add a new rule specifically for HTTP traffic.

  • Click the Add button (green plus icon) to create a new rule.
  • In the Name field, enter a descriptive label such as Apache-Web. This helps you identify the rule later if you add more services.
  • In the Protocol dropdown, select TCP. Web servers rely on TCP connections for reliable data transmission.
  • In the Host IP field, leave it blank. Leaving this empty tells VirtualBox to listen on all available network interfaces on your Windows 11 machine, including localhost (127.0.0.1).
  • In the Host Port field, enter 22222. This is the port number your Windows 11 browser will use to connect to the VM.
  • In the Guest IP field, leave it blank. This directs traffic to whatever IP address the Ubuntu guest currently holds within the NAT network.
  • In the Guest Port field, enter 80. This is the standard port where Apache listens for incoming web requests.

After entering these details, click OK to save the rule, then click OK again to close the Settings window. Your configuration is now saved permanently for this virtual machine.

Verifying Apache is Running in Ubuntu

Before testing the connection, ensure that the Apache service is actually active inside the Ubuntu guest. Sometimes, after a fresh install or update, the service may not start automatically.

Boot your Ubuntu VM and log in. Open the terminal and run the following command to check the status:

sudo systemctl status apache2

If the service is inactive or failed, start it using:

sudo systemctl start apache2

To ensure it starts automatically on boot, enable it with:

sudo systemctl enable apache2

You can also verify that Apache is listening on port 80 by checking the network sockets:

sudo netstat -tlnp | grep :80

If you see a line indicating LISTEN on port 80, the server is ready to receive forwarded traffic.

Testing the Connection from Windows 11

Now that the infrastructure is in place, test the connectivity from your Windows 11 host. Open any web browser (Chrome, Firefox, Edge, etc.) and navigate to:

http://localhost:22222

You should see the default Apache2 Ubuntu Default Page. This confirms that the traffic is successfully passing through VirtualBox’s NAT engine, translating from your host's port 22222 to the guest's port 80.

If you encounter a "Connection Refused" error, several factors could be at play. First, ensure that no firewall on the Ubuntu guest is blocking port 80. While less common in minimal installs, you can check with:

sudo ufw status

If UFW is active, allow HTTP traffic with:

sudo ufw allow 80/tcp

Additionally, verify that your Windows 11 firewall is not blocking inbound connections on port 22222. Usually, VirtualBox handles its own firewall exceptions, but in rare cases, manual intervention is required. You can temporarily disable the Windows Firewall to test if it is the culprit, though this is not recommended for long-term security.

This setup provides a clean, isolated environment for web development. It prevents conflicts with other local services that might also want to use port 80 on your Windows machine. If you need to host multiple sites, you can add additional rules for different ports, such as mapping host port 22223 to guest port 80 for a second site, or mapping to port 443 for HTTPS.

For those who recently installed their operating system, refer to our guide on Installing Ubuntu 24.04 on VirtualBox 7.0.20 (Windows 11 PC) for initial setup steps. If you experience issues starting the VM after making network changes, check our troubleshooting article on PowerSuspend: VM Failed to Start or Interrupted in Oracle VirtualBox on Windows 11.

Frequently Asked Questions

Why am I getting a "Connection Refused" error?

This usually means the Ubuntu guest is not listening on port 80 or the firewall is blocking the connection. Verify that Apache is running with systemctl status apache2 and ensure UFW is not blocking port 80. Also, confirm that the VirtualBox port forwarding rule is correctly mapped to host port 22222.

Can I access the VM from another computer on my LAN?

No, not with NAT port forwarding alone. NAT only exposes the port to the host machine (localhost). To access the VM from other devices on your local network, you would need to switch the network adapter to "Bridged Adapter" mode and assign a static IP to the Ubuntu guest, or use a different routing strategy.

How do I stop Apache from running?

To stop the service temporarily, run sudo systemctl stop apache2 in the Ubuntu terminal. To prevent it from starting automatically at boot, use sudo systemctl disable apache2. Remember to remove or disable the corresponding port forwarding rule in VirtualBox if you no longer need access.

What if I want to use HTTPS instead of HTTP?

You can add another port forwarding rule in VirtualBox. Map a different host port (e.g., 22223) to guest port 443. Ensure that Apache has an SSL certificate configured and is listening on port 443 inside the Ubuntu guest. Then access it via https://localhost:22223.

Does this affect internet speed in the VM?

Port forwarding itself has negligible impact on performance. However, NAT mode shares the host's network connection. If your host machine is under heavy network load, the VM's internet access might slow down slightly. For high-performance networking needs, consider switching to a Bridged Adapter.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More