OS: FreeBSD 9.1-release
參考資料:
1. http://lifestory.moqin.com/?p=346
2. http://www.twbsd.org/cht/book/ch18.htm
3. http://blog.weithenn.org/2009/05/freebsddhcp-ip-lan-user.html
VPN Server
對外 ip: 1.2.3.4
對內 ip: 192.168.0.1/24
本機 ip: 192.168.0.254
使用軟體:mpd5
1. 安裝方式:使用ports安裝mpd5(也有其他可以做VPN Server的軟體,但mpd5看起來最直覺簡單。)
root@test:/ # cd /usr/ports/net/mpd5
root@test:/usr/ports/net/mpd5 //安裝並於裝完後清除安裝檔。
........................
http://www.sourceforge.net/projects/mpd
===> Cleaning for mpd-5.6
2. 設定mpd5:
root@test:/usr/ports/net/mpd5 # cd /usr/local/etc/mpd5
root@test:/usr/local/etc/mpd5 # cp mpd.conf.sample mpd.conf
root@test:/usr/local/etc/mpd5 # cp mpd.secret.sample mpd.secret
root@test:/usr/local/etc/mpd5 # vi mpd.conf //設定mpd5
startup:
set console self 127.0.0.1 5005
set console open
set web self 0.0.0.0 5006
set web open
default:
load pptp_server
pptp_server:
# Define dynamic IP address pool.
set ippool add pool 192.168.0.190 192.168.0.195 //設定VPN連進來時使用的ip範圍,連進來的電腦會自動抓ip。
# Create clonable bundle template named VPN
create bundle template VPN
set iface disable on-demand
set iface enable proxy-arp
set iface idle 0
set iface enable tcpmssfix
set ipcp yes vjcomp
# Specify IP address pool for dynamic assigment.
set ipcp ranges 192.168.0.1/32 ippool pool //要注意名字需與前面的相同。
set ipcp dns 192.168.0.1 //內部使用的DNS Server
# The five lines below enable Microsoft Point-to-Point encryption
# (MPPE) using the ng_mppc(8) netgraph node type.
set bundle enable compression
set ccp yes mppc
set mppc yes e40
set mppc yes e128
set mppc yes stateless
# Create clonable link template named VPN
create link template VPNLINK pptp
# Set bundle template to use
set link action bundle VPN
# Multilink adds some overhead, but gives full 1500 MTU.
set link enable multilink
set link yes acfcomp protocomp
set link no pap chap eap
set link enable chap
# We can use use RADIUS authentication/accounting by including
# another config section with label 'radius'.
# load radius
set link keep-alive 30 300
# We reducing link mtu to avoid GRE packet fragmentation.
set link mtu 1460
# Configure PPTP
set pptp self 1.2.3.4 //VPN對外的正式IP,要連VPN,Server ip要打這個號碼唷!
# Allow to accept calls
set link enable incoming
存檔退出。
3. 設定連線進來的帳號和密碼:
root@test:/usr/local/etc/mpd5 # vi mpd.secret
id password //這行不用寫,只是表示檔案內部格式。
aaa 1234567
abc 3215687
mpd.secret: new file: 5 lines, 86 characters.
存檔退出。
4. 設定rc.conf,開機自動啟動:
#vi /etc/rc.conf
# ------ VPN Settings ----- #
mpd_flags="-b"
mpd_enable="Yes"
這樣開機就會自動啟動pptp格式的VPN了。
5. 啟動mpd:
root@test:/usr/local/etc/mpd5 # /usr/local/etc/rc.d/mpd5 start
Starting mpd5.
如果沒有設定rc.conf,要用# /usr/local/etc/rc.d/mpd5 onestart
啟動後就有VPN Server的功能了。
6. 以下是XP環境下如何連到VPN的設定:
請打開「網路芳鄰」的「內容」,會看到下面的畫面,請使用左上方的「建立一個新連線」。然後就如畫面說明般地往下設定。
公司名稱可以亂寫,VPN伺服器的ip就是上面VPN Server對外的正式ip。
設定完會多一個虛擬私人網路,就是VPN。
使用者名稱和密碼跟mpd.secret中的設定一樣唷。
按下連線就可以連線進入內部網路了。不用啟動DHCP,因為會自動使用mpd.conf中給定的ip範圍。