在生产环境中,有可能会出现被其他管理员或使用者修改hosts.allow允许更多的ip登陆机器;为了方便统一管理,我们可以在用户退出的时候统一修改allow和deny文件成默认设置。同时也能自动获取机器所配ip的整个ip段为允许登陆
test -f /root/.bash_logout && chattr -i /root/.bash_logout
cat >/root/.bash_logout <
/usr/bin/chattr -i /etc/hosts.allow /etc/hosts.deny
#for hosts.deny
/bin/awk 'BEGIN{FS="[=.]";RS="n"};/^IPADDR/{print "sshd:all EXCEPT "$2"."$3"."$4".0/255.255.255.0"}' /etc/sysconfig/network-scripts/ifcfg-* | grep -v 127.0.0 | uniq 1>/etc/hosts.deny
/bin/cat >>/etc/hosts.deny << iEOF
sshd:all EXCEPT ip
iEOF
#for hosts.allow
/bin/awk 'BEGIN{FS="[=.]";RS="n"};/^IPADDR/{print "sshd:"$2"."$3"."$4".0/255.255.255.0"}' /etc/sysconfig/network-scripts/ifcfg-* | grep -v 127.0.0 | uniq 1>/etc/hosts.allow
/bin/cat >>/etc/hosts.allow << iEOF
sshd:ip
iEOF
/usr/bin/chattr +i /etc/hosts.allow /etc/hosts.deny
clear
EOF
sh /root/.bash_logout 2>&1 >/dev/null
ssh登录限制ip的方法
vi /etc/hosts.allow
sshd:192.168.0.100:allow //允许IP 192.168.0.100 登录
sshd:192.168.0.:allow //允许IP 192.168.0. 网段登录
sshd:all:deny //禁止其他的所有IP登录
或者
sshd:223.227.223.*:allow //允许IP 223.227.223.* 网段登录
sshd:192.168.0.*:allow //允许IP 192.168.0.* 网段登录
sshd:all:deny //禁止其他的所有IP登录
fedora下 修改后保存后生效
freeBSD限制特定ip的ssh登陆:
1.
#ee /etc/hosts.allow
在ALL : ALL : allow的前面加上
sshd : 192.168.0.100 : allow
sshd : 223.227.223.* : allow
sshd : ALL : deny
2.
修改/etc/ssh/sshd_config
加入
Allowusers [email protected]
意思为
只允许admin从172.16.2.188登陆
FreeBSD 改IP ,不用重启电脑:
在rc.conf里改完后/etc/netstart
iptables自动封IP脚本
#!/bin/bash
#Created by haiyun
num=10 #上限
for i in `awk '/Failed/{print $(NF-3)}' /var/log/secure|sort|uniq -c|sort -rn|awk '{if ($1>$num){print $2}}'`
do
iptables -I INPUT -p tcp -s $i --dport 22 -j DROP
done
加入crontab计划任务
crontab -e
* */5 * * * sh /path/file.sh #5小时执行一次
原神祈愿模拟器最新版
原神祈愿模拟器手机版是一款完整汉化的趣味原神抽卡模拟小游戏,
宝宝森林美食完整版
宝宝森林美食游戏最新版是一款十分有趣的休闲益智游戏,帮助宝宝
g沙盒仇恨官方英文版(gorebox)
G沙盒仇恨英文原版是一款最近非常火热的沙盒模拟类游戏,在这里
迷你世界测试服最新版2024
迷你世界测试服2021最新版,即迷你世界的先遣服版本,用户能
闪耀暖暖最新版2024
闪耀暖暖手游这是非常好玩的换装手游,游戏内容丰富有趣,游戏环