由林克敏主任的網路實驗室下載的文件,  網址 http://www.lab.mlc.edu.tw/phorum/

請教如何用Freebsd當交換器
發言人: 游志峰 (---.dialup.seed.net.tw)
發表日期:   05-21-01 21:45

林主任您好
本校adsl是由小烏龜接到交換器Zylan switch,上星期五可能是遭受雷擊,目前
交換器已損壞送修,請教是否可用Freebsd裝2片網路卡代替,縣網的人告訴我一片
IP 163.17.181.254接到hub,另一片10.111.66.193接到小烏龜就可以了,不知道您
有沒有這樣做過,是否就是NAT的方式?

ip位址規劃
A B D
校方LAN IP CHT設備IP 縣網IP
10.111.71.193 10.111.71.194 10.111.66.193

謝謝!

 

 Re: 請教如何用Freebsd當交換器
發言人: Tim (---.bsdlab.idv.tw)
發表日期:   05-21-01 22:14

也就是將「交換器Zylan switch」替換成一台「FreeBSD」。
這是NAT。

 

 Re: 請教如何用Freebsd當交換器
發言人: 顏國雄 (---.lsps.tp.edu.tw)
發表日期:   05-22-01 01:49

有 ADSL 的 ATUR
只要讓 FreeBSD 扮演 gateway 的角色


1.兩張網卡 && 不需NAT

    ┌─ATUR→Internet
||||||||HUB||||||||
    ↑fxp0
    ├FreeBSD
    ↓fxp1
||||||||HUB||||||||
 │  
 ┴
其它電腦(用public IP && gateway 設 163.17.181.254)

--------------------------------------- gate.sh
ifconfig fxp0 10.111.71.193 netmask 255.255.255.252
ifconfig fxp1 163.17.181.254 netmask 255.255.255.0 aliase
arp -da
route change default 10.111.71.194

執行 sh gate.sh


2.兩張網卡 && 需NAT

    ┌─ATUR→Internet
||||||||HUB||||||||
    ↑fxp0
    ├FreeBSD
    ↓fxp1
||||||||HUB||||||||
 │  
 ┴
其它電腦(用private IP && gateway 設 172.16.1.254)

#-----------------------------------------------nat.sh
ifconfig fxp0 10.111.71.193 netmask 255.255.255.252
ifconfig fxp1 163.17.181.254 netmask 255.255.255.0 aliase
arp -da
route change default 10.111.71.194
#------For Nat
natd -f /etc/natd.conf
ipfw add divert natd all from any to any

#--------------------------------------------------/etc/natd.conf
interface fxp0
redirect_address 172.16.1.2 163.17.181.2
redirect_address 172.16.1.3 163.17.181.3
redirect_address 172.16.1.4 163.17.181.5

執行 sh nat.sh

ps. 172.16.1.2-4 是需 1 對 1 NAT(static mapping) 的網路主機




3.一張網卡 && 不需NAT 時

    ┌─ATUR→Internet
||||||||HUB||||||||
 │  └fxp0 FreeBSD
 ┴
其它電腦(用public IP && gateway 設 163.17.181.254)


#-----------------------------------------------gate.sh
ifconfig fxp0 delete
ifconfig fxp0 10.111.71.193 netmask 255.255.255.252
ifconfig fxp0 163.17.181.254 netmask 255.255.255.0 aliase
arp -da
route change default 10.111.71.194
arp -S 10.111.71.193 0:8:c7:bf:c8:53
#------------------------------------------------
執行 sh gate.sh

ps.0:8:c7:bf:c8:53是 fxp0 的 MAC Address 用 ifconfig fxp0 可查到


4.一張網卡 && 需NAT

    ┌─ATUR→Internet
||||||||HUB||||||||
 │  └fxp0 FreeBSD
 ┴
其它電腦(用public IP && gateway 設 172.16.1.254)

