分享
 
 
 

openbsd+pf配置

王朝other·作者佚名  2008-05-21
窄屏简体版  字體: |||超大  

openbsd+pf配置

初学openbsd+pf,见笑了,不对的请指正

qq:35907960

mail:yanypunix@yahoo.com.cn

openbsd服务器3块网卡

rl0 61.131.58.x 接公网

rl1 192.168.1.0/24 接内网段1

rl2 131.107.3.0/24 接内网段2

有些ip要24小时上网,有些ip限定8小时上网

写了两个脚本

shellpf1+pf1.conf(24小时上网)

shellpf2+pf2.conf(8小时上网)

shellpf1,shellpf2,pf1.conf,pf2.conf四个文件放在/etc/pf目录下

在crontab里定时执行,

文件/etc/pf/pf1.conf的配置如下:

ext_if="rl0" #接公网192_if="rl1" #接内网段1131_if="rl2" #接内网段2192net="{192.168.1.222/32,192.168.1.5/32,192.168.1.132/32,192.168.1.77/32,192.168.1.2/32,192.168.1.8/32,192.168.1.4/32,192.168.1.6/32,192.168.1.28/32,192.168.1.177/32,192.168.1.195/32,192.168.1.45/32,192.168.1.47/32,192.168.1.16/32,192.168.1.249/32,}"131net="{131.107.3.215/32,131.107.3.216/32,131.107.3.217/32,131.107.3.218/32,131.107.3.219/32,131.107.3.220/32,131.107.3.211/32,131.107.3.43/32,131.107.3.47/32,131.107.3.48/32,131.107.3.174/32,131.107.3.175/32,131.107.3.181/32,131.107.3.194/32,131.107.3.123/32,131.107.3.252/32,131.107.3.253/32,131.107.3.216/32,131.107.3.198/32,131.107.3.17/32}"tcp_services="{22,113}"icmp_types="echoreq"priv_nets="{127.0.0.0/8,192.168.0.0/16,172.16.0.0/12,10.0.0.0/8}"set optimization aggressivescrub in allnat on rl0 from 192.168.1.0/24 to any -> 61.131.58.x/32nat on rl0 from 131.107.3.0/24 to any -> 61.131.58.x/32block allpass quick on lo0 allblock drop in quick on $ext_if from $priv_nets to anyblock drop out quick on $ext_if from any to $priv_nets#pass in inet proto icmp all icmp-type $icmp_types keep statesblock in quick on $192_if from 131.107.3.0/24 to anyblock out quick on $192_if from any to 131.107.3.0/24block in quick on $131_if from 192.168.1.0/24 to anyblock out quick on $131_if from any to 192.168.1.0/24pass in on $192_if from $192net to any keep statepass out on $192_if from any to $192net keep statepass in on $131_if from $131net to any keep statepass out on $131_if from any to $131net keep statepass out on $ext_if proto tcp all modulate state flags S/SApass out on $ext_if proto udp all keep state

/etc/pf/pf2.conf如下

ext_if="rl0" #接公网192_if="rl1" #接内网段1131_if="rl2" #接内网段2192net="{192.168.1.2/32,192.168.1.8/32,192.168.1.6/32,192.168.1.45/32,192.168.1.47/32,192.168.1.16/32,192.168.1.28/32,192.168.1.249/32,192.168.1.222/32}"131net="{131.107.3.48/32,131.107.3.47/32}"tcp_services="{22,113}"icmp_types="echoreq"priv_nets="{127.0.0.0/8,192.168.0.0/16,172.16.0.0/12,10.0.0.0/8}"set optimization aggressivescrub in allnat on rl0 from 192.168.1.0/24 to any -> 61.131.58.x/32nat on rl0 from 131.107.3.0/24 to any -> 61.131.58.X/32block allpass quick on lo0 allblock drop in quick on $ext_if from $priv_nets to anyblock drop out quick on $ext_if from any to $priv_nets#pass in inet proto icmp all icmp-type $icmp_types keep statesblock in quick on $192_if from 131.107.3.0/24 to anyblock out quick on $192_if from any to 131.107.3.0/24block in quick on $131_if from 192.168.1.0/24 to anyblock out quick on $131_if from any to 192.168.1.0/24pass in on $192_if from $192net to any keep statepass out on $192_if from any to $192net keep statepass in on $131_if from $131net to any keep statepass out on $131_if from any to $131net keep statepass out on $ext_if proto tcp all modulate state flags S/SApass out on $ext_if proto udp all keep state

/etc/pf/shellpf1如下

pfctl -d

pfctl -e

pfctl -f /etc/pf/pf1.conf

/etc/pf/shellpf2如下

pfctl -d

pfctl -e

pfctl -f /etc/pf/pf2.conf

crontab如下 /var/cron/tabs/root

# $OpenBSD: crontab,v 1.9 2001/09/11 19:03:55 millert Exp $# $Id: crontab-nomail,v 1.1 2002/04/15 01:03:20 jmates Exp $## JAM 2002-04-14 Disabled mailings from root.## /var/cron/tabs/root - root's crontab#SHELL=/bin/shPATH=/bin:/sbin:/usr/bin:/usr/sbin:/etc/pfHOME=/var/log##minute hour mday month wday command#*/10 18 * * * /etc/pf/shellpf2*/50 7 * * * /etc/pf/shellpf1## sendmail clientmqueue runner## rotate log files every hour, if necessary0 * * * * /usr/bin/newsyslog# send log file notifications, if necessary#1-59 * * * * /usr/bin/newsyslog -m## do daily/weekly/monthly maintenance30 1 * * * /bin/sh /etc/daily 1>/var/log/daily.out 2>&130 3 * * 6 /bin/sh /etc/weekly 1>/var/log/weekly.out 2>&130 5 1 * * /bin/sh /etc/monthly 1>/var/log/monthly.out 2>&1

每天7:50执行脚本shellpf1,18:10执行shellpf2

对于mac与ip绑定,可写一脚本,防止有人改ip上网(会改mac地址的除外)

arp -s 192.168.1.4 00:0c:76:84:52:f0 pub

arp -s 192.168.1.5 00:0c:76:2f:dd:2c pub

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有