Iptables firewall configuration in CentOS

Source: Internet
Author: User
Tags ssh port
After a web server is built on a virtual machine, the host cannot be accessed, as shown in the following figure: 1. The local machine can ping Virtual Machine 2. The VM can also ping the host 3. Virtual machines can access their own web4. The reason why the local machine cannot access the web of the virtual machine is the firewall. Many examples of firewall settings on the Internet are also a bit complicated. I will not introduce them here. After a web server is built on a virtual machine, the host cannot be accessed. The details are as follows:
1. The local machine can ping the virtual machine
2. The VM can also ping the host.
3. Virtual machines can access their own web
4. The local machine cannot access its web
The reason should be the firewall. Many examples of firewall settings on the Internet are also a bit complicated. I will not introduce them here. This article only addresses how to allow hosts to access the web of virtual machines through ip addresses.
[Root @ CentOS ~] # Vi/etc/sysconfig/ Iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
* Filter
: Input accept [:]
: Forward accept [:]
: Output accept [:]
-A input-m state -- state ESTABLISHED, RELATED-j ACCEPT
-A input-p icmp-j ACCEPT
-A input-I lo-j ACCEPT
-A input-m state -- state NEW-m tcp-p tcp -- dport-j ACCEPT
-A input-m state -- state NEW-m tcp-p tcp -- dport 80-j ACCEPT
-A input-j REJECT -- reject-with icmp-host-prohibited
-A forward-j REJECT -- reject-with icmp-host-prohibited
COMMIT
Pay attention to the red line above. Port 80 is the default web port. 22 is the ssh port (you can connect to the virtual machine through ssh ).
Restart the firewall to make the modification take effect.
[Root @ CentOS ~] #/Etc/init. d/iptables restart
In this case, you can access the web of a virtual machine through an ip address on the host.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.