CentOS6/7关闭防火墙和SELinux[TOC]CentOS7之后默认使用防火墙作为防火墙。如果改用iptables,应该先关闭默认的firewalld,再安装iptables服务。1.关闭CentOS7中的防火墙firewalld1,暂时关闭(下次启动会自动启动防火墙)[root@localhost~]#systemctlstopfirewalld2,查看防火墙状态#查看默认防火墙状态(关闭后不运行,打开后运行)[root@localhost~]#firewall-cmd--staterunning绿色Active:active(运行)表示防火墙已启用[root@localhosttest]#systemctlstatusfirewalldFirewalld.service-firewalld-动态防火墙守护进程已加载:已加载(/usr/lib/systemd/system/firewalld.service;已启用;供应商预设:已启用)活动:自周三2020-09-2317:36:45CST起活动(运行);5小时36分钟前Docs:man:firewalld(1)MainPID:875(firewalld)Tasks:2CGroup:/system.slice/firewalld.service└─875/usr/bin/python2-Es/usr/sbin/firewalld--nofork--nopidSeptember2317:36:43localhost.localdomainsystemd[1]:启动firewalld-动态...9月23日17:36:45localhost.localdomainsystemd[1]:启动firewalld-动态...提示:一些线条是椭圆形的,使用-l显示完整。3.永久关闭防火墙(开机时不会启动)[root@localhost~]#systemctldisablefirewalld4、永久开启防火墙[root@localhost~]#systemctlenablefirewalld.service2、关闭CentOS6中的防火墙Iptables1,永久生效,重启后不会恢复。开启:chkconfigiptableson关闭:chkconfigiptablesoff2.暂时关闭serviceiptablesstop#停止iptables3.暂时开启serviceiptablesstart3.关闭SElinux1,查看selinux状态#permissive模式暂时关闭,enforcing模式暂时开启,disabled模式永久关闭[root@localhost~]#getenforce强制启动的意思#IfSELinuxstatus如果参数为enabled,则表示启用状态[root@localhosttest]#/usr/sbin/sestatus-vSELinuxstatus:enabled 2.暂时禁用和暂时启用SELinuxsetenforce1[root@localhost~]#setenforceusage:setenforce[Enforcing|宽容|1|0]1表示启动,0表示关闭[root@localhost~]#setenforce0临时关闭[root@localhost~]#getenForce查看状态允许关闭状态3.永久修改(修改配置文件,可以永久永久关闭)PermanentlycloseSELinux:settodisabled永久开启SELinux:settoenabled[root@localhost~]#vi/etc/selinux/config#这个文件控制着系统上SELinux的状态。#SEINux=可以采用这三个值之一:#执行-Selinux安全策略将执行。#允许-selinux打印警告而不是执行。=可以采用以下三个值之一:#targeted-目标进程受到保护,#minimum-目标策略的修改。只有选定的进程受到保护。#getmls-四个命令多级安全TX保护受到保护。有以下两种方式1.服务方式查看防火墙状态:serviceiptablesstatusiptables:防火墙未运行开启防火墙:serviceiptablesstart关闭防火墙:serviceiptablesstop2.iptables方式首先进入init.d目录,命令如下:[root@centos6~]#cd/etc/init.d/[root@centos6init.d]#然后查看防火墙状态:[root@centos6init.d]#/etc/init.d/iptablesstatus暂时关闭防火墙:[root@centos6init.d]#/etc/init.d/iptablesstop重启iptables:[root@centos6init.d]#/etc/init.d/iptables重启
