Not getting redirected: Trying to access Apache2 server on Ubuntu 24.04 via VirtualBox - Networking issue

Abstract: Resolve Apache2 connection refused errors in Ubuntu 24.04 VirtualBox by configuring NAT port forwarding or bridged networking to enable host access.

Created: 2026-08-27 by
Accessing an Apache2 server on Ubuntu 24.04 inside VirtualBox requires configuring the host machine’s network adapter to allow traffic through to the guest. By default, NAT mode isolates the VM, preventing external access. Switching to Bridged Adapter or setting up port forwarding in NAT resolves this connectivity block immediately.

Understanding the Network Isolation

When you install Ubuntu 24.04 in VirtualBox, the virtual network interface card (NIC) is typically configured for NAT (Network Address Translation). This setup allows the guest OS to access the internet and other networks by routing traffic through the host’s IP address. However, it does not allow incoming connections from the host machine or other devices on the local network to reach services running inside the VM, such as Apache2. This isolation is a security feature designed to protect the host system. When you try to access localhost or the host’s IP address from your browser, the request never reaches the Apache2 process listening on port 80 inside the Ubuntu guest. Instead, the connection is either dropped or routed elsewhere, resulting in a "Connection Refused" or timeout error. To fix this, you must explicitly configure how network traffic flows between the host and the guest.

Method 1: Using Port Forwarding with NAT

Port forwarding is the least intrusive method because it keeps the VM behind the NAT firewall while exposing specific ports to the host. This approach is ideal if you want to keep the VM’s internal network configuration unchanged. First, shut down the Ubuntu 24.04 VM if it is currently running. Open the VirtualBox Manager and select your Ubuntu VM. Click on Settings, then navigate to the Network tab. Ensure that Attached to is set to NAT. Next, click the Advanced dropdown arrow to reveal additional options. In the Advanced section, locate the Port Forwarding button and click it. A new window will appear listing existing rules. Click the green plus icon to add a new rule. You will need to fill in the following fields:
  • Name: Give it a descriptive name like Apache-Web.
  • Protocol: Select TCP.
  • Host IP: Leave blank or enter 127.0.0.1 to restrict access to the host only.
  • Host Port: Enter 8080 (or any available port on the host).
  • Guest IP: Leave blank to target the VM’s primary IP.
  • Guest Port: Enter 80 (the default Apache port).
Click OK to save the rule, then OK again to close the settings. Start the Ubuntu VM. Once it boots, open your web browser on the host machine and navigate to http://localhost:8080. The traffic will be forwarded from the host’s port 8080 to the guest’s port 80, allowing you to view the Apache2 default page.

Method 2: Switching to Bridged Adapter

Bridged networking makes the VM appear as a distinct device on your physical network. It receives its own IP address from your router, just like a physical computer. This method provides full bidirectional access but requires your network environment to support it. Shut down the Ubuntu VM. Go to Settings > Network. Change Attached to from NAT to Bridged Adapter. In the Name dropdown, select the physical network interface your host is using (e.g., Wi-Fi or Ethernet). If you are unsure which one is active, check your host’s network status. Once applied, start the VM. Ubuntu will request an IP address via DHCP from your router. You can find this IP by running ip addr show in the terminal. Look for the inet address associated with your network interface (usually eth0 or ens33). Use this IP address from your host browser (e.g., http://192.168.1.50). Note that some corporate or university networks may block bridged adapters due to security policies. If the VM fails to obtain an IP, refer to our guide on How to Fix UFW Blocking KVM Guest from Getting IP Address and Accessing Network for troubleshooting similar network stack issues.

Verifying Apache2 Configuration

Even with correct network settings, Apache2 might still refuse connections if it is misconfigured. Ensure the service is active by running sudo systemctl status apache2. If it is inactive, start it with sudo systemctl start apache2. Check the Apache2 configuration file located at /etc/apache2/ports.conf. Ensure it contains Listen 80. Additionally, verify that the default site configuration in /etc/apache2/sites-enabled/000-default.conf is correctly pointing to the document root. Restart Apache2 after any changes using sudo systemctl restart apache2. If you are using a firewall like UFW, ensure it allows incoming HTTP traffic. Run sudo ufw allow http to permit port 80. For more details on firewall setups, see Setting Up a Firewall on Ubuntu Network Gateway for a Virtual Network with VirtualBox.

Troubleshooting Common Errors

If you still cannot connect, check the following:
  • Firewall Rules: Confirm that no host-side firewall is blocking the chosen port. On Windows, check Windows Defender Firewall; on macOS, check the built-in firewall settings.
  • IP Changes: In Bridged mode, the VM’s IP may change upon reboot. Consider setting a static IP in Ubuntu or using port forwarding for stability.
  • Service Binding: Ensure Apache2 is binding to 0.0.0.0 rather than just 127.0.0.1. Check /etc/apache2/ports.conf for this directive.
By adjusting these network parameters, you establish a reliable bridge between your host and the Ubuntu Apache2 server.

Frequently Asked Questions

Why does port forwarding fail when I use localhost?

Ensure that the Host IP field in the port forwarding rule is left blank or set to 127.0.0.1. If you enter a specific host IP that isn’t actively bound to the loopback interface, the connection may be refused. Also, verify that no other application is already using the host port you selected.

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

Yes, but only if you use Bridged Adapter mode. NAT mode with port forwarding typically restricts access to the host machine only. In Bridged mode, other devices can reach the VM using its assigned LAN IP address, provided their firewalls allow it.

What if my VM gets a different IP every time it starts?

This is common in Bridged mode due to DHCP. To resolve this, configure a static IP within Ubuntu’s Netplan configuration files. Alternatively, stick to Port Forwarding in NAT mode, which uses consistent host ports regardless of the guest’s changing IP.

Does Apache2 need special permissions to run in VirtualBox?

No, Apache2 runs normally within the guest OS. However, ensure it is started with sufficient privileges if you bind to ports below 1024. Running sudo systemctl start apache2 ensures the service has the necessary rights to listen on port 80.

How do I know if my firewall is blocking the connection?

Temporarily disable the firewall using sudo ufw disable to test connectivity. If the connection succeeds, re-enable the firewall with sudo ufw enable and add specific rules for HTTP and HTTPS traffic using sudo ufw allow http.

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