Chinaunix

标题: openbsd做NAT死活不通,救命啊 [打印本页]

作者: ioerr    时间: 2011-03-14 10:34
标题: openbsd做NAT死活不通,救命啊
本帖最后由 ioerr 于 2011-03-17 16:33 编辑

换装openBSD4.8中:
rc.conf
   pf=YES

sysctl.conf
   net.inet.ip.forwarding=1

pf规则如下:

ext_if="fxp0"  #外网
int_if ="fxp1"  #内网
dmz_if="rl0"    #dmz

#set skip on lo

pass out on $ext_if from 192.168.1.0/24 to any nat-to $ext_if

block all
pass all



死活不通啊。愁死我了
原来配置过4.2和4.5的,以为很容易的事呢,结果被搞定,help,almost crazy!


3.17日补充:
----------
现在是调通了,但是谁能解释下为什么蓝色的规则不通么?
作者: congli    时间: 2011-03-14 13:38
现在PF的规则搞得有点不适应!
作者: congli    时间: 2011-03-14 13:40
pass out on $ext_if inet from 192.168.1.0/24 to any nat-to $ext_if
作者: congli    时间: 2011-03-14 13:42
本帖最后由 congli 于 2011-03-14 13:43 编辑

前两天在4.8上测试的

  1. ext_if = "em1"
  2. int_if = "em0"
  3. lo_if  = "lo0"

  4. pass quick on $lo_if all
  5. pass out on $ext_if inet from $int_if:network to any nat-to $ext_if
  6. pass quick on $int_if all keep state

复制代码

作者: ioerr    时间: 2011-03-14 14:11
我的  :pass out on $ext_if from 192.168.1.0/24 to any nat-to $ext_if
版主的:pass out on $ext_if inet from 192.168.1.0/24 to any nat-to $ext_if

就查一個inet?

下午開會,有時間我試試去
作者: congli    时间: 2011-03-14 14:28
应该是block all, 如果是,还得加个quick.
pass out quick on $ext_if inet from 192.168.1.0/24 to any nat-to $ext_if
作者: congli    时间: 2011-03-14 14:53
按FAQ上,又可以使用match及pass两个.

  1. ext_if = "em1"
  2. int_if = "em0"
  3. lo_if  = "lo0"

  4. pass quick on $lo_if all
  5. pass quick on $int_if all keep state

  6. match out on $ext_if inet from $int_if:network to any nat-to $ext_if
  7. pass out on $ext_if from $ext_if to any
复制代码

作者: myuebbs    时间: 2011-03-14 16:01
这个您加 了没
# nat/rdr
#nat on $ext_if from $stu_if:network to any -> ($ext_if)
nat on $ext_if from $web_if:network to any -> ($ext_if)
nat on $ext_if from $oth_if:network to any -> ($ext_if)
rdr on $ext_if proto tcp from any to any port {80,21,20} -> $web_host

呵呵,致命的一处,貌似
作者: ioerr    时间: 2011-03-14 16:44
回复 8# myuebbs


    我现在还没通,考虑不了www什么的服务。
作者: ioerr    时间: 2011-03-14 16:54
回复 6# congli


    初步找到问题了,应该是
pass out quick on $ext_if from $int_if:network to any nat-to $ext_if

加上这个quick就ok了,艹,就这个,差点让我吐血。

我再好好试试,查查手册,然后来个总结,就这么点,真是郁闷,幸好版主帮忙,谢谢了!
作者: freebsdpf    时间: 2011-03-14 16:59
本帖最后由 freebsdpf 于 2011-03-14 17:05 编辑

match out on $ext_if from !($ext_if) to any nat-to ($ext_if)
pass out on $ext_if all
试试
作者: congli    时间: 2011-03-14 17:11
这个您加 了没
# nat/rdr
#nat on $ext_if from $stu_if:network to any -> ($ext_if)
nat on $ext_if f ...
myuebbs 发表于 2011-03-14 16:01

这是以前版本的写法,现在的都变了.
作者: lsstarboy    时间: 2011-03-14 21:45
有很多人不喜欢读man
作者: ioerr    时间: 2011-03-16 15:50
这个match关键字真的需要好好研究下
作者: ioerr    时间: 2011-03-16 15:53
本帖最后由 ioerr 于 2011-03-16 15:59 编辑

测试过的几组规则,给大家参考吧。前面后面都没有任何其他规则,除了宏以外。
该好好看man去了,nat定义形式变了,真是的 ,这种形式上的变化有什么好处呢,搞不懂!

1.
----------

pass out on $ext_if from $int_if:network to any nat-to $ext_if


2.
----------

match out on $ext_if from $int_if:network to any nat-to $ext_if
pass on $ext_if


3.
----------
不通!!!估计加上quick可以通
pass out on $ext_if from $int_if:network to any nat-to $ext_if
block all

4.
--------------
不通
match out on $ext_if from $int_if:network to any nat-to $ext_if
pass on $ext_if from $int_if:network to any
作者: congli    时间: 2011-03-16 17:24
4.
--------------
不通
match out on $ext_if from $int_if:network to any nat-to $ext_if
pass on $ext_if from $int_if:network to any

要改成下面这样,因为不可能有内网Ip经过.:
pass on $ext_if from $ext_if to any
作者: wosl2001    时间: 2011-03-17 13:45
lZ 你的系统是否没有打2-16的补丁 提示只是地址块解析有问题 其实也影响了nat
更新系统后
match out on $ext_if from $int_if:network to any nat-to $ext_if
pass on $ext_if
等于
pass out on $ext_if from $int_if:network to any nat-to $ext_if

