Linux防火墙学习笔记8

iptables的白名单和黑名单:

iptables -t filter -I INPUT -s 192.168.2.20 -p tcp --dport 80 -j DROP

之前内网的机器可以访问到80端口,现在添加了这条规则,那么就192.168.2.10这个用户就不能访问了。

案例:白名单:

iptables -F
iptables -P INPUT DROP


# 然后直接再开通22端口
iptables -t filter -A INPUT -p tcp --dport 22 -j ACCEPT

# 然后再在物理机上开通80端口
iptables -t filter -A INPUT -p tcp --dport 80 -j ACCEPT

案例:黑名单:

ipables -P INPUT ACCEPT
iptables -F

注意两者的顺序。

这就相当于没有限制了。

iptables -t filter -A INPUT -p tcp --dport 80 -j DROP
# 这个规则是所有人都访问不了

iptables -t filter -A INPUT -s 192.168.2.20/24 -p tcp --dport 80 -j DROP
# 限制某个网段的人不能访问

黑名单在生产环境中,是不建议这么做的。

iptables的表和链的查看:

iptables -t filter -nL

iptables -t nat -nL

iptables -t mangle -nL

iptables -t raw -nL

iptables -t security -nL

再复习下各个表的作用:

filter: 过滤

nat:网络地址转换

mangle:封装标记

raw:数据跟踪

security:强制访问控制规则

常见操作命令:

你可能感兴趣的:(iptables,linux)