PF防火墙典型应用
PF防火墙起源于OPENBSD项目。近年来FREEBSD/NETBSD也开始支持PF防火墙了,在BSD系统中PF防火墙变得越来越流行了。这里我们重点结合FTP(因为FTP服务器涉及到FTP和FTP-DATA两个TCP端口,并且又分为主动、被动连接模式。相对其他服务要复杂一些,所以今天主要针对这中环境)应用环境列举几个典型应用。
转载时请保留下面的信息:
作者:LLZQQ
联系:
出自:BBS.CHINAUNIX.NET
代理服务器:OpenBSD-3.9/4.0
客户端配置:Win2k+FileZilla+FlashGet/Linux
1. 采用PF构建NAT服务器,代理LAN中的CLIENTS上网。配置过程如下:
# vi /etc/rc.conf.local
============================
identd_flags=""
inetd=YES
pf=YES
ftpproxy_flags=""
============================
# > /etc/pf.conf
# vi /etc/pf.conf
============= pf.conf ==============
ext_if="rl0"
int_if="fxp0"
ftp_port="{21,2201,20021}"
set skip on lo
scrub in
nat-anchor "ftp-proxy/*"
rdr-anchor "ftp-proxy/*"
nat on $ext_if from !($ext_if) -> ($ext_if:0)
rdr pass on $int_if proto tcp to port $ftp_port -> 127.0.0.1 port 8021
anchor "ftp-proxy/*"
antispoof for $ext_if inet
block in
pass quick on $int_if
pass in on $ext_if proto tcp to ($ext_if) port ssh keep state
pass out keep state
============= pf.conf =============
简单解释:
ftp_port="{21,2201,20021}"
在互联网上不是所有的FTP服务器都监听TCP 21端口,比如有的监听2201,20021等。当CLIENTS采用PASV模式(被动模式)来连接外部FTP服务器时没有问题,但是当用主动模式连接那些非TCP21端口的服务器时就有问题了。针对这种情况,我们把这些端口列出来就可以了(当然我们不可能列出所有的,这个也是很无奈的事情)。
试验结论:
按照上面给出的配置搭建的PF(NAT)服务器可以完美的代理用户连接外部FTP服务器,当然对代理其他类型的服务也没得说。
2. 采用PF构建NAT服务器,代理LAN中的CLIENTS上网,同时NAT服务器上也同时提供FTP服务。配置过程如下:
# vi /etc/rc.conf.local
============================
identd_flags=""
inetd=YES
pf=YES
ftpproxy_flags=""
============================
# > /etc/pf.conf
# vi /etc/pf.conf
============= pf.conf ============
ext_if="rl0"
int_if="fxp0"
ftp_port="{21,221,20021}"
set skip on lo
scrub in
nat-anchor "ftp-proxy/*"
rdr-anchor "ftp-proxy/*"
nat on $ext_if from !($ext_if) -> ($ext_if:0)
rdr pass on $int_if proto tcp to port $ftp_port -> 127.0.0.1 port 8021
anchor "ftp-proxy/*"
antispoof for $ext_if inet
block in
pass quick on $int_if
pass quick on lo
pass in on $ext_if proto tcp to ($ext_if) port ssh keep state
pass in on $ext_if proto tcp to ($ext_if) port ftp keep state
pass in on $ext_if proto tcp from any to any port > 55000 keep state
pass out keep state
============= pf.conf ============
简单解释:
这个规则是在(1)的基础上增加了下面的部分。比较简单这里就不废话了。
pass in on $ext_if proto tcp to ($ext_if) port ftp keep state
pass in on $ext_if proto tcp from any to any port > 55000 keep state
试验结论:
成功!
3. 采用PF构建NAT服务器,代理LAN中的CLIENTS上网,同时映射LAN中的一台FTP服务器到外部网络:
# vi /etc/rc.conf.local
============================
identd_flags=""
inetd=YES
pf=YES
ftpproxy_flags="-R 192.168.0.20 -p 21 -b 202.87.21.43"
============================
# > /etc/pf.conf
# vi /etc/pf.conf
============= pf.conf ============
ext_if="rl0"
int_if="fxp0"
ext_ip = "202.87.21.43"
ftp_ip = "192.168.0.20"
set skip on lo
scrub in
nat-anchor "ftp-proxy/*"
nat on $ext_if inet from $int_if -> ($ext_if)
rdr-anchor "ftp-proxy/*"
pass in on $ext_if inet proto tcp to $ext_ip port 21 flags S/SA keep state
pass out on $int_if inet proto tcp to $ftp_ip port 21 user proxy flags
S/SA keep state
anchor "ftp-proxy/*"
antispoof for $ext_if inet
block in
pass quick on $int_if
pass quick on lo
pass in on $ext_if proto tcp to ($ext_if) port ssh keep state
pass out keep state
============= pf.conf ============
简单解释:
ftpproxy_flags="-R 192.168.0.20 -p 21 -b 202.87.21.43"
其中192.168.0.20是LAN中的FTP服务器。202.87.21.43是NAT服务器的公网IP。
试验结论:
成功!
注意事项:
在OPENBSD中只有3.9/4.0版本才可以支持以上的规则。
转载于:
原作者:llzqq
参考文档:
阅读(1560) | 评论(0) | 转发(0) |