两种都可以通!
作者: ioerr    时间: 2011-03-17 15:56
回复 16# congli


    多谢版主指教,明白了
作者: ioerr    时间: 2011-03-17 16:34
哪位解释下为什么1楼蓝色的规则不通,最后是个pass all啊,莫名啊
作者: congli    时间: 2011-03-17 17:24
哪位解释下为什么1楼蓝色的规则不通,最后是个pass all啊,莫名啊
ioerr 发表于 2011-03-17 16:34



    难道是bug?:wink:
作者: ioerr    时间: 2011-03-18 10:11
回复 20# congli


    版主给他们邮件列表问下吧。我不会用
作者: ioerr    时间: 2011-03-18 11:10
关于1楼蓝色规则不通原因可能如下:

pf FAQ中有如下一段:
Translation Rule Exceptions

If you need to translate most traffic, but provide exceptions in some cases, make sure that the exceptions
are handled by a filter rule which does not include the nat-to parameter. For example, if the NAT
example above was modified to look like this:

pass out on tl0 from 192.168.1.0/24 to any nat-to
24.2.74.79
pass out on tl0 from 192.168.1.208 to any

Then the entire 192.168.1.0/24 network would have its packets translated to the external address
24.2.74.79 except for 192.168.1.208.

因此1楼蓝色规则中,后面的那条pass all符合这个说法,所以不通!!!
作者: ioerr    时间: 2011-03-18 11:33
做nat后,如果想排除某些ip,后面跟一条pass out on $ext_if from yourIP to any,或者更宽泛的pass out规则,要包含前面的那个。详细的我还没试,感觉还不如原来的方便。
作者: congli    时间: 2011-03-18 13:17

  1. ext_if = "em1"
  2. int_if = "em0"
  3. lo_if  = "lo0"

  4. pass quick on $lo_if all
  5. pass quick on $int_if all keep state

  6. pass out on $ext_if from 192.168.2.0/24 to any nat-to $ext_if
  7. #block all
  8. pass all
复制代码
刚才试了一下,都是不通,看来这pass all不能随便用,得看上下文,否则实际效果跟想的有的出入.
作者: ioerr    时间: 2011-03-18 14:43
如果不想受pass all 的影响,前面加上quick即可。刚测试过,大家可以再试试看。
作者: ioerr    时间: 2011-03-18 15:02
pass out quick on $ext_if from 192.168.2.0/24 to any nat-to $ext_if
block all

这个也不通,我真晕啊。按说加了quick就ok了,不通!看faq去
作者: ioiioi    时间: 2011-03-20 00:05
回复 16# congli


    嗯,nat问题也把我搞死了,根据版主的这种做法,我终于配通了nat,但是跟pf faq有很大差异,难道openbsd4.8的文档质量下降了?

This would lead to a most basic form of these lines similar to this:

    match out on tl0 from 192.168.1.0/24 to any nat-to 24.5.0.5
    pass on tl0 from 192.168.1.0/24 to any

or you may simply use

    pass out on tl0 from 192.168.1.0/24 to any nat-to 24.5.0.5

This rule says to perform NAT on the tl0 interface for any packets coming from 192.168.1.0/24 and to replace the source IP address with 24.5.0.5.

作者: ioiioi    时间: 2011-03-20 22:40
match out on $ext_if from !($ext_if) to any nat-to ($ext_if)
   
block all
pass out on $ext_if all
pass in on $lan_if to port blah blah
pass in on $dmz_if to port blah blah
pass quick inet from $lan_net to $dmz_net blah blah
pass quick inet from $dmz_net to $lan_net blah blah

因为4.8的nat中必须要pass out on tl0 all,相当于允许openbsd的外网卡可以访问外面所有的服务,因此在入方向需要做限制。
作者: guoruimin    时间: 2011-03-24 09:56
本帖最后由 guoruimin 于 2011-03-24 09:58 编辑

实在不行,换linux!
性能高,驱动全。
作者: congli    时间: 2011-03-24 10:06
Linux也不行! 换M$?
作者: ioerr    时间: 2011-05-25 11:18
match out on $ext_if from !($ext_if) to any nat-to ($ext_if)
pass out on $ext_if all
试试
freebsdpf 发表于 2011-03-14 16:59


又试了试,汇报如下:
---------------------
1.通,去掉quick不通。
pass out quick on $ext_if from $int_if:network to any nat-to $ext_if

block all
pass all

2.对比看下面,是freebsdpf的规则,这个通,把括号里面的改成和我上面一样也通


match out on $ext_if from !($ext_if) to any nat-to ($ext_if)
no quick
block all
pass all


很怪吧,按说pass模式的也应该通啊,看来match和pass配合起来做nat用,对比单独在pass里面配置nat要方便,里面原因不清楚。
作者: ioerr    时间: 2011-05-25 11:24
只记得在faq里面说,match规则的动作,在碰上匹配包的pass或者block时会起作用。这就是说match先匹配,碰到后面规则然后执行。

再分析直接一条规则nat的(第一条),不能在一条规则里面直接匹配+执行动作。


目前就分析到这,希望对兄弟们有用。我是不是词语很乱啊,大家看man吧,然后自己试试就知道。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2