十二 172009

有个软件监听的是80端口,但不提供Web服务
麻烦的是又可以通过ip:80访问到,还有输出
这样就不和谐了

80是不能封的,封了客户端就连接不了
想到用iptables禁止浏览器对80的访问
问了些QQ群的朋友,可以实现

先看下有没有string这个模块
iptables -m string --help
如果有,它会提示一堆帮助信息,没有则显示
iptables v1.2.11: Couldn't load match `string':/lib64/iptables/libipt_string.so: cannot open shared object file: No such file or directory

已知iptables v1.3.5是有的

规则,HTTP就是我们要过滤的关键字,--algo,指定使用的算法,有2中,分别是kmp,bm
/sbin/iptables -I INPUT -p tcp -m string --string HTTP --algo kmp --dport 80 -j DROP

保存规则
/sbin/iptables-save

Posted by admin Tagged with: ,
十一 062009

iptables -A RH-Firewall-1-INPUT -s 192.168.1.0/27 –dport 161 -j ACCEPT
iptables v1.2.11: Unknown arg `–dport’
Try `iptables -h’ or ‘iptables –help’ for more information.

改为这样就好了
iptables -A RH-Firewall-1-INPUT -p tcp -s 192.168.1.0/27 -m state –state NEW -m tcp –dport 161 -j ACCEPT

要在前面加 -p tcp

Posted by admin Tagged with: ,
052009

SNAT和DNAT是通过NAT表实现的

SNAT:

将172.16.1.78转换成192.168.1.19
iptables -t nat -A POSTROUTING -s 172.16.1.78 -j SNAT --to-source 192.168.1.19

DNAT:

iptables -t nat -A PREROUTING -d 192.168.1.19 -p tcp -m tcp --dport 80 -j DNAT --to-destination 172.16.1.78

这样访问192.168.1.19的端口就会转发到172.16.1.78的80端口上,如果想转发到172.16.1.78的8080端口上,可以用如下命令

iptables -t nat -A PREROUTING -d 192.168.1.19 -p tcp -m tcp --dport 80 -j DNAT --to-destination 172.16.1.78:8080

当然还需要在filter里允许访问80,8080端口,当然,这里允许了对局域网所有主机80,8080端口的访问,为安全,应该进一步细化规则

iptables -A FORWARD -p tcp -m tcp --dport 80 -j ACCEPT

iptables -A FORWARD -p tcp -m tcp --dport 8080 -j ACCEPT

Posted by admin Tagged with: ,
052009

/usr/local/sbin/iptables -P INPUT ACCEPT
/usr/local/sbin/iptables -P FORWARD ACCEPT
/usr/local/sbin/iptables -P OUTPUT ACCEPT

#
# reset the default policies in the nat table.
#
/usr/local/sbin/iptables -t nat -P PREROUTING ACCEPT
/usr/local/sbin/iptables -t nat -P POSTROUTING ACCEPT
/usr/local/sbin/iptables -t nat -P OUTPUT ACCEPT

#
# flush all the rules in the filter and nat tables.
#
/usr/local/sbin/iptables -F
/usr/local/sbin/iptables -t nat -F

#
# erase all chains that's not default in filter and nat table.
#
/usr/local/sbin/iptables -X
/usr/local/sbin/iptables -t nat -X'

转载自:http://www.7880.com/Info/Article-657b9d40.html

Posted by admin Tagged with:
142009

本文将对iptables的配置做一个综述并且重点介绍一些iptables的配置工具。本文的讨论将着眼于linux内核的IP防火墙以及其各种界面的配置工具,比如:GUI或者脚本(shell、Perl或者特定的配置语言)。使用这些工具能够简化iptables的配置减少配置的错误。关于 iptables的知识请参考Rusty Russell写的Linux iptables HOWTO。

Continue reading »

Posted by admin Tagged with: ,