#-----------------------------------------------nat.sh
ifconfig fxp0 delete
ifconfig fxp0 10.111.71.193 netmask 255.255.255.252
ifconfig fxp0 163.17.181.254 netmask 255.255.255.0 aliase
ifconfig fxp0 172.16.1.254 netmask 255.255.0.0 alias
arp -da
route change default 10.111.71.194
arp -S 10.111.71.193 0:8:c7:bf:c8:53
arp -S 172.16.1.254 0:8:c7:bf:c8:53
#------For Nat
natd -f /etc/natd.conf
ipfw add divert natd all from any to any

#--------------------------------------------------/etc/natd.conf
alias_address 163.17.181.254
redirect_address 172.16.1.2 163.17.181.2
redirect_address 172.16.1.3 163.17.181.3
redirect_address 172.16.1.4 163.17.181.5

執行 sh nat.sh

ps. 172.16.1.2-4 是需 1 對 1 NAT(static mapping) 的網路主機

 

 Re: 請教如何用Freebsd當交換器
發言人: 顏國雄 (---.lsps.tp.edu.tw)
發表日期:   05-22-01 01:54

Sorry!! 更正
方案4 的其它電腦應該是設 Private IP

 

 Re: 請教如何用Freebsd當交換器
發言人: 游志峰 (---.s32.ts32.hinet.net)
發表日期:   05-22-01 14:07

顏老師您好
我依照您的說明操作(一片網卡不做nat,執行gate.sh 時出現
10.111.71.193 (10.111.71.193) deleted
163.17.181.1 (163.17.181.1) deleted
163.17.181.2 (163.17.181.2) deleted
163.17.181.3 (163.17.181.3) deleted
163.17.181.24 (163.17.181.24) deleted
route: writing to routing socket: No such process
change net default: gateway 10.111.71.194: not in table
delete: can't locate 10.111.71.193

請教這是哪裡的問題呢?謝謝!

 

 Re: 請教如何用Freebsd當交換器
發言人: 游志峰 (---.s32.ts32.hinet.net)
發表日期:   05-22-01 14:34

我將route change 改為 routed change 後出現
10.111.71.193 (10.111.71.193) deleted
163.17.181.1 (163.17.181.1) deleted
163.17.181.2 (163.17.181.2) deleted
163.17.181.3 (163.17.181.3) deleted
163.17.181.24 (163.17.181.24) deleted
routed: usage: routed [-sqdghmpAtv] [-T tracefile] [-F net[,metric]] [-P parms]p
delete: can't locate 10.111.71.193

 

 Re: 請教如何用Freebsd當交換器
發言人: gsyan (---.moe.edu.tw)
發表日期:   05-22-01 15:25

Sorry!!
route change default 10.111.71.194 是用在 routing table 中己經有 default 時
新增應該是 route add default 10.111.71.194

另外 routed 和 route 是不同的指令
你可以 man route man routed 比較看看

ps.查 routing table 的方法: netstat -nr

 

 Re: 請教如何用Freebsd當交換器
發言人: yunfun (---.tcrc.edu.tw)
發表日期:   05-22-01 17:27

顏老師
成功了,太謝謝您啦!

 

 Re: 請教如何用Freebsd當交換器
發言人: Tim (---.bsdlab.idv.tw)
發表日期:   05-22-01 19:58
附加檔案:  dhcpd.conf

說也奇怪。
先敘明我的環境:
FreeBSD4.3-RELEASE、IP(211.75.215.107)--vr0、HUB * 1。
ATR-U、FreeBSD、Win98等,都接在HUB上。
以此設備,架設了NAT + DHCP ,很順利,NAT端的工作站都能自DHCP取得IP而上internet。
-------------------------
換一下環境:
插入第二塊網卡(vr1),ATU-R接vr0(211.75.215.107),vr1(192.168.1.254)及Win98接HUB上,NAT依然暢通。但是DHCP執行時,卻出現:
Listening on BPF/vr1/00:50:ba:cd:08:5e/192.168.1.0
Sending on BPF/vr1/00:50:ba:cd:08:5e/192.168.1.0
No subnet declaration for vr0 (211.75.215.107).
Please write a subnet declaration in your dhcpd.conf file for the
network segment to which interface vr0 is attached.
exiting.
--------------------------
我是希望DHCP作用在vr1上,卻卡在vr0。