系统安全博客1-iptables防火墙与selinux安全机制配置

1.iptables防火墙配置

最小化防火墙规则:配置防火墙, 拒绝所有端口,只放行SSH, HTTP这两个必要的端口。

[root@localhost ~]# iptables -F
[root@localhost ~]# iptables -p INPUT DROP
[root@localhost ~]# iptables -p INPUT DROP
[root@localhost ~]# iptables -p INPUT DROP
[root@localhost ~]# iptables -p INPUT DROP
[root@localhost ~]# iptables -A INPUT -p tcp --dport 443 -j ACCEPT
[root@localhost ~]# iptables -A INPUT -p tcp --dport 443 -j ACCEPT

2.开启SELinux(永久开启,需要设置 /etc/sel inux/config配置文件)

[root@localhost ~]# vim /etc/sel inux/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.
#enforcing一SELinux security policy is enforced.
#permissive一SELinux prints warnings instead of enforcing.
#disabled一No SELinux policy is Loaded.
SELINUX=enforcing(SELinux有三种模式:Enforcing, Permissive 和 Disable,Enforcing模式就是应用SELinux所设定的Policy,所有违反Policy的规则(Rules)都会被SELinux拒绝,Permissive和Enforcing的区别就在于,前者还是会遵循SELinux的Policy,但是对于违反规则的操作只会予以记录而并不会拒绝操作,Disable 顾名思义就是完全禁用SELinux)
[root@localhost ~]# setenforce 1
开启SeLinux后,会发现sshd服务无法正常启动了,这是因为SELinux策略生效了,下面我们需要修改配置。

4.SELinux放行SSH端口

通过Semanage管理I具放行6553这个端口

[ root@localhost ~]# yum install -y policycoreutils -python-2.5-29.el7.x86_ 64
[root@localhost ~]# semanage port -L | grep ssh
ssh_ port_ t tcp 22
[root@localhost ~]# semanage port -a -t ssh_ port t -P tcp 6553
[root@localhost ~]# semanage port -L | grep ssh
ssh_ port_ t tcp 6553,22

5.设置Web目录权限

通过semanage命令设置,web目录权限

[root@localhost html]# semanage fcontext -a -t httpd sys_ content_t/var/www/html/index. htmL
[root@localhost html]# ls -z
-rW-r–r--. root root unconfined_ u:object_ r:httpd_ sys_ content_ t:s0 index. html

发布了11 篇原创文章 · 获赞 9 · 访问量 1008

猜你喜欢

转载自blog.csdn.net/weixin_42566183/article/details/104160260
今日推荐