Linux firewall set Port method detailed

Source: Internet
Author: User

Linux itself has a firewall named "Iptables". The Dark One you said is the terminal. Enter the following command in the terminal to open the firewall:

The code is as follows Copy Code

Chkconfig iptables on

If the firewall is closed, enter:

The code is as follows Copy Code

Chkconfig iptables off

All two of these commands have to be restarted for the system to take effect.
You can use the service command if you do not want to take effect immediately by restarting the system. The disadvantage is that the settings will be lost when you reboot the system.

Firewall turned on:

The code is as follows Copy Code
Service Iptables Start

To turn off the firewall:

The code is as follows Copy Code

Service Iptables Stop

To set a switch on some ports in the firewall, modify the edit/etc/sysconfig/iptables file, such as SSH Port 22, which can be added as follows:

When the firewall is turned on, make the following settings, open the relevant port,

Modify the/etc/sysconfig/iptables file and add the following:

The code is as follows Copy Code

-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 22-j ACCEPT


CentOS Linux firewall configuration and shutdown

Perform the "Setup" command to start the text mode configuration Utility, select "Firewall Configuration" in "Select a tool", then select the "Run Tool" button, the firewall configuration interface appears, set the security level to Disabled, and select OK.

or by command:

The code is as follows Copy Code

#/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 this reboot the computer, the firewall has opened 80 and 22 ports by default
You should also not reboot the computer here:

The code is as follows Copy Code
#/etc/init.d/iptables restart

To turn off the Firewall service:

To view firewall information:

The code is as follows Copy Code

#/etc/init.d/iptables status

To turn off the Firewall service:

  code is as follows copy code

#/etc/ Init.d/iptables stop

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.