免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123下一页
最近访问板块 发新帖
查看: 7745 | 回复: 22
打印 上一主题 下一主题

晚上睡不着,用PF写了个策略路由教本,大家看看 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-02-17 09:42 |只看该作者 |倒序浏览
讨论一下,暂时没条件测试:

# vi /etc/rc.conf
================+==============+=================
ifconfig_rl0="inet 218.104.232.207 netmask 255.255.255.0"    //网通
ifconfig_rl1="inet 61.154.11.150 netmask 255.255.255.0"        //电信
pf_enable="YES"
================+==============+=================

# vi /etc/pf.conf
================+==============+=================
##anchors
ext_if1 = "rl0"
ext_if2 = "rl1"
ext_gw1 = "218.104.232.1"
ext_gw2 = "61.154.11.254"
loop = "lo0"
service = "{22, 80, 443}"

scrub in all

antispoof for {$ext_if1, $ext_if2} inet

##default deny
block all
block return

##general "pass in" rules for external and loop interfaces
pass quick on $loop all
pass in on {$ext_if1, $ext_if2} proto tcp from any to any port $service flags S/SA modulate state
pass in on {$ext_if1, $ext_if2} proto { udp, icmp } from any to any keep state

##general "pass out" rules for external interfaces
pass out on {$ext_if1, $ext_if2} proto tcp from any to any flags S/SA modulate state
pass out on {$ext_if1, $ext_if2} proto { udp, icmp } from any to any keep state

##route packets from any IPs on $ext_if1 to $ext_gw1 and the same for
##$ext_if2 and $ext_gw2
pass out quick on $ext_if1 route-to ($ext_if2 $ext_gw2) from $ext_if2 to any
pass out quick on $ext_if2 route-to ($ext_if1 $ext_gw1) from $ext_if1 to any
================+==============+=================

这个教本参考了pf的faq写的。实现双线接入情况下,从网通专线来的IP包,回去的时候还走网通线路,同理,电信线路来的IP包回去的时候还走电信线路。大家帮我分析一下,这个教本实现的思路有没有问题。


下面这个是网上参考别人的思路来的,给IP包打了标记,IP包出去的时候根据原先打的标记判断IP包的出口是那个:


给IP包打标记的策略路由方法:


##anchors

ext_if1 = "rl0"    //接网通
ext_if2 = "rl1"    //接电信
ext_gw1 = "218.104.232.1"   //网通网关
ext_gw2 = "61.154.11.254"   //电信网关
loop = "lo0"
service = "{22, 80, 443}"

scrub in all
antispoof for {$ext_if1, $ext_if2} inet

##default deny

block all
block return

##general "pass in" rules for external and loop interfaces

pass quick on $loop all
pass in on $ext_if1 tag cncgroup keep state
pass in on $ext_if2 tag chinanet keep state

##general "pass out" rules for external interfaces

pass out on {$ext_if1, $ext_if2} proto tcp from any to any flags S/SA modulate state
pass out on {$ext_if1, $ext_if2} proto { udp, icmp } from any to any keep state

##route packets from any IPs on $ext_if1 to $ext_gw1 and the same for
##$ext_if2 and $ext_gw2

pass out quick on $ext_if1 route-to ($ext_if2 $ext_gw2) tagged chinanet keep state
pass out quick on $ext_if2 route-to ($ext_if1 $ext_gw1) tagged cncgroup keep state

[ 本帖最后由 llzqq 于 2006-11-30 17:20 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2006-02-17 12:20 |只看该作者
没人理

论坛徽章:
0
3 [报告]
发表于 2006-02-17 12:31 |只看该作者
太高了吧,估计没人敢来提点什么!!!
2004xxx 该用户已被删除
4 [报告]
发表于 2006-02-17 12:52 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
2
丑牛
日期:2013-09-29 09:47:222015七夕节徽章
日期:2015-08-21 11:06:17
5 [报告]
发表于 2006-02-17 13:03 |只看该作者
印象中曾经试过,好像不管用,可能是没弄好吧,后来因为急着用,就在dns上打主意了

论坛徽章:
0
6 [报告]
发表于 2006-02-17 13:05 |只看该作者
原帖由 2004xxx 于 2006-2-17 12:52 发表
状态和接口无关吗?

如果有关,在只是提供服务的情况下,
还需要这个吗?

[code]pass out on $ext_if1 route-to ($ext_if2 $ext_gw2) from $ext_if2 to any
pass out on $ext_if2 route-to ($ext_if1 $ext_gw ...


这个是核心,实现由那条线来,还到那条线去。

论坛徽章:
0
7 [报告]
发表于 2006-02-17 13:10 |只看该作者
谁有条件试验一下,用几台路由器也可以做这个试验,可惜偶没有。
2004xxx 该用户已被删除
8 [报告]
发表于 2006-02-17 13:45 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
9 [报告]
发表于 2006-02-17 15:43 |只看该作者
这个是pf文档中的一个范例---双线接入做网关负载均衡:

##anchors
lan_net = "192.168.0.0/24"
int_if  = "fxp0"
ext_if1 = "rl0"
ext_if2 = "rl1"
ext_gw1 = "221.33.88.254"
ext_gw2 = "61.0.57.254"

##nat outgoing connections on each internet interface
nat on $ext_if1 from $lan_net to any -> ($ext_if1)
nat on $ext_if2 from $lan_net to any -> ($ext_if2)

##default deny
block in  from any to any
block out from any to any

##pass all outgoing packets on internal interface
pass out on $int_if from any to $lan_net
##pass in quick any packets destined for the gateway itself
pass in quick on $int_if from $lan_net to $int_if
##load balance outgoing tcp traffic from internal network.
pass in on $int_if route-to \
{ ($ext_if1 $ext_gw1), ($ext_if2 $ext_gw2) } round-robin \
proto tcp from $lan_net to any flags S/SA modulate state
##load balance outgoing udp and icmp traffic from internal network
pass in on $int_if route-to \
{ ($ext_if1 $ext_gw1), ($ext_if2 $ext_gw2) } round-robin \
proto { udp, icmp } from $lan_net to any keep state

##general "pass out" rules for external interfaces
pass out on $ext_if1 proto tcp from any to any flags S/SA modulate state
pass out on $ext_if1 proto { udp, icmp } from any to any keep state
pass out on $ext_if2 proto tcp from any to any flags S/SA modulate state
pass out on $ext_if2 proto { udp, icmp } from any to any keep state

##route packets from any IPs on $ext_if1 to $ext_gw1 and the same for
##$ext_if2 and $ext_gw2
pass out on $ext_if1 route-to ($ext_if2 $ext_gw2) from $ext_if2 to any
pass out on $ext_if2 route-to ($ext_if1 $ext_gw1) from $ext_if1 to any


我是在这个基础上稍加修改二来的。应该不会有楼上提到的问题。

论坛徽章:
0
10 [报告]
发表于 2006-02-19 07:22 |只看该作者
一个试验这个教本效果的简单网络拓扑图,有条件的网友不妨试验一下:

观察网络流量从那个专线出去的,可以用ifstat工具观察,很直观。

[ 本帖最后由 llzqq 于 2006-2-19 07:29 编辑 ]

绘图3_gif_1.gif (17.7 KB, 下载次数: 36)

image

image
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP