Linux下防火牆和selinux的啓動、關閉和查看

CentOS7.X下:

1.防火牆

防火牆狀態查看:

[root@localhost sunan]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)

其中Active爲inactive (dead)爲關閉狀態,active (running)爲開啓狀態linux

關閉防火牆命令:

[root@localhost sunan]# systemctl stop firewalld.service

開啓防火牆命令:

[root@localhost sunan]# systemctl start firewalld.service

永久禁用防火牆命令(開機不自啓動)

[root@localhost sunan]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

永久啓動防火牆命令(開機自啓動)

[root@localhost sunan]# systemctl enable firewalld.service   
Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service.

CentOS6.X下:

1.防火牆

防火牆狀態查看:

[root@localhost ~]# service iptables status

關閉防火牆命令:

[root@localhost ~]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]

開啓防火牆命令:

[root@localhost ~]# service iptables start
iptables: Applying firewall rules:                         [  OK  ]

永久禁用防火牆命令(開機不自啓動)

[root@localhost ~]# chkconfig iptables off

永久啓動防火牆命令(開機自啓動)

[root@localhost ~]# chkconfig iptables on

2.selinux(CentOS7.X同CentOS6.X)

查看selinux狀態:

[root@localhost sunan]# getenforce 
Enforcing

selinux狀態有三種模式:
enforcing:強制模式,表明selinux運行中,且已經正確的開始限制domain/type了。
permissive:寬容模式,表明selinux運做中,不過僅會有警告信息並不會實際限制domain/type的訪問。這種模式能夠用來做爲selinux的debug之用
disabled:關閉,selinux沒有實際運行。
命令設置SELinux,前提不能是disabled狀態:vim

[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce  
Permissive

其中setenforce 0|1
0:設置爲premissive狀態;
1:設置爲enforcing狀態;
此設置:重啓系統後無效。
修改配置文件,設置selinux爲disabled狀態:dom

[root@localhost ~]# vim /etc/selinux/config

SELINUX=disabled
SELINUXTYPE=targeted

保存,重啓系統生效。ide

相關文章
相關標籤/搜索