工作中发现欧拉系统不支持hosts.allow/deny来控制SSH登录源IP,研究了一下使用iptables限制。
步骤如下:
1、新建一个脚本文件 iptables.sh;
touch iptables.sh
2、编辑脚本文件iptables.sh, 地址按实际需求来;
vi iptables.sh
3、加入以下内容:
#默认deny所有SSH请求
iptables -I INPUT -p tcp --dport 22 -j DROP -m comment --comment "ssh"
#按照IP范围开放SSH请求
iptables -I INPUT -p tcp -m iprange --src-range 172.28.9.1-172.28.9.10 --dport 22 -j ACCEPT -m comment --comment "ssh"
#按照IP网段开放SSH请求
iptables -I INPUT -p tcp -s 172.22.24.0/24 --dport 22 -j ACCEPT -m comment --comment "ssh"
iptables -I INPUT -p tcp -s 172.22.8.0/24 --dport 22 -j ACCEPT -m comment --comment "ssh"
4.ESC+Shift :后输入wq保存退出;
5.运行脚本后完成。
sh iptables.sh
iptables --list 查看已有的ACl