5.CentOS7的防火墙配置

大多数ssh连接不上虚拟机,数据库软件连接不上linux中的数据库,都是因为防火墙阻挡了

1.SELinux

SELinux(Security-Enhanced Linux) 是美国国家安全局(NSA)对于强制访问控制的实现,这个功能管理员又爱又恨,大多数生产环境也是关闭的做法,安全手段使用其他方法。

永久关闭:

#1.修改配置文件,永久生效关闭selinuxcp 
/etc/selinux/config /etc/selinux/config.bak #修改前备份
#2.修改方式可以vim编辑,找到
# 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=disabled
#3.用sed替换
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
#4.检查状态
grep "SELINUX=disabled" /etc/selinux/config#出现结果即表示修改成功

临时关闭(命令行修改,重启失效):

生产环境的服务器是禁止随意重启的!!!!

getenforce #获取selinux状态
#修改selinux状态
setenforce usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]
数字0 表示permissive,给出警告,不会阻止,等同disabled
数字1表示enforcing,表示开启

2.iptables防火墙

systemctl status firewalld #查看防火墙状态
systemctl stop firewalld    #关闭防火墙
systemctl disable firewalld#关闭防火墙开机启动
systemctl is-enabled firewalld.service#检查防火墙是否启动

3.更改防火墙规则

#启动防火墙服务
systemctl start firewalld
#停止防火墙开机启动
systemctl disable firewalld
#开机时启动防火墙服务
systemctl enable firewalld.service
#查看所有打开的端口
firewall-cmd --zone=public --list-ports
#打开MySQL服务的3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
#更改防火墙规则
firewall-cmd --reload
#查看所有打开的端口
firewall-cmd --zone=public --list-ports

针对诸如阿里云服务器,可以通过制器配置安全组规则实现,点击云服务器ESC->网络和安全->安全组;添加安全规则

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值