[Linux 安全] tcp_wrappers 和 iptables 的配置和使用
转载本站文章请注明,转载自:扶凯[http://www.php-oa.com]
本文链接: http://www.php-oa.com/2007/10/17/tcp_wrappers-ciptables.html
tcp_wrappers
.使用libwrap.so保护某种tcp协定的服务器
.配置文件/etc/hosts.deny和/etc/hosts.allow
.支持tcp_wrappers的服务器
sshd,mysald,vsftpd,tcpd,xinetd(所有用sinetd启动的服务器)
.配置文件语法
daemon: client list
e.g
vsftpd: 192.168.0.2 10.0.0.0.0/255.255.255.0
sshd: .example.com
例子:
保护sshd服务器
.要求: 192.168.0.0/255.255.255.0中除了192.168.0.254之外都能够访问本地的ssh服务器
.配置文件
/etc/hosts.allow
sshd:192.168.0 EXCEPT 192.168.0.254
/etc/hosts.deny
sshd:ALL
iptables
基本使用
iptabls 只是一个 Netfilter 的管理工具,它包括4张表raw, mangle, nat, filter.
iptables 的架构表由链组成,链由规则组成.
表间的优先级
raw > mangle > net > filter
链间的匹配顺序
入站数据: PREROUTING, INPUT
出站数据: OUTPUT, POSTROUTING
转发数据: PREROUTING, FORWARD, POSTROUTING
iptables [-t table] 命令 链 [条件] [-j 处理]
常用命令: -A ,-D ,-F ,-I ,-R , -L
条件: -i, -o, -s, -d, -p, –dport, –sport, -m
处理方式: ACCEPT,DROP,REJECT,LOG
例:
iptables -A INPUT -p icmp -j DROP
iptables -A OUTPUT -D 192.168.0.254 -j ACCEPT
iptables -D INPUT 1
iptables -A INPUT -S 192.168.0.0/24 -p tcp –dprot 80 -j ACCEPT
默认策略
#iptables -nL
#iptables -P INPUT DROP
#iptables -P OUTPUT DROP
#iptables -P FORWARD DROP
包的状态检查
状态: NEW,ESTABLISHED,RELATED
#iptables -A INPUT -s 192.168.0.0/24 -P tcp -dport 22 -m state –state ESTABLISHED -j ACCEPT
配置实例
.要求: 192.168.0.0/255.255.255.0中除了
192.168.0.254之外都能访问本地的 ssh服务器
.命令:
#iptables -P INPUT DROP
#iptables -P OUTPUT DROP
#iptables -A INPUT -s 192.168.0.254 -j DROP
#iptables -A INPUT -s 192.168.0.0/24 -p tcp –dport 22 -j ACCEPT
#iptables -A OUTPUT -D 192.168.0.0/24 -p tcp –sport 22 -m state –stat ESTABLISHED -j ACCEPT


















