Accessing a CentOS 7 server running on VirtualBox from outside

4

5

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.

ctrlz

Posted 2014-11-19T12:39:43.420

Reputation: 41

Answers

6

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

niaomingjian

Posted 2014-11-19T12:39:43.420

Reputation: 171

thanks! only this worked for me! – Diogo Garcia – 2019-03-07T22:13:42.443

Works great, thanks. Interestingly this step doesn't seem to be necessary on Debian-based systems. – Radu Murzea – 2019-03-18T16:00:45.780

2

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.

Matt

Posted 2014-11-19T12:39:43.420

Reputation: 19

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.

Andreas F

Posted 2014-11-19T12:39:43.420

Reputation: 323