Home  >  Article  >  Operation and Maintenance  >  How to solve the problem of being unable to access the web service in the virtual machine under centos

How to solve the problem of being unable to access the web service in the virtual machine under centos

王林
王林Original
2020-03-31 09:34:123178browse

How to solve the problem of being unable to access the web service in the virtual machine under centos

Problem:

The CentOS host cannot access the web service in the virtual machine.

Reason:

is that a CentOS6.5 firewall did not open port 80 of the web service, blocking external access.

Solution:

There are two methods to enable the host to access the virtual machine's web page: (1) Turn off the firewall in the virtual machine; (2) Open port 80 of the web service.

(Recommended tutorial: centos tutorial)

The specific method is as follows:

1. Turn off the firewall

Use

service iptables stop
The

command can temporarily turn off the firewall, so that the web page in the virtual machine can be accessed through the host machine.

iptables The firewall is usually started at boot. After using the above command to temporarily close the firewall, the firewall software will still be started the next time you boot. You can use the following command to disable starting the firewall at boot:

chkconfig iptables off

But The purpose of the firewall is to prevent malicious external access, so it is best to keep the firewall running.

2. Open the corresponding port

2.1. Open port 80 through the command line

Use the following command to temporarily open port 80:

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

Restart the firewall It will take effect:

service iptables restart

If you want to keep port 80 open the next time you boot, use the following command to save the current settings:

service iptables save

2.2. Modify the configuration file of iptables to open it. Port

Use the

vim /etc/sysconfig/iptables

command to modify the iptables firewall configuration file and add a line as follows:

-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

As shown in the figure:

How to solve the problem of being unable to access the web service in the virtual machine under centos

Then restart the firewall:

service iptables restart

In this way, you can access the network service of the virtual machine through the host machine.

Recommended related video tutorials: linux video tutorial

The above is the detailed content of How to solve the problem of being unable to access the web service in the virtual machine under centos. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn