【已解决】IPF+IPNAT,端口转发不起作用,搞死人了。。。。
本帖最后由 hackson99 于 2012-11-04 10:45 编辑看了精华贴子,看了剑心斑竹的n年前的ipf帖子,google了n多的e文论坛和邮件列表,代理可以,只是外网访问内网主机的80端口不行。高手们啊,帮忙看看吧,兄弟快搞死了!
网卡设置:
re0 192.168.1.200<--内网网关
re1动态地址 <--PPPoE拨号上网
系统:
root@bsd:/root # uname -a
FreeBSD bsd.site 8.3-STABLE FreeBSD 8.3-STABLE #1: Thu Nov1 13:46:37 CST 2012 wjm@bsd.site:/usr/obj/usr/src/sys/GENERICi386
内核编译文件:
#cpu I486_CPU
#cpu I586_CPU
cpu I686_CPU
ident wjm
......
#Add IPFilter for NAT
options IPFILTER
options IPFILTER_LOG
more/etc/rc.conf
defaultrouter="192.168.1.1"
hostname="bsd.site"
ifconfig_re0="inet 192.168.1.200netmask 255.255.255.0"
keymap="us.iso"
named_enable="YES"
sshd_enable="YES"
#For ADSL
ifconfig_re1=up
ppp_enable="YES"
ppp_mode="ddial"
ppp_nat="YES"
ppp_profile="adsl"
#make this machine as a NAT gateway
gateway_enable="YES"
#netd for what??
netd_enable="YES"
ipfilter_enable="YES"
ipfilter_rules="/etc/ipf.rules"
ipmon_enable="YES"
ipmon_flags="-Dsv /var/log/ipfilter.log"
ipnat_enable="YES"
ipnat_rules="/etc/ipnat.rules"
natd_enable="YES"
natd_interface="tun0"
natd_flags="-f /etc/natd.conf"
#for dhcpd
dhcpd_enable="YES"
dhcpd_ifaces="re0"
more /etc/ipf.rules
pass in all
pass out all
# for redirect 80
pass in log quick on tun0 proto tcp from any to any port=80 flags S keep state keep frags
more /etc/ipnat.rules
# for ftp from lan
map tun0 192.168.1.0/24 -> 0.0.0.0/32 proxy port ftp ftp/tcp
# for ftp from gateway
map tun0 0.0.0.0/32 -> 0.0.0.0/32 proxy port 21 ftp/tcp
# for all from lan
map tun0 192.168.1.0/24 -> 0.0.0.0/32 portmap tcp/udp auto
map tun0 192.168.1.0/24 -> 0.0.0.0/32
#redirect 80 to lan's erp server
rdr tun0 0/0 port 80 -> 192.168.1.100 port 80 tcp
sysctl -a
....
net.inet.ip.forwarding: 1
net.inet.ip.redirect: 1
....
ipnat -l
....
MAP 192.168.1.16 3848<- -> a.b.c.d5124
MAP 192.168.1.16 5041<- -> a.b.c.d5057
MAP 192.168.1.16 5041<- -> a.b.c.d5057
MAP 192.168.1.9 9909<- -> a.b.c.d3373
MAP 192.168.1.13 4075<- -> a.b.c.d4343
MAP 192.168.1.9 9909<- -> a.b.c.d3373
MAP 192.168.1.93 3794<- -> a.b.c.d24474
MAP 192.168.1.16 4484<- -> a.b.c.d5256
MAP 192.168.1.16 4000<- -> a.b.c.d5276
MAP 192.168.1.9 4002<- -> a.b.c.d3514
MAP 192.168.1.17 1386<- -> a.b.c.d5434
MAP 192.168.1.13 4072<- -> a.b.c.d4340
MAP 192.168.1.16 4461<- -> a.b.c.d5233
MAP 192.168.1.16 4457<- -> a.b.c.d5229
MAP 192.168.1.9 3162<- -> a.b.c.d3430
MAP 192.168.1.16 4005<- -> a.b.c.d5281
MAP 192.168.1.98 4002<- -> a.b.c.d25942
MAP 192.168.1.16 5041<- -> a.b.c.d5057
MAP 192.168.1.16 5041<- -> a.b.c.d5057
....
ipfstat -t
bsd.site - IP Filter: v4.1.28 - state top 15:04:31
Src: 0.0.0.0, Dest: 0.0.0.0, Proto: any, Sorted by: # bytes
Source IP Destination IP ST PR #pkts #bytes ttl
(这里是空白的。。。。。不知道怎么回事)
代理正常,内网通过192.168.1.200自动获取IP,上网,很正常。就是从外网连接a.b.c.d的80端口时不能转发到内网100的机器上。
大侠们啊,怎么办呢???救命吧,。。。。。。。。。。。。
:dizzy::dizzy::dizzy:
本帖最后由 anthie 于 2012-11-02 16:15 编辑
ipf 我是搞过的。很好用。但是我要问楼主是:这两个选项放这里为了搞基吗?
ppp_nat="YES"
netd_enable="YES" 回复 2# anthie
我也是按照文档的说明来做的。
老兄的意思是,这两天可以删除?那我的内网上网受影响吗??
谢谢! 去读一读Freebsd的handbook
里面有一章专门讲Ipf的。
另外把ppp nat 设成No 因为默认是打开的。 已经有natd了,就用ipfw吧,你把两个防火墙、PPP都掺合到一块了。 最近谷歌不好使 一搜就挂:outu: 回复 6# muwanqing_cu
18禁大会搞得呗。
十八禁大会总结:不要…不要…!要…要…!大力…大力…!深入…深入…!还要…还要…!高举…加快…推进…探索…坚持…两手抓…要硬…狠抓…奋力…!!!啪啪啪啪啪啪啪… 高:-L··············· 好了,搞定了。
是我搞混了。把PPPnat 和natd 和ipnat都混合到一起了。虽然内网可以无限制的访问外网,但是,到外网进来访问内网的80端口、也就是要NAT做端口转发的时候,可能是FreeBSD不知道用那个nat机制:因为有三个nat机制---pppnat ipnat natd,所以,FreeBSD不知如何做。是这个意思吧。呵呵。
现在就是很简单的,去除了 ppp_nat,去除了natd,只留下ipfilter和ipnat,很简单就搞定了。呵呵,谢谢各位帮忙哦~~~~
页:
[1]