4

Is it possible to access my Apache server from outside the VirtualBox on Google Chrome browser on my host computer? Its running on CentOS 7 on VirtualBox. I have tried connecting to the ip address of the CentOS virtual machine but it didn't work. Its using 'Bridged Adapter' networking in the VM settings and i checked the ip address using the 'ip addr' command. Thanks.

3 Answers 3

8

I met the same issue. I fixed it as the following:

  1. In the VM network settings, using 'Bridged Adapter'.
  2. Turn on the port of CenOS7: using the following command in terminal(for example port 8080): $ firewall-cmd --permanent --add-port=8080/tcp $ firewall-cmd --reload

My environment:
Host : Win7 64bit
Guest:CenOS 7

1
  • Works great, thanks. Interestingly this step doesn't seem to be necessary on Debian-based systems. Mar 18, 2019 at 16:00
3

You can use a single NAT (without a second adapter):

Set adapter No1 to NAT, then click "Port forwarding", type (for example) 8080 in Host port, and 80 in Guest port (no ip addresses needed). You may also (optionally) wish to map SSH here to a different port.

Then in the CentOS 7 VM, once your Apache or NGINX server is installed and running (eg: yum install nginx, systemctl start nginx, systemctl enable nginx), configure the firewall as niaomingjian suggested, but perhaps more properly:

sudo firewall-cmd --zone=public --add-service=http --permanent
sudo firewall-cmd --reload

Then navigate on your host machine to http://127.0.0.1:8080 and check you get the welcome page. If this doesn't work straight away, try stopping and starting the firewalld service, or rebooting the VM.

1
  • It worked for me! Thanks a lot!
    – E. AMARAL
    Oct 23, 2020 at 19:10
0

You can divide the problem into smaller parts that will help troubleshooting:

  • Use 'ping ' from the host to the guest to determine if you can reach it.
  • Check if there are firewalls running on the guest that blocks ping and/or www ports (e.g. 'iptables -L'.
  • Open the web page with a browser within the guest to check that it's actually running and accessible.
1
  • Sounds like a reasonable strategy, though rather short on details. For example, in step 1, what ip/name do I ping?
    – JohnK
    Apr 15, 2020 at 11:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .