The host machine cannot access the Web service in the virtual machine

CentOS6.5 operating system is installed in VMware virtual machine in Windows7 host machine, and a Web server is built based on Nginx. When the Web page is just built, the Web page in the virtual machine can be accessed through the browser of the host machine. However, after a while, I could not access it. This problem bothered me for several days. Each time, I had to go back to the step where the Web service was just established through the virtual machine snapshot, so that I could access it.

Later, through searching information on the Internet, I finally understood that it was a firewall of CentOS6.5 that did not open port 80 of web service, shielding external access. Two methods can be used to enable the host to access the vm web page :(1) disable the firewall on the vm. (2) Open port 80 of the Web service.

1. Disable the firewall

use

service iptables stop

The firewall command is used to temporarily disable the firewall so that web pages in the VIRTUAL machine can be accessed from the host machine.

Generally, iptables firewalls are started upon startup. After you run the preceding command to temporarily disable the firewall, the firewall software will still be started upon startup next time. You can run the following command to disable the firewall startup upon startup:

chkconfig iptables off

However, the purpose of firewalls is to prevent malicious access from outside, so it is best to keep firewalls running.

2. Enable the corresponding port

2.1 Enabling Port 80 on the CLI

To temporarily enable port 80, run the following command:

/sbin/iptables -I INPUT -p tcp –dport 80 -j ACCEPT

Restarting the firewall takes effect:

service iptables restart

If you want to keep port 80 turned on the next time you start up, use the following command to save the current Settings:

service iptables save

2.2 Modifying the Iptables configuration file to enable the port

use

vim /etc/sysconfig/iptables

Run the following command to modify the iptables firewall configuration file: -a INPUT -p TCP -m state –state NEW -m TCP –dport 80 -j ACCEPT

As shown in the figure:

Then restart the firewall:

service iptables restart

This allows access to the virtual machine’s network services from the host machine.

From: www.cnblogs.com/blackhumour…