centos处理防火墙

1、firewalld

这个有时候明明百分百确定开放了防火墙端口,但是却无法访问,考虑处理下面的SELinux

# 查看防火墙状态
service iptables status  
systemctl status firewalld

systemctl stop firewalld   #临时关闭
systemctl disable firewalld   #永久关闭,enable开启

2、开放指定端口
firewall-cmd --zone=public --add-port=1935/tcp --permanent
 命令含义:
--zone #作用域
--add-port=1935/tcp  #添加端口,格式为:端口/通讯协议
--permanent  #永久生效,没有此参数重启后失效

移除 开放端口
firewall-cmd --permanent --remove-port=123/tcp

查看已经开放的端口
firewall-cmd --list-ports

ping端口
curl ip:port

3、重启防火墙																								
systemctl restart firewalld

2、SELinux

SELinux(Security-Enhanced Linux) 是美国国家安全局(NSA)对于强制访问控制的实现,是 Linux历史上最杰出的新安全子系统。但是我们一般都不用它,因为它管的东西太多了,想做安全可以用防火墙等其他措施。

我们可以通过查看配置文件的命令cat /etc/selinux/config来查看状态,

[root@lill ~]# cat /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
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted

发现SELinux共有3个状态enforcing (执行中)、permissive (不执行但产生警告)、disabled(关闭)。
我们可以通过修改配置文件来修改SELinux的状态

[root@lill ~]# sed -i s#SELINUX=enforcing#SELINUX=disabled# /etc/selinux/config
[root@lill ~]# cat /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=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted

最后我们重启服务器,SELinux状态由enforcing变为disabled 。
当然,一般我们的Linux都不能重启,我们可以使用这个命令setenforce 1临时(重启即失效)设置SELinux 成为enforcing模式(setenforce 0设置SELinux 成为permissive模式),用getenforce这个命令来检查。

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

我们还可以用/usr/sbin/sestatus命令来查看SELinux的状态。

[root@lill ~]# /usr/sbin/sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: disabled
Policy version: 24
Policy from config file: targeted
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值