︿
Top

1、前言

以下前言內容引用自 D-Link 技術新知

穿隧技術 (Tunneling):穿隧技術是為了將私有數據網路的資料在公眾數據網路上傳輸,所發展出來的一種資料包裝方式(Encapsulation),亦即在公眾網路上建立一條秘密通道。現在穿隧技術所使用的協定主要有:IPsec、PPTP 及 L2TP 等三種。


  • IPsec (IP Secruity):為第三層的穿隧技術,專門為 IP 所設計不但符合現有 IPv4 的環境,同時也是 IPv6 的標準,它也是 IEIF 所制定的業界標準,目前 IETF 從 1995 年起,陸續公佈許多網路安全之相關技術標準。這些標準統稱為 IPSec (IP Security),可參考 RFC 1825RFC 1826RFC 1827RFC 1828RFC 1829RFC 1851RFC 2085RFC 2104
  • PPTP(Point to Point Tunneling Protocol):定義了一個主從式的架構,主要是由 PNS (PPTP Network Server) 和 PAC (PPTP Access Concentrator) 組成的機制,乃是透過這個機制來支援 VPN 的功能。將 IP、IPX 或 NetBEUI 通訊協定封裝在 IP 封包中,並使用 TCP 方式來交換加密通道的維護訊息。
  • L2TP (Layer 2 Tunneling Protocol):結合 Layer-2 Forwarding (L2F) 和 PPTP 的協定由 IETF 所提出的一個資料連結層的加密通訊協定。
PPTP 與 L2TP 均為第二層的穿隧技術,適合具有 IP/IPX/AppleTalk 等多種協定的環境。IPsec、PPTP、L2TP 三者,最大的不同在於運用 IPsec 的技術,使用者可以同時使用 Internet 與 VPN 的多點傳輸功能 (包括 Internet/Intranet/Extranet/Remote Access...等),而 PPTP 及 L2TP 只能執行點對點 VPN 的功能,無法同時執行 Internet 的應用,使用時較不方便而在安全性方面,IPSec 會對整個傳輸資料做加密而 PPTP 及 L2TP 則是僅針對封包的再包 (Encapsulation) 並未對資料做加密處理,安全性相對較低。

驗證通訊協定
  • PAP (Password Authentication Protocol):當驗證方式採用 PAP 時,則用戶端要連結到遠端伺服器時所傳送的帳號及密碼是以 明文 傳送,也就是沒加密的因此只要有心人士在其封包傳送過程中抓取,則帳號密碼就被看得一清二楚啦。
  • CHAP (Chanllenge Handshake Authentication Protocol):當驗證方式採用 CHAP 時,則用戶端要連結到遠端伺服器時所傳送的密碼是以 MD5 加密 後才傳送。
  • MSCHAPv2 (Microsoft Chanllenge Handshake Authentication Protocol Version 2):當驗證方式採用 MSCHAPv2 時,採 雙向驗證 方式也就是遠端伺服器可以驗證用戶端身份,也可讓用戶端確認所連接的是正確的遠端伺服器。





文章目錄

1、前言
2、實作環境
3、安裝及設定
          步驟1.安裝 mpd 套件
          步驟2.修改 mpd 設定檔 (mpd.conf)
          步驟3.修改 mpd 連結設定檔 (mpd.links)
          步驟4.修改 mpd 密碼檔 (mpd.secret)
          步驟5.修改 rc.conf
          步驟6.啟動 mpd 服務
          步驟7.設定 Windows XP PPTP Client
4、架設 FreeRadius 進行帳號驗證
          步驟1.安裝 freeradius 套件
          步驟2.修改 freeradius 設定檔 (radiusd.conf)
          步驟3.修改認證設定檔 (users)
          步驟4.修改連接設定檔 (clients.conf)
          步驟5.更改 mpd.conf 驗證方式 (Radius 作驗證)
          步驟6.測試 Radius 能否進行驗證
          步驟7.修改rc.conf
          步驟8.啟動 radius 服務
5、參考
6、Me FAQ
          Q1.VPN Client 利用 PPTP 撥入後跟同網段的其它台電腦都不通?





2、實作環境

  • FreeBSD 6.4-RELEASE-p2
  • mpd-3.18_6
  • freeradius-1.0.2_1 (若使用 RADIUS 進行驗證才需要安裝)





3、安裝及設定

步驟 1. 安裝 mpd 套件

