当前位置:  首页  >  服务器技术  >  Linux/unix  >  Linux教程

FreeBsd5.4+pf+squid反向代理实战笔记

文章标题:FreeBsd5.4+pf+squid反向代理实战笔记。Linux是中国IT实验室的一个技术频道。包含桌面应用,Linux系统管理,内核研究,嵌入式系统和开源等一些基本分类

1、硬件配置
HP NETSERVER 800 PⅢ1000 内存256M Inter82559网卡两张
2、分区情况
Filesystem Size Used Avail Capacity Mounted on
/dev/da0s1a 248M 54M 174M 24% /
devfs 1.0K 1.0K 0B 100% /dev
/dev/da0s1f 4.8G 130M 4.3G 3% /home
/dev/da0s1d 248M 12K 228M 0% /tmp
/dev/da0s1g 4.8G 565M 3.9G 12% /usr
/dev/da0s1e 5.8G 410K 5.3G 0% /var
3、系统安装情况
采用最小化安装
并且安装src和ports(原本打算采用ports安装,但是不知道怎么搞的,竟然不能cvs源码,当然也就不能通过ports安装,无奈之下只能采用源码编译)
4、内核编译
没有对内核采用优化,这里只是为了验证pf和squid结合做反向代理的可行性,在实际的生产应用中应该对服务器内核做一定程度的优化。

cd /usr/src/sys/i386/conf
cp GENERIC cache

编辑内核cache在内核中添加如下选项
device pf
device pflog
device pfsync
options ALTQ
options ALTQ_CBQ

编译内核
/usr/sbin/config cache
cd ../config/cache
make depend
make
make install

至此内核编译完毕
reboot

5、让系统自动加载pf
编辑/etc/rc.conf
usbd_enable="NO"
defaultrouter="218.4.xxx.xxx"
hostname="cache.aaa.com"
ifconfig_fxp0="inet 218.4.xxx.xxx netmask 255.255.255.248"
ifconfig_fxp1="inet 192.168.2.10 netmask 255.255.255.0"
gateway_enable="YES"
inetd_enable="YES"
pf_enable="YES"
pf_rules="/etc/pf.conf"
pf_flags=""
pflog_enable="YES"
pflog_logfile="/var/log/pflog"
sshd_enable="YES"

6、打开ip转发
在/etc/sysctl.conf中添加如下内容
net.inet.ip.forwarding=1

7、实现共享上网,最简单的pf设置
wan_if="fxp0"
lan_if="fxp1"
inter_net="192.168.2.0/24"
web_server="192.168.2.3"
ftp_server="192.168.2.3"
scrub in all
nat on $wan_if from $inter_net to any -> fxp0

rdr on fxp1 proto tcp from $lan_if to any port 80 -> $lan_if port 80

rdr on fxp1 proto tcp from any to any port 21 -> 127.0.0.1 port 8021
#rdr on fxp0 proto tcp from any to $wan_if port 80 ->$web_server port 8080
#rdr on fxp1 proto tcp from $lan_if to $wan_if port 80 ->$web_server port 8080

rdr on $wan_if proto tcp from any to any port 21 -> $ftp_server port 21
rdr on $wan_if proto tcp from any to any port 49152:65535 -> $ftp_server port 49152:65535

# in on $wan_if
pass in quick on $wan_if proto tcp from any to $ftp_server port 21 keep state
pass in quick on $wan_if proto tcp from any to $ftp_server port > 49151 keep state

# out on $lan_if
pass out quick on $lan_if proto tcp from any to $ftp_server port 21 keep state
pass out quick on $lan_if proto tcp from any to $ftp_server port > 49151 keep state

#Disable danger port
#Danger_Port="{445 135 139 593 5554 9995 9996}"
#block quick on $wan_if inet proto tcp from any to any port $Danger_Port
#block quick on $wan_if inet proto tcp from any to any port $Danger_Port
pass in all
pass out all


 

[1] [2] 下一页

吐了个 "CAO" !
扫码关注 PHP1 官方微信号
PHP1.CN | 中国最专业的PHP中文社区 | PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | PHP问答
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved PHP1.CN 第一PHP社区 版权所有