Can't Access Apache on VirtualBox VM (using NAT + Host-only)
I figured out what was causing the problem ... iptables
!
The configuration I have set up for the VM should work without any problem.
If anyone with the same setup is facing problems, checkout the following:
- System firewall (i.e.
iptables
) configuration; SELinux
configuration;
cheers :)
Related videos on Youtube
Seyed Mohammad
Updated on September 18, 2022Comments
-
Seyed Mohammad over 1 year
Short Description:
My host OS is Ubuntu-12.04 and using VirtualBox I have set up a VM of Oracle Linux 6.4 (based on RHEL) with Apache httpd web server. I need to access the web pages served by the VM from my host Ubuntu.
Additional Details:
Here are the configurations:
-
The 1st network adapter of the VM is configured as
NAT
, since I need it to use the host's Internet connection. See image below: -
I have enabled a 2nd adapter as Host-only, so I can access the VM from the host (
ssh
orscp
to guest VM from host, etc). This is working fine. The IP of the guest VM is manually set to10.10.10.15
and I can successfullyping
,ssh
andscp
to the guest VM without any problem. See below:
Inside the VM, I have set up Apache successfully and it's working for
localhost
but when I try to access the page from the host, by entering10.10.10.15
in Chromium or Firefox, it fails to connect!:(
I have also tried to add an entry inside
/etc/hosts
as follows, but enteringtest-website.net
inside Chromium or Firefox still gives the same error!:(
10.10.10.15 test-website.net
One more thing to note is about
SELinux
. As you might know,SELinux
is enabled by default on RHEL-based distros such as CentOS and Oracle-Linux. To make sure that SELinux is not messing up my work, I have configured it topermissive
mode in/etc/selinux/config
and confirming the effect after reboot usingsestatus
:SELinux status: enabled SELinuxfs mount: /selinux Current mode: permissive Mode from config file: permissive Policy version: 26 Policy from config file: targeted
This may sound like a duplicate of the following questions, but the answers in these questions suggest to set up a
Host-only
adapter for the guest and configure/etc/hosts
in the host, which I have already tested and didn't work for me:Any help?!
-
ignis almost 11 yearsIf you run
wget 10.10.10.15
in the host, what error does it display?
-
-
Seyed Mohammad almost 11 yearsActually I didn't do anything special after installing Apache with YUM, other than starting the
httpd
service. What should I do ? -
Terry Wang almost 11 years
yum
... that is CentOS/RHEL, this is for Ubuntu/Debian, wrong place... -
Seyed Mohammad almost 11 yearsI did mention in the question that the VM is Oracle Linux which is based on RHEL ... Can you please explain your note on binding Apache to all interfaces ... What exactly should I do to fix my problem?
-
Terry Wang almost 11 yearsIn your site's configuration file, what did you bind to? e.g.
<VirtualHost *:80>
-
Seyed Mohammad almost 11 yearsI haven't done any binding. Actually I don't need the server to be accessed by a name. The VM's IP address (i.e.
10.10.10.15
) is fine if it works ... -
Terry Wang almost 11 yearsDo a
netstat -nap | grep :80
see if it's binding to 10.10.10.15, also ping the IP and make sure you can reach it (there is route). -
rfay over 10 yearsTo manually turn off iptables in the guest: sudo service iptables stop
-
Christopher Markieta over 8 yearsTurning off iptables should not be the solution!
-
Seyed Mohammad over 8 years@ChristopherMarkieta Yes, turning off
iptables
can have security consequences and it is only recommended for controlled test environments. For a production system the correct way is to configureiptables
to allow the desired traffic to pass in and out. -
Alexander about 7 yearsThanks its always
iptables
and yes, selinux is a "problem, too". If you want to connect to the host using mod_proxy, make sure to call/usr/sbin/setsebool -P httpd_can_network_connect 1
, too. See for example viewsby.wordpress.com/2012/07/03/…