[TOC]python
CentOS 7以後默認使用的是firewall做爲防火牆,若是切換到iptables首先應該關掉默認的firewalld,而後安裝iptables服務。linux
[root@localhost ~]# systemctl stop firewalld
#查看默認防火牆狀態(關閉後顯示notrunning,開啓後顯示running) [root@localhost ~ ]# firewall-cmd --state running 綠的Active: active (running) 表示防火牆開啓 [root@localhost test]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: active (running) since 三 2020-09-23 17:36:45 CST; 5h 36min ago Docs: man:firewalld(1) Main PID: 875 (firewalld) Tasks: 2 CGroup: /system.slice/firewalld.service └─875 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid 9月 23 17:36:43 localhost.localdomain systemd[1]: Starting firewalld - dynami... 9月 23 17:36:45 localhost.localdomain systemd[1]: Started firewalld - dynamic... Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# systemctl enable firewalld.service
開啓:shell
chkconfig iptables on
關閉:centos
chkconfig iptables off
service iptables stop #中止iptables
service iptables start
一、查看selinux狀態dom
#permissive模式是臨時關閉,enforcing模式是臨時打開,disabled模式是永久關閉 [root@localhost ~]# getenforce Enforcing 表示啓動 #若是SELinux status參數爲enabled即爲開啓狀態 [root@localhost test]# /usr/sbin/sestatus -v SELinux status: enabled
二、臨時關閉
臨時打開SELinux setenforce 1
rest
[root@localhost ~]# setenforce usage: setenforce [ Enforcing | Permissive | 1 | 0 ] 1表示啓動,0表示關閉 [root@localhost ~]# setenforce 0 臨時關閉 [root@localhost ~]# getenforce 查看狀態 Permissive 關閉狀態
三、永久關閉(修改配置文件,便可永久關閉)code
永久關閉SELinux:設置爲disabled
永久打開SELinux:設置爲enabled
[root@localhost ~]# vi /etc/selinux/config # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=enforcing 修改成"SELINUX=disabled" # SELINUXTYPE= can take one of three values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted
1、service方式 查看防火牆狀態:service iptables status iptables:未運行防火牆。 開啓防火牆: service iptables start 關閉防火牆: service iptables stop 2、iptables方式 先進入init.d目錄,命令以下: [root@centos6 ~]# cd /etc/init.d/ [root@centos6 init.d]# 而後 查看防火牆狀態: [root@centos6 init.d]# /etc/init.d/iptables status 暫時關閉防火牆: [root@centos6 init.d]# /etc/init.d/iptables stop 重啓iptables: [root@centos6 init.d]# /etc/init.d/iptables restart