Home >Operation and Maintenance >Linux Operation and Maintenance >How to turn on and off the firewall in linux

How to turn on and off the firewall in linux

青灯夜游
青灯夜游Original
2021-07-26 16:38:3617275browse

In Linux, you can use the "chkconfig iptables on;" command to permanently turn on the firewall, and use the "chkconfig iptables off;" command to permanently turn off the firewall; both commands take effect after restarting.

How to turn on and off the firewall in linux

The operating environment of this tutorial: CentOS 6 system, Dell G3 computer.

Permanently turn on and off the firewall

Turn on: chkconfig iptables on;(Take effect after restart)

Turn off:chkconfig iptables off;(effective after restart)

Detailed usage explanation

Command:

chkconfig --level 2345 iptables off
或者 
chkconfig iptables off

where 2345 represents "execute" Level”

  • Level 0 means: shutdown

  • Level 1 means: single-user mode

  • Level 2 means: multi-user command line mode without network connection

  • Level 3 means: multi-user command line mode with network connection

  • Level 4 means: Unavailable

  • Level 5 means: Multi-user mode with graphical interface

  • Level 6 means: Restart

Temporarily turning on and off the firewall

1 service method

View firewall status:

[root@centos6 ~]# service iptables status

iptables: The firewall is not running.

Turn on the firewall (effective immediately, invalid after restart):

[root@centos6 ~]# service iptables start

Turn off the firewall (effective immediately, invalid after restart):

[root@centos6 ~]# service iptables stop

(Note): Allow a certain port Through firewall configuration

When the firewall is turned on, make the following settings, open the relevant ports, modify the /etc/sysconfig/iptables file, and add the following content:

-A INPUT -m state -- state NEW -m tcp -p tcp --dport 80 -j ACCEPT #Allow port 80 through the firewall

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT #Allow port 3306 to pass through the firewall

Note: Many netizens add these two rules to the last line of the firewall configuration, causing the firewall to fail to start.

The correct one should be to add it to the default port 22 Below this rule

2 iptables methods

First enter the init.d directory, the command is as follows:

[root@centos6 ~]# cd /etc/init.d/
[root@centos6 init.d]#

Then

Check the firewall status:

[root@centos6 init.d]# /etc/init.d/iptables status

Temporarily close the firewall:

[root@centos6 init.d]# /etc/init.d/iptables stop

Restart iptables:

[root@centos6 init.d]# /etc/init.d/iptables restart

Related recommendations: "Linux Video Tutorial

The above is the detailed content of How to turn on and off the firewall in linux. 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