切換至 Ports Tree 路徑安裝 mpd 套件。
cd  /usr/ports/net/mpd      //切換到安裝路徑
make install clean          //安裝套件並清除暫存檔案




步驟 2. 修改 mpd 設定檔 (mpd.conf)

修改 mpd 設定檔 (mpd.conf) 內容如下。
vi /usr/local/etc/mpd/mpd.conf   //修改內容如下
 default:
        load pptp      //載入 pptp 設定
 pptp:                 //開啟 5 個 pptp 通道 pptp1 ~ pptp5
        load pptp1
        load pptp2
        load pptp3
        load pptp4
        load pptp5
### Server IP 為 Gateway IP (192.168.88.1)
### Client IP 為 VPN Client 屆時連通後發給的 IP (192.168.88.56 ~ 60)
 pptp1:      
        new -i ng0 pptp1 pptp1
        set ipcp ranges 192.168.88.1/32 192.168.88.56/32  
        load pptp_def
 pptp2:
        new -i ng1 pptp2 pptp2
        set ipcp ranges 192.168.88.1/32 192.168.88.57/32
        load pptp_def
 pptp3:
        new -i ng2 pptp3 pptp3
        set ipcp ranges 192.168.88.1/32 192.168.88.58/32
        load pptp_def
 pptp4:
        new -i ng3 pptp4 pptp4
        set ipcp ranges 192.168.88.1/32 192.168.88.59/32
        load pptp_def
 pptp5:
        new -i ng4 pptp5 pptp5
        set ipcp ranges 192.168.88.1/32 192.168.88.60/32
        load pptp_def
### 當 VPN Client 連結後所發給的相關資訊
 pptp_def:
        set iface disable on-demand
        set iface enable proxy-arp
        set iface idle 0
        set iface enable tcpmssfix
        set bundle enable multilink
        set link yes acfcomp protocomp
        set link no pap chap
        set link enable chap-msv2      //VPN Client 驗證方式
        set link keep-alive 10 60
        set link mtu 1460
        set ipcp yes vjcomp
        set ipcp dns 192.168.88.1      //指定 VPN Client 的 DNS IP
        set ipcp nbns 192.168.88.1     //指定 VPN Client 的 NetBIOS IP
        set bundle enable compression
        set ccp yes mppc
        set ccp yes mpp-e40
        set ccp yes mpp-e128           //加密方式
        set ccp yes mpp-stateless




步驟 3. 修改 mpd 連結設定檔 (mpd.links)

修改 mpd 連結設定檔 (mpd.links) 內容如下
vi /usr/local/etc/mpd/mpd.links    //修改內容如下
 pptp1:
        set link type pptp
        set pptp self 61.60.59.58   //要開放 VPN Client 連結的 Public IP
        set pptp enable incoming
        set pptp disable originate
 pptp2:
        set link type pptp
        set pptp self 61.60.59.58
        set pptp enable incoming
        set pptp disable originate
 pptp3:
        set link type pptp
        set pptp self 61.60.59.58
        set pptp enable incoming
        set pptp disable originate
 pptp4:
        set link type pptp
        set pptp self 61.60.59.58
        set pptp enable incoming
        set pptp disable originate
 pptp5:
        set link type pptp
        set pptp self 61.60.59.58
        set pptp enable incoming
        set pptp disable originate  




步驟 4. 修改 mpd 密碼檔 (mpd.secret)

修改 mpd 密碼檔 (mpd.secret) 內容如下,由於此密碼檔為 明碼 的文字檔案,因此設定完成後建議將檔案權限設定為 600。
/usr/local/etc/mpd/mpd.secret  //修改內容如下
 weithenn    "vpn123"              //設定 VPN 帳號及密碼
chmod 600 mpd.secret           //設定檔案權限




步驟 5. 修改 rc.conf

修改 /etc/rc.conf 檔以便系統重新開機時能自動啟動 mpd 服務。
vi /etc/rc.conf      //修改 rc.conf 內容如下
 gateway_enable="YES"   //啟動 Forwarding IP Packet (net.inet.ip.forwarding:1)
 mpd_flags="-b"         //加入此行,背景執行
 mpd_enable="YES"       //加入此行




步驟 6. 啟動 mpd 服務

鍵入如下指令啟動 mpd 服務。
/usr/local/etc/rc.d/mpd    start       //啟動
                                stop        //停止
                                restart     //重新啟動
                                rcvar       //顯示可加入至 rc.conf 的參數
                                status      //目前執行狀態

