[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