How to turn on and off the firewall in linux

青灯夜游
Release: 2023-01-07 11:45:44
Original
17162 people have browsed it

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
Copy after login

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
Copy after login

iptables: The firewall is not running.

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

[root@centos6 ~]# service iptables start
Copy after login

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

[root@centos6 ~]# service iptables stop
Copy after login

(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]#
Copy after login

Then

Check the firewall status:

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

Temporarily close the firewall:

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

Restart iptables:

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!