檢查 mpd 執行序是否執行
ps aux |grep mpd
 root    74827  0.0  0.1  2852  1728  ??  Ss   11:49上午   0:00.13 /usr/local/sbin/mpd -b

檢查 mpd 服務是否開啟對應 Port 1723 (可參考 /etc/service)
sockstat | grep mpd
 root     mpd        23468 15 tcp4   61.60.59.58:1723      *:*

啟動完成後因為上面的步驟 2 時我們開了 5 個 PPTP 通道,因此會產生那 5 個網卡來負責這個撥入的服務,如下所示:
ifconfig | grep ng
 ng0: flags=8890<POINTOPOINT,NOARP,SIMPLEX,MULTICAST> mtu 1500
 ng1: flags=8890<POINTOPOINT,NOARP,SIMPLEX,MULTICAST> mtu 1500
 ng2: flags=8890<POINTOPOINT,NOARP,SIMPLEX,MULTICAST> mtu 1500
 ng3: flags=8890<POINTOPOINT,NOARP,SIMPLEX,MULTICAST> mtu 1500
 ng4: flags=8890<POINTOPOINT,NOARP,SIMPLEX,MULTICAST> mtu 1500




步驟 7. 設定 Windows XP PPTP Client

上面步驟完成 VPN Server 設定後,接著設定 Windows XP PPTP Client 畫面如下,設定過程中只有一點必須注意,也就是 PPTP Client 撥入 VPN 後是否採用 VPN Server 所指定的 Gateway IP 來 取代  PPTP Client 本身的 Default Gateway,若您希望 PPTP Client 撥入 VPN 環境後仍維持本來的 Default Gateway 設定,則設定步驟如下:

  1. 點選【PPTP 連線 Icon】按下【右鍵】點選【內容】。
  2. 選擇【網路功能】頁籤 >> 點選【Internet Protocol (TCP/IP)】>> 按下【內容】。
  3. 按下【進階】>> 取消【使用遠端網路的預設閘道】勾選項目 >> 按下【確定】 即完成設定。





同一時間當 PPTP Client 服務撥入 VPN 環境成功後可看到目前是哪片 ng 網卡在處理這個 PPTP Client 的流量,如下可知目前是 ng0 在處理 PPTP Client (192.168.88.56) 的流量。
ifconfig | grep ng
 ng0: flags=88d1<UP,POINTOPOINT,RUNNING,NOARP,SIMPLEX,MULTICAST> mtu 1396
         inet 192.168.88.1 --> 192.168.88.56 netmask 0xffffffff
 ng1: flags=8890<POINTOPOINT,NOARP,SIMPLEX,MULTICAST> mtu 1500
 ng2: flags=8890<POINTOPOINT,NOARP,SIMPLEX,MULTICAST> mtu 1500
 ng3: flags=8890<POINTOPOINT,NOARP,SIMPLEX,MULTICAST> mtu 1500
 ng4: flags=8890<POINTOPOINT,NOARP,SIMPLEX,MULTICAST> mtu 1500






4、架設 FreeRadius 進行帳號驗證

按上面步驟來設定即可順利使用 mpd 來建立 PPTP 的 VPN 連線了,雖然 mpd 可利用 mpd.secret 來建立能 VPN Client 端的帳號及密碼,但系統中使用者已經有一百多個使用者 (/etc/master.passwd),若要一筆一筆建立可是個大工程 (重要是密碼的部份,使用者應該不想告知),因此本次實作為利用 FreeRADIUS 來驗證系統帳戶 (/etc/master.passwd) 取代原本的 mpd 帳戶驗證 (mpd.secret),本次實作為設定 VPN Client 的驗證方式必須改為 PAP 而不是原本的 MS-CHAPv2 因為 MS-CHAPv2 為雙向驗證加密會阻礙我們的流程 (此次實作為先測試成功,之後有空再測試 MS-CHAPv2 部份)。



步驟 1. 安裝 freeradius 套件

切換至 Ports Tree 路徑安裝 freeradius 套件
cd  /usr/ports/net/freeradius    //切換到安裝路徑
make install clean                //安裝套件並清除暫存檔案




步驟 2. 修改 freeradius 設定檔 (radiusd.conf)

