分页: 1 / 1

OpenBSD做简单NAT路由备忘pf.conf named.conf ppp.conf

发表于 : 2013-05-10 15:43
f5b
OpenBSD做简单可用的nat路由器,未优化
1. ADSL 拨号上网
2. 用Named做DNS cache
3. 有需要可编辑/etc/dhcpd.conf 启动dhcp服务,这样局域网电脑就能自动获取ip上网了。
参看
http://www.openbsd.org/faq/pf/example1.html

/etc/sysctl.conf增加
net.inet.ip.forwarding=1

/etc/rc.conf.local

代码: 全选

ntpd_flags=""
named_flags=""
/var/named/etc/named.conf ###有些参数未消化:)

代码: 全选

acl clients {
	localnets;
	::1;
};

options {
	version "";	// remove this to allow version queries
	forward only;
	forwarders { 114.114.114.114; 8.8.8.8; };
	max-cache-size 2097152;   //not sure, optional.

	listen-on    { any; };
	listen-on-v6 { any; };

	empty-zones-enable yes;

	allow-recursion { clients; };
};

logging {
	category lame-servers { null; };
};

/etc/pf.conf

代码: 全选

    # increase default state limit from 10'000 states on busy systems
    #set limit states 100000

    int_if="em0"  ###修改为内网网卡

    set skip on lo

    match out on tun0 inet from !(tun0:network) to any nat-to (tun0:0)

    block in
    pass out quick

    antispoof quick for { lo $int_if }

    pass in on $int_if

    # By default, do not permit remote connections to X11
    block in on ! lo0 proto tcp to port 6000:6010

/etc/ppp/ppp.conf ###这里有2g/3g 中国移动/联通/电信 ADSL的 上网配置

代码: 全选

###start(dial):ppp -auto chinatelcom, stop(disconnect):pkill ppp  
###(c) f5b
default:
  set log Phase Chat LCP IPCP CCP tun command
### chinatelcom, cdma 3g ok.
chinatelcom:
  set device /dev/cuaU0
  set speed 1843200
  set dial "ABORT BUSY ABORT NO\\sCARRIER TIMEOUT 5 \
           \"\" AT OK-AT-OK ATE1Q0 OK \\dATDT\\T TIMEOUT 40 CONNECT"
  set phone "#777"
  set login
  set authname [email protected]
  set authkey vnet.mobi
  set timeout 120
  set ifaddr 10.0.0.1/0 10.0.0.2/0 255.255.255.0 0.0.0.0
  add default HISADDR
  enable dns
### chinamobile, 2g only
chinamobile:
  set device /dev/cuaU0
  set dial "ABORT ERROR ABORT BUSY ABORT NO\\sCARRIER TIMEOUT 5 \
           \"\" ATZ OK-ATZ-OK AT+CGDCONT=1,\\\"IP\\\",\\\"cmnet\\\" OK \\dATD\\T TIMEOUT 40 CONNECT"
  set phone "*99#"
  set speed 460800
  set login
  set timeout 0
  set ifaddr 10.0.0.1/0 10.0.0.2/0 255.255.255.0 0.0.0.0
  add default HISADDR
  enable dns
### chinaunicom, 3g only
chinaunicom:
  set device /dev/cuaU0
  set dial "ABORT ERROR ABORT BUSY ABORT NO\\sCARRIER TIMEOUT 5 \
           \"\" ATZ OK-ATZ-OK AT+CGDCONT=1,\\\"IP\\\",\\\"3gnet\\\" OK \\dATD\\T TIMEOUT 40 CONNECT"
  set phone "*99#"
  set speed 7200000
  set login
  set timeout 0
  set ifaddr 10.0.0.1/0 10.0.0.2/0 255.255.255.0 0.0.0.0
  add default HISADDR
  enable dns
### China Telecom ADSL only, change bge0 to interface name connected to modem, change authname & authkey according.
adsl:
 set device "!/usr/sbin/pppoe -i bge0"
 set mtu max 1492
 set mru max 1492
 set speed sync
 disable acfcomp protocomp
 deny acfcomp
 set authname [email protected]
 set authkey 12345
 enable lqr
 enable mssfixup
 enable dns
 add! default HISADDR

Re: OpenBSD做简单NAT路由备忘pf.conf named.conf ppp.conf

发表于 : 2013-12-24 22:48
fengjunfan
f5b 写了:OpenBSD做简单可用的nat路由器,未优化
1. ADSL 拨号上网
2. 用Named做DNS cache
3. 有需要可编辑/etc/dhcpd.conf 启动dhcp服务......
我用的是河南省联通的adsl,4M宽带;想用openbsd 5.4 做路由器,做路由的那台主机可以上网,但下面的内网就是上不去!内网我装了两个网卡,接外网一个网卡,一共3个网卡。pf.conf 那部分模仿
faq.openbsd.org 的那个例子,可以下面的电脑就是不通,上不了网!

/etc/pf.conf

代码: 全选

    # increase default state limit from 10'000 states on busy systems
    #set limit states 100000

    int_if="em0"  ###修改为内网网卡

    set skip on lo

    match out on tun0 inet from !(tun0:network) to any nat-to (tun0:0)
####
在openbsd 5.4 中,可不可以写成这样:
[color=#FF0040]# match rules

match out on egress inet from !(egress:network) to any nat-to (egress:0)[/color]

#####
    block in
    pass out quick

    antispoof quick for { lo $int_if }

    pass in on $int_if

    # By default, do not permit remote connections to X11
    block in on ! lo0 proto tcp to port 6000:6010
openbsd 5.4 也可这样写吗?
我如何写才能保证另外两个网卡也可以上网?怎么修改你的设置?谢谢

Re: OpenBSD做简单NAT路由备忘pf.conf named.conf ppp.conf

发表于 : 2013-12-25 13:21
fengjunfan
pf.conf 部分:
如果有多个网卡 int_if="xl0 xl1" 对不对?
antispoof quick for { lo $int_if } pf 加载时说语法错误 ,请问为什么

另外对thunder下载时出现速度忽快忽慢,但总体是慢,请您也讲一下:pf.conf如何调节

Re: OpenBSD做简单NAT路由备忘pf.conf named.conf ppp.conf

发表于 : 2013-12-27 11:16
bsdplus
想把多个网卡定义在一个宏(Macro)里,要用:
int_if = "{ xl0 xl1}"

使用OpenBSD+ADSL做路由器,最好使用内核模式PPPoE来进行拨号上网,普通的PPPoE速度会慢很多

关于内核模式PPPoE可参考:
http://www.kdump.org/media/kernel-mode-pppoe-on-openbsd

Re: OpenBSD做简单NAT路由备忘pf.conf named.conf ppp.conf

发表于 : 2013-12-31 9:49
fengjunfan
那 pf.conf 的部分用不用修改?
tun0 需不需要改为 pppoe?

Re: OpenBSD做简单NAT路由备忘pf.conf named.conf ppp.conf

发表于 : 2013-12-31 10:36
bsdplus
pf.conf需要相应更改。上面我只是试图回答多网卡时定义宏以及OpenBSD下用ADSL下载慢的问题,不涉及具体的pf.conf的配置