用Packet Filter(PF) 做 IP mapping 遇到問題 - BBS
By Rebecca
at 2010-04-30T16:21
at 2010-04-30T16:21
Table of Contents
架構大致如下:
PC1(server)--| pppoe1 | | |
PC2----------|em1 FreeBSD pppoe2 em0|----|FTTB VDSL|
PC3----------| | | |
IP如下:
PC1: 192.168.198.3/24
PC2: 192.168.198.4/24
PC3: 192.168.198.5/24
FreeBSD
em1: 192.168.198.254/24
em0不帶IP
pppoe1: 固IP, next-hop 1.1.1.1, 介面為tun0
pppoe2: 動IP, next-hop 1.1.1.2, 介面為tun1
想要達到的目的:
由 FreeBSD 撥接 PPPoE 出去取得 public IP, 然後 固IP mapping 到 PC1,
使得外面連線到 固IP 時, 就等同於連線到 PC1;
而 動IP 則作為其它 PC 連外的 NAT(更正確應該說是 PAT) 使用
做法:
使用PF, 設定檔pf.conf如下:
int_if="em1"
int_ip="192.168.198.254"
int_lan="192.168.198.0/24"
dyn1_if="tun1"
dyn1_gw="1.1.1.2"
static_if="tun0"
static_gw="1.1.1.1"
set block-policy return
scrub in all
#將固IP介面上, src為內網的封包做NAT轉換為固IP
nat on $static_if from $int_lan to any -> $static_if
#將動IP介面上, src為內網的封包做NAT轉換為動IP
nat on $dyn1_if from $int_lan to any -> $dyn1_if
#將連線到固IP的port 220 轉到192.168.198.3, 測試看看.
rdr on $static_if from any to $static_if port 220 -> 192.168.198.3
pass all
#抓取預設出口端的封包, 若src為固IP的就將下一站設為固IP的下一站
pass out on $dyn1_if route-to ($static_if $static_gw) proto tcp from $static_if to any flags any
pass out on $dyn1_if route-to ($static_if $static_gw) proto {udp,icmp} from $static_if to any
#因僅指定的來源轉去固IP, 不會有其他封包走錯路到static_if
#pass out on $static_if route-to ($dyn1_if $dyn1_gw) proto tcp from $dyn1_if to any flags any
#pass out on $static_if route-to ($dyn1_if $dyn1_gw) proto {udp,icmp} from $dyn1_if to any
#設定PUM server的封包改走static if出去
pass in on $int_if route-to ($static_if $static_gw) proto tcp from 192.168.198.3 to any flags any
pass in on $int_if route-to ($static_if $static_gw) proto {udp,icmp} from 192.168.198.3 to any
結果:
PC1 連線去外面的話, 如預期地走 固IP 出去;
但若是外面連到 固IP port 220,則會有問題, 出現的狀況如下:
1.FreeBSD 轉送了該 SYN 封包給 PC1
2.PC1 回送 SYN/ACK 封包 給外面來源
3.FreeBSD 從em1收到該封包, 經過轉換後, src 換成 固IP
4.該封包就這樣依照 default gateway 是走 動IP 的介面而送出去了,
沒有再被抓回來轉送到 固IP 介面送出.
想請教不知道有沒有人有這方面的經驗可以指點問題在哪?
--
PC1(server)--| pppoe1 | | |
PC2----------|em1 FreeBSD pppoe2 em0|----|FTTB VDSL|
PC3----------| | | |
IP如下:
PC1: 192.168.198.3/24
PC2: 192.168.198.4/24
PC3: 192.168.198.5/24
FreeBSD
em1: 192.168.198.254/24
em0不帶IP
pppoe1: 固IP, next-hop 1.1.1.1, 介面為tun0
pppoe2: 動IP, next-hop 1.1.1.2, 介面為tun1
想要達到的目的:
由 FreeBSD 撥接 PPPoE 出去取得 public IP, 然後 固IP mapping 到 PC1,
使得外面連線到 固IP 時, 就等同於連線到 PC1;
而 動IP 則作為其它 PC 連外的 NAT(更正確應該說是 PAT) 使用
做法:
使用PF, 設定檔pf.conf如下:
int_if="em1"
int_ip="192.168.198.254"
int_lan="192.168.198.0/24"
dyn1_if="tun1"
dyn1_gw="1.1.1.2"
static_if="tun0"
static_gw="1.1.1.1"
set block-policy return
scrub in all
#將固IP介面上, src為內網的封包做NAT轉換為固IP
nat on $static_if from $int_lan to any -> $static_if
#將動IP介面上, src為內網的封包做NAT轉換為動IP
nat on $dyn1_if from $int_lan to any -> $dyn1_if
#將連線到固IP的port 220 轉到192.168.198.3, 測試看看.
rdr on $static_if from any to $static_if port 220 -> 192.168.198.3
pass all
#抓取預設出口端的封包, 若src為固IP的就將下一站設為固IP的下一站
pass out on $dyn1_if route-to ($static_if $static_gw) proto tcp from $static_if to any flags any
pass out on $dyn1_if route-to ($static_if $static_gw) proto {udp,icmp} from $static_if to any
#因僅指定的來源轉去固IP, 不會有其他封包走錯路到static_if
#pass out on $static_if route-to ($dyn1_if $dyn1_gw) proto tcp from $dyn1_if to any flags any
#pass out on $static_if route-to ($dyn1_if $dyn1_gw) proto {udp,icmp} from $dyn1_if to any
#設定PUM server的封包改走static if出去
pass in on $int_if route-to ($static_if $static_gw) proto tcp from 192.168.198.3 to any flags any
pass in on $int_if route-to ($static_if $static_gw) proto {udp,icmp} from 192.168.198.3 to any
結果:
PC1 連線去外面的話, 如預期地走 固IP 出去;
但若是外面連到 固IP port 220,則會有問題, 出現的狀況如下:
1.FreeBSD 轉送了該 SYN 封包給 PC1
2.PC1 回送 SYN/ACK 封包 給外面來源
3.FreeBSD 從em1收到該封包, 經過轉換後, src 換成 固IP
4.該封包就這樣依照 default gateway 是走 動IP 的介面而送出去了,
沒有再被抓回來轉送到 固IP 介面送出.
想請教不知道有沒有人有這方面的經驗可以指點問題在哪?
--
Tags:
BBS
All Comments
Related Posts
關於Sendmail AUTH Login 的問題
By Iris
at 2010-04-28T21:21
at 2010-04-28T21:21
cp或mv時 顯示狀態
By Mary
at 2010-04-27T16:02
at 2010-04-27T16:02
cp或mv時 顯示狀態
By Delia
at 2010-04-27T15:16
at 2010-04-27T15:16
大家的 FreeBSD 都拿來做甚麼事情比較多 ?
By Caroline
at 2010-04-27T07:58
at 2010-04-27T07:58
wineconsole的中文問題
By Noah
at 2010-04-24T19:39
at 2010-04-24T19:39