修改 radiusd.con 設定檔,以下設定檔的內容僅留下必要的基本設定,若卻了解其他更進階的部份請參考 Main Page - FreeRADIUS Wiki
vi /usr/local/etc/raddb/radiusd.conf
 prefix = /usr/local
 exec_prefix = ${prefix}
 sysconfdir = ${prefix}/etc
 localstatedir = /var
 sbindir = ${exec_prefix}/sbin
 logdir = /var/log
 raddbdir = ${sysconfdir}/raddb
 radacctdir = ${logdir}/radacct
 confdir = ${raddbdir}
 run_dir = ${localstatedir}/run/radiusd
 log_file = ${logdir}/radius.log
 libdir = ${exec_prefix}/lib
 pidfile = ${run_dir}/radiusd.pid
 max_request_time = 30
 delete_blocked_requests = no
 cleanup_delay = 5
 max_requests = 1024
 bind_address = 61.60.59.58
 port = 1812
 hostname_lookups = no
 allow_core_dumps = yes
 regular_expressions     = yes
 extended_expressions    = yes
 log_stripped_names = no
 log_auth = no
 log_auth_badpass = yes
 log_auth_goodpass = yes
 usercollide = no
 lower_user = no
 lower_pass = no
 nospace_user = no
 nospace_pass = no
 checkrad = ${sbindir}/checkrad
# SECURITY CONFIGURATION
 security {
        max_attributes = 200
        reject_delay = 1
        status_server = no
 }
# CLIENTS CONFIGURATION
#
#  Client configuration is defined in "clients.conf".
#
 $INCLUDE  ${confdir}/clients.conf
# THREAD POOL CONFIGURATION
 thread pool {
        start_servers = 5
        max_servers = 32
        min_spare_servers = 3
        max_spare_servers = 10
        max_requests_per_server = 0
 }
# MODULE CONFIGURATION
 modules {
        # PAP module to authenticate users based on their stored password
        #
        #  Supports multiple encryption schemes
        #  clear: Clear text
        #  crypt: Unix crypt
        #    md5: MD5 ecnryption
        #   sha1: SHA1 encryption.
        #  DEFAULT: crypt
        pap {
                encryption_scheme = crypt
        }
        # Unix /etc/passwd style authentication
        unix {
                cache = no
                cache_reload = 600
                radwtmp = ${logdir}/radwtmp
        }
        # Livingston-style 'users' file
        #
        files {
                usersfile = ${confdir}/users
                compat = no
        }
        # Write a detailed log of all accounting records received.
        #
        detail {
                detailfile = ${radacctdir}/%{Client-IP-Address}/detail-%Y%m%d
                detailperm = 0600
        }
        #
        acct_unique {
                key = "User-Name, Acct-Session-Id, NAS-IP-Address, Client-IP-Address, NAS-Port"
        }
 }
#  Authorization. First preprocess (hints and huntgroups files),
#  then realms, and finally look in the "users" file.
#
#  The order of the realm modules will determine the order that
#  we try to find a matching realm.
#
#  Make *sure* that 'preprocess' comes before any realm if you
#  need to setup hints for the remote radius server
 authorize {
              files #  Read the 'users' file
 }
#  Authentication.
#
 authenticate {
        #
        #  PAP authentication, when a back-end database listed
        #  in the 'authorize' section supplies a password.  The
        #  password can be clear-text, or encrypted.
        Auth-Type PAP {
                pap
        }
        #  module checks the users password.  Note that packets
        #  containing CHAP-Password attributes CANNOT be authenticated
        #  against /etc/passwd!  See the FAQ for details.
        #
        unix
 }
#
#  Pre-accounting.  Decide which accounting type to use.
#
 preacct {
           acct_unique
 }
#
#  Accounting.  Log the accounting data.
#
 accounting {
              detail
 }




步驟 3. 修改認證設定檔 (users)

修改使用者認證方式為使用系統檔案 (/etc/master.passwd)。
vi /usr/local/etc/raddb/users   //設定認證方式
 DEFAULT Auth-Type := System         //指定系統檔案進行驗證
        Fall-Through = 1




步驟 4. 修改連接設定檔 (clients.conf)

修改連接設定檔 (clients.conf)。
vi /usr/local/etc/raddb/clients.conf   //內容如下
 client 61.60.59.58 {            //指定 VPN Server Hostname 或 Public IP
       secret          = test    //指定驗證密碼
       shortname       = gw      //指定驗證主機
 }




步驟 5. 更改 mpd.conf 驗證方式 (Radius 作驗證)

