centos7最小安装怎么安装防火墙

centos7最小安装怎么安装防火墙,第1张

CentOS 7.0默认使用的是firewall作为防火墙,需要事先关闭

关闭firewall:

systemctl stop firewalld.service

systemctl disable firewalld.service

systemctl mask firewalld.service

安装iptables防火墙

yum install iptables-services -y

启动设置防火墙

systemctl enable iptables

systemctl start iptables

查看防火墙状态

systemctl status iptables

启动设置防火墙

vi /etc/sysconfig/iptables #编辑防火墙配置文件

-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

:wq! #保存退出

1、关闭 firewalld

由于 firewalld 是 CentOS-7系列的默认防火墙,因此如果想使用iptables的话,需要将CentOS-7系列的默认防火墙 firewalld 关闭,并安装 iptables-services 

[root@shell ~]#

[root@shell ~]# systemctl  stop  firewalld.service            #关闭

[root@shell ~]# systemctl  disable  firewalld.service        #禁止开机自启动

[root@shell ~]# firewall-cmd  --state          #查看firewalld是否在运行

not  running

[root@shell ~]#

2、安装iptables防火墙

[root@shell ~]#

[root@shell ~]# yum install iptables-services                  #安装iptables服务

[root@shell ~]# systemctl  start  iptables

[root@shell ~]# systemctl  enable  iptables                      #设置iptables为开机自启动

[root@shell ~]#

[root@shell ~]# cat  /etc/sysconfig/iptables            #查看iptables默认配置

[root@shell ~]# 

[root@shell ~]#

[root@shell ~]# systemctl  start  iptables             #启动 iptables

[root@shell ~]# systemctl  status  iptables            #查看状态

[root@shell ~]#

[root@shell ~]# iptables  -L                  #查看当前防火墙规则

3、配置防火墙规则

关闭ping扫描,虽然没什么卵用

先切换到root

echo 1 >/proc/sys/net/ipv4/icmp_echo_ignore_all

1代表关闭

0代表开启

用iptables

iptables -I INPUT -p icmp -j DROP

简单介绍下基本的 dedecms _aq/' target='_blank'>安全设置

一、创建普通用户,禁止root登录,只允许普通用户使用su命令切换到root

这样做的好处是双重密码保护,黑客就算知道了普通用户的密码,如果没有root密码,对服务器上攻击也比较有限

以下是具体做法(需要在root下)

添加普通用户

useradd xxx

设置密码

passwd xxx

这样就创建好了一个普通用户

禁止root登录

vi /etc/ssh/sshd_config

PermitRootLogin no

Systemctl restart sshd

这样就完成了第一步,之后root就无法登录服务器只能通过普通用户su切换

二、修改ssh的默认端口22,因为ssh的端口是22,我们如果修改了该端口,他们就需要花费一点时间来扫描,稍微增加了点难度

以下将端口改为51866可以根据需要自己更改,最好选择10000-65535内的端口

step1 修改/etc/ssh/sshd_config

vi /etc/ssh/sshd_config

#Port 22 //这行去掉#号

Port 51866 //下面添加这一行

为什么不先删除22,以防其他端口没配置成功,而又把22的删除了,无法再次进入服务器

step2 修改SELinux

安装semanage

$ yum provides semanage

$ yum -y install policycoreutils-python

使用以下命令查看当前SElinux 允许的ssh端口:

semanage port -l | grep ssh

添加51866端口到 SELinux

semanage port -a -t ssh_port_t -p tcp 51866

注: *** 作不成功,可以参考:https://sebastianblade.com/how-to-modify-ssh-port-in-centos7/

失败了话应该是selinux没有打开

然后确认一下是否添加进去

semanage port -l | grep ssh

如果成功会输出

ssh_port_t tcp 51866, 22

step3 重启ssh

systemctl restart sshd.service

查看下ssh是否监听51866端口

netstat -tuln

Step4 防火墙开放51866端口

firewall-cmd --permanent --zone=public --add-port=51866/tcp

firewall-cmd --reload

然后测试试试,能不能通过51866登录,若能登录进来,说明成功,接着删除22端口

vi /etc/ssh/sshd_config

删除22端口 wq

systemctl restart sshd.service

同时防火墙也关闭22端口

firewall-cmd --permanent --zone=public --remove-port=22/tcp

注意如果是使用阿里的服务器需要到阿里里面的安全组添加新的入站规则(应该是因为阿里的服务器是用的内网,需要做端口映射)

三、使用一些类似DenyHosts预防SSH暴力破解的软件(不详细介绍)

其实就是一个python脚本,查看非法的登录,次数超过设置的次数自动将ip加入黑名单。

四、使用云锁(不详细介绍)

参考自http://tim-fly.iteye.com/blog/2308234

总的来说做好了前两步能够减少至少百分之五十的入侵,在做好第三步之后,基本可以杜绝百分之八十以上的入侵。当然最重要的还是自己要有安全意识,要多学习一些安全知识和linux的知识。

第三第四其中都有稍微提到一点,感兴趣可以看看


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11852995.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-19
下一篇2023-05-19

发表评论

登录后才能评论

评论列表(0条)

    保存