【iptables】服务器密码策略,用户权限控制,外网控制等配置

密码策略配置

1、设置密码的有效期和最小长度

vim /etc/login.defs
PASS_MAX_DAYS   90    #密码过期时间,设置90表示90天后过期,默认为99999,表示永不过期(Maximum number of days a password may be used)
PASS_MIN_DAYS   2     #两次修改密码的最小间隔时间(Minimum number of days allowed between password changes.)
PASS_MIN_LEN    8     #密码最小长度,对于root无效(Minimum acceptable password length.)
PASS_WARN_AGE   7     #Number of days warning given before a password expires.

2、设置最短密码长度

vim /etc/pam.d/common-password
password        requisite                       pam_cracklib.so  retry=3 minlen=8 difok=3 ucredit=-1 lcredit=-1 dcredit=-1 ocredit=-1

说明:字段并且附加有 “ucredit=-1 lcredit=-2 dcredit=-1 ocredit=-1” 的那行,它表示密码必须至少包含一个大写字母(ucredit),两个小写字母(lcredit),一个数字(dcredit)和一个标点符号(ocredit)。

设置用户家目录的权限

要求是其他用户不能操作其他用户的文件,也不能看到其他用户的家目录及文件
chown -R username.username 用户家目录
chmod 700 用户家目录

限制出口外网访问

开放22端口

iptables -A INPUT -s 192.168.44.0/23 -p tcp —dport 22 -j ACCEPT
iptables -A OUTPUT -d 192.168.44.0/23 -p tcp —sport 22 -j ACCEPT

开放44.0网段的流量

iptables -A INPUT -s 192.168.44.0/23 -j ACCEPT
iptables -A OUTPUT -d 192.168.44.0/23 -j ACCEPT

开放”回环”地址(127.0.0.1)的流量

iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

设置INPUT,FORWARD,OUTPUT默认策略是DROP (这个看情况设置,本内网的iptables是最后一条配置DROP所有流量)

iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP

因为-P设置的是默认策略为DROP,清空规则前,需要先放开,不然就连接不上了

iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

iptables -F

## 设置完成后192.168.24.28的效果是这样的:
iptables -F      #清空所有的防火墙规则
iptables -X      #删除用户自定义的空链
iptables -Z      #清空计数
iptables -A INPUT -s 192.168.44.0/23 -p tcp --dport 22 -j ACCEPT
iptables -A OUTPUT -d 192.168.44.0/23 -p tcp --sport 22 -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A INPUT -s 192.168.44.0/23 -j ACCEPT
iptables -A OUTPUT -d 192.168.44.0/23 -j ACCEPT
iptables -A INPUT -s 172.16.16.103 -j ACCEPT
iptables -A OUTPUT -d 172.16.16.103 -j ACCEPT
iptables -A INPUT -s 172.16.16.101 -j ACCEPT
iptables -A OUTPUT -d 172.16.16.101 -j ACCEPT
iptables -A INPUT -s 172.16.16.100 -j ACCEPT
iptables -A OUTPUT -d 172.16.16.100 -j ACCEPT
iptables -A INPUT -j DROP
iptables -A OUTPUT -j DROP

 

 
posted @   陈晓猛  阅读(62)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2019-05-15 【Linux常用命令】Linux kill, killall, kill -9,
点击右上角即可分享
微信分享提示