修改 mpd 設定檔 (mpd.conf) 將驗證方式由原本的檔案模式 (mpd.secret) 改為 RADIUS 進行驗證。
vi /usr/local/etc/mpd/mpd.conf   //修改內容如下
 pptp_def:
  set link enable chap-msv2  //預設值 (VPN Client 認證方式)
  set link enable pap        //修改後 (採 PAP 方式)
  set link accept chap       //Server 認證方式
  load radius                //載入支援 Radius 設定
 radius:                     //有關 Radius 的設定
  set radius retries 3
  set radius timeout 3
  set radius server 61.60.59.58 test1 1812 1813  //指定 VPN Server Public IP
  set radius acct-update 300
  set ipcp yes radius-ip
  set bundle enable radius-auth radius-fallback
  set bundle enable radius-acct




步驟 6. 測試 Radius 能否進行驗證

上述相關設定完成後,我們利用指令 radiusd -x 屆時 RADIUS 的執行情況,測試 VPN Client 能否透過 RAIDUS 進行驗證並且連上 VPN。
radiusd -x              //模擬 Radius 執行情況
 Starting - reading configuration files ...
 Module: Loaded PAP
 Module: Instantiated pap (pap)
 Module: Loaded System
 Module: Instantiated unix (unix)
 Module: Loaded files
 Module: Instantiated files (files)
 Module: Loaded Acct-Unique-Session-Id
 Module: Instantiated acct_unique (acct_unique)
 Module: Loaded detail
 Module: Instantiated detail (detail)
 Initializing the thread pool...
 Listening on authentication 61.60.59.58:1812
 Listening on accounting 61.60.59.58:1813
 Listening on proxy 61.60.59.58:1814
 Ready to process requests.

開啟另一個 Terminal 試試看輸入 /etc/master.passwd 中存在的使用者帳號密碼及 clients.conf 所設定的資訊 (剛才設定的 secret 及 shortname)。

  • 使用者帳號 (/etc/master.passwd):weithenn
  • 使用者密碼 (/etc/master.passwd):12345
  • 驗證密碼 (clients.conf 中 secret):test
  • 驗證主機 (clients.conf 中 shortname):gw
  • FreeRadius 驗證 Port:1812 (Listening on authentication)

輸入如下指令看能否透過 RADIUS 來進行使用者帳號及密碼的驗證
radtest weithenn 12345 gw 1812 test
 Sending Access-Request of id 21 to 61.60.59.58:1812
        User-Name = "weithenn"
        User-Password = "12345"
        NAS-IP-Address = gw.weithenn.org
        NAS-Port = 1812
 rad_recv: Access-Accept packet from host 61.60.59.58:1812, id=21, length=20      //驗證成功




步驟 7. 修改rc.conf

修改 /etc/rc.conf 檔以便系統重新開機時能自動啟動 Radius 服務。
vi /etc/rc.conf        //修改 rc.conf 內容如下
 radiusd_enable="YES"     //加入此行




步驟 8. 啟動 radius 服務

鍵入如下指令啟動 radius 服務。
/usr/local/etc/rc.d/radiusd.sh start     //啟動
                                    stop      //停止
                                    restart   //重新啟動
                                    rcvar     //顯示可加入至 rc.conf 的參數
                                    status    //目前執行狀態







5、參考






6、Me FAQ

Q1. VPN Client 利用 PPTP 撥入後跟同網段的其它台電腦都不通?

Error Message:
設定完成後 VPN Client 利用 PPTP 撥入後跟同網段的其它台電腦都不通,例如只能 ping 到設定的 VPN Gateway IP 而以但 ping 其它同網段的電腦都無法連通?

Answer:
因為設定的這台機器在 rc.conf 中沒有設定 Gateway Enable 也因此沒有啟動 Forwarding IP Packet 機制所造成的結果,請依如下步驟檢查:
vi /etc/rc.conf        //修改啟動設定檔
 gateway_enable="YES"   //檢查是否有此行 (若無此行請新增此行)

上述步驟是當系統重新開機時會啟動 Forwarding IP Packet 機制,若不想重新開機系統的話也可以先進行手動啟動 Forwarding IP Packet (0=disable, 1=enable)。
sysctl -a | grep forwarding     //查看目前 Forwarding IP Packet 設定值
 net.inet.ip.forwarding: 0
 net.inet.ip.fastforwarding: 0
 net.inet6.ip6.forwarding: 0
sysctl net.inet.ip.forwarding=1 //手動設定 Forwarding IP Packet 為 Enable
文章標籤: