Linux firewall settings

Source: Internet
Author: User

Basic operational commands for firewalls:

Querying firewall Status:
[[Email protected] ~]# service iptables status< carriage return >

To stop the firewall:
[[Email protected] ~]# service iptables Stop < Enter >

To start the firewall:
[[Email protected] ~]# service iptables start < Enter >

To restart the firewall:
[[Email protected] ~]# service iptables Restart < Enter >

To permanently shut down the firewall:
[[email protected] ~]# chkconfig iptables off< Carriage return >

Enable after permanent shutdown:
[[email protected] ~]# chkconfig iptables on< Carriage return >

CentOS is one of the Linux distributions, and friends who are just starting out may not even know what the CentOS shutdown firewall method is? The next article will show you how to turn off the CentOS firewall using the command line.

We can use the following command:

#/sbin/iptables-i input-p TCP--dport 80-j ACCEPT

#/sbin/iptables-i input-p TCP--dport 22-j ACCEPT

#/etc/rc.d/init.d/iptables Save

After restarting the computer, the firewall has already opened 80 and 222 ports by default.

Temporary shutdown of the firewall completely, can not restart the machine:

#/etc/init.d/iptables Status # #查看防火墙状态

#/etc/init.d/iptable Stop # #本次关闭防火墙

#/etc/init.d/iptable Restart # #重启防火墙

To permanently shut down the firewall:

#chkconfig--level iptables Off (note that the middle is two English small short-term; restart)

Here's how to set up a firewall open port:

Vi/etc/sysconfig/iptables

When modifying a firewall, it is best to leave the management port of VNC and SSH.

The following is an example of a iptables:

# Firewall configuration written by System-config-securitylevel

# Manual Customization of this file are not Recommended.*filter

: INPUT ACCEPT [0:0]

: FORWARD ACCEPT [0:0]

: OUTPUT ACCEPT [0:0]

: Rh-firewall-1-input-[0:0]

-A input-j Rh-firewall-1-input

-A forward-j Rh-firewall-1-input

-A rh-firewall-1-input-i lo-j ACCEPT

-A rh-firewall-1-input-p icmp–icmp-type any-j ACCEPT

-A rh-firewall-1-input-p 50-j ACCEPT

-A rh-firewall-1-input-p 51-j ACCEPT

-A rh-firewall-1-input-m state–state established,related-j ACCEPT

-A rh-firewall-1-input-m state–state new-m tcp-p tcp–dport 53-j ACCEPT

-A rh-firewall-1-input-m state–state new-m udp-p udp–dport 53-j ACCEPT

-A rh-firewall-1-input-m state–state new-m tcp-p tcp–dport 22-j ACCEPT

-A rh-firewall-1-input-m state–state new-m tcp-p tcp–dport 25-j ACCEPT

-A rh-firewall-1-input-m state–state new-m tcp-p tcp–dport 80-j ACCEPT

-A rh-firewall-1-input-m state–state new-m tcp-p tcp–dport 443-j ACCEPT

-A rh-firewall-1-input-j Reject–reject-with icmp-host-prohibited

COMMIT

To modify this file according to your own needs, for example, if you do not want to open the 80 port to provide Web services, you should delete this line accordingly:

-A rh-firewall-1-input-m state–state new-m tcp-p tcp–dport 80-j ACCEPT

Restart iptables after all modifications are completed:

Service Iptables Restart

You can verify that the rules are in effect: iptables-l

In this way, we have completed the setup modification of the CentOS firewall.

Article content Source:
Http://jingyan.baidu.com/article/a948d65152b0bc0a2ccd2e6c.html

Linux firewall settings

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.