2010年7月20日 星期二

IPv6 Prefix delegation 不完整報告

IPv6的主要特色,就是地址多到不行...所以之前的IPv4的NAT,就不需要了,且之前的NAT對於雙向對等溝通(主動,從外部連到內部)不太方便,雖然有很多的解決辦法(STUN.或使用者透過設定NAT,允許某些應用程式的溝通),不過這些動作都代表需要多些運算能力來處理...如果使用IPv6就可以讓Router的工作減輕(地址太多了,每個人,甚至是裝置,都是真實的IP),也不用再實做STUN到應用程式裡...當然NAT對於安全性還是有幫助的...

IPv6的裝置,一般透過和Router的溝通(NDP),可以得到一個Prefix,再加上裝置的MAC位址,就可以得到一個連上Internet的網路位址
目前radvd,是linux這方面的實作

如果用戶端有一個Router,想要得到一個Prefix來分配給用戶端的裝置,可以透過DHCPv6來得到Prefix,然後分配給底下的裝置使用
我們選用Dibbler來練習

環境:
vmware-1.0.9
centos 4.8
設一張網卡接到Host-only

實做DHCPv6 Server:
首先實做DHCPv6 Server,下載dibbler-0.7.3-src.tar.gz, 解壓縮, make server client relay, make install

修改設定檔:
在/etc/dibbler底下有許多server或client的設定檔範例,我們拿server-prefix-delegation.conf來修改,並把檔名修改成server.conf


#
# Example server configuration file: Prefix Delegation
#
# Server is able to grant prefixes for clients, who ask for it.
# Prefixes can be assigned besides of or instead of addresses.
# It depends what client asks for.

# Logging level range: 1(Emergency)-8(Debug)
log-level 8

# Don't log full date
log-mode short

iface "eth0" {


# clients should renew every half an hour
T1 1800

# In case of troubles, after 45 minutes, ask any server
T2 2700

# Addresses should be prefered for an hour
prefered-lifetime 3600

# and should be valid for 2 hours
valid-lifetime 7200

class {
  pool 5000::/48
}

# the following lines instruct server to grant each client
# 1 or 2 prefixes (if you have uncommented second line with pd-pool or not).
# For example, client might get
# 2222:2222:2222:222:2222:993f:6485:0/112 and
# 1111:1111:1111:1111:1111::993f:6485:0/112
pd-class {
       pd-pool 2001:1234:5678::/48

       // uncomment following line to assign 2 prefixes for 2 different pools
// Note: each client will receive 1 prefix from each pool.
// pd-pool 1111:1111:1111:1111:1111::/80
       pd-length 64
       T1 11111
       T2 22222
   }

}


PS : prefix 2001:1234:5678::/48這是隨便給的,主要是為了測試用

啟動dibbler-server:
dibbler-server start

觀察dibbler-server:
dibbler-server status

停止dibbler-server:
dibbler-server stop

實做DHCPv6 Client:
vmware-1.0.9
centos 4.8
設一張網卡接到Host-only
再設另一張網卡接到NAT

修改設定檔:
參考client-prefix-delegation.conf,並修改,然後將檔名修改成client.conf(完全沒改)


#
# Example client configuration file: Prefix Delegation
#

# This is an example configuration file with prefix delegation
# enabled. To ask for prefixes, use 'pd' (or 'prefix-delegation') keyword.

log-mode short

# 7 = omit debug messages
log-level 7

iface "eth0" {
 ia
 pd

# it is also possible to define parameters for prefix delegation
# pd {
#    t1 1000
#    t2 2000
#}

}



啟動dibbler-client
dibbler-client start

觀察dibbler-client
dibbler-client status

停止dibbler-client
dibbler-client stop

radvd的設定:
從client啟動dibbler-client,有一個檔案會更新,/etc/dibbler/radvd.conf,這個檔案是radvd的設定檔,讓這個檔案,可以對其它的介面或接收prefix的介面來發出router advertisement

PS : 若有打開IPv6 routing, echo “1” > /proc/sys/net/ipv6/conf/all/forwarding,則會在其它的介面上(不包括接收prefix的介面)發出router advertisement,若沒有打開IPv6 routing,則會在同樣接收prefix的介面發出router advertisement

不過dibbler只是產生一個設定檔,啟動停止radvd還是要靠radvd daemon且若radvd.conf的設定檔有變動,好像也不會讓radvd重新reload設定檔

我有測試radvd-1.6.tar.gz,發現一個問題,就是dibbler產生的radvd.conf會有語法不合的情形...所以需要修改dibbler的source code
修改./Port-linux/lowlevel-options-linux.c,找到fprintf(f, "         AdvAutonomous false;\n");這一行
改成fprintf(f, "         AdvAutonomous on;\n");...然後重新編譯,安裝

PS: 我用win xp 做client,AdvAutonomous 一定要on,才能得到IPv6的位址,至於其他radvd.conf的參數,看情況加入

還有radvd source code安裝時, 解壓縮, ./configure --sysconfdir=/etc/dibbler, make, make install,configure下的參數,可以讓radvd去/etc/dibbler/radvd.conf找設定檔

結論:
dibbler + radvd,目前還不算是完整的解決方案,不過至少有雛形了...也許過陣子再來關心,看看有沒有高手來解決!!!

相關連結:
http://en.wikipedia.org/wiki/Radvd
http://en.wikipedia.org/wiki/Neighbor_Discovery_Protocol
NDP : RFC1970 -> RFC2461 -> RFC4861 . RFC5006 (RDNSS)

http://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol
http://en.wikipedia.org/wiki/DHCPv6
DHCPv6 : RFC3315 . RFC3319 . RFC3633 . RFC3646 . RFC3736 . RFC4242 . RFC5007

2010年7月12日 星期一

Linux PPTP 實作報告

PPTP(Point to Point Tunneling Protocol),是VPN(Virtual Private Network)的一種,這裡PPTP的設定(MPPE. MPPC MS-CHAPv2)主要是為了Windows環境所設置的(Windows的OS還是大部份人在使用),方便員工在外地存取公司網路資源,...其它像是L2TP或L2TP/IPSec之類的VPN也許有機會可以試試看...

環境:
VMware-server 1.0.10
Fedora Core 5(記得要把selinux關掉)
由於FC5的核心已經包括了MPPE&MPPC的module功能,且ppp-2.4.3-6.2.1的RPM也預設安裝,所以只剩下pptpd for Server,和pptp for client.

首先實做Server:
下載pptpd-1.3.4.tar.gz,./configure,./make,./make install

編輯/etc/pptpd.conf(這個是pptpd的預設設定檔,可以man pptpd.conf或man pptpd參考)
localip 192.168.1.1
remoteip 192.168.1.10-19
#這是告訴pppd,它的設定檔是這一個,否則會預設用/etc/ppp/options
option /etc/ppp/options.pptpd

編輯/etc/ppp/options.pptpd(pppd的設定檔,裡面的參數,可以man pppd參考)
#這裡name的定義可以對應到/etc/ppp/chap-secrets
name test
#Microsoft定義兩種handshake protocol,MS-CHAPv1 for win95,之後就用MS-CHAPv2,所以這裡用較新的
require-mschap-v2
#這是通道加密的方法,開啟這個,可以使用40bits或128bits的加密方式,(參考Microsoft的加密等級)
require-mppe
ms-dns 192.168.1.1
ms-wins 192.168.1.1
 
編輯/etc/ppp/chap-secrets
“user_name”    “pptpd_hostname”    “password”    “allow-source-ip”
第二欄可以關聯/etc/ppp/options.pptpd的name的設定,所以這裡設定為test,也可以設定”*”,代表wildcard
第四欄設為”*”,可以不限制pptp client的來源ip

啟動pptpd
pptpd
#可以cat /var/log/messages,查看運作情形,如果有client連結成功,可以透過ifconifg可以看到ppp的介面

關閉pptpd
ps -e | grep pptpd #找出pptpd的process_id
kill process_id

利用windows client來連上
應該不困難,忽略...

Routing for Server:
當然不是clinet連得上來就好,封包還要能路由到用戶希望到的機器,所以第一步就是打開linux的路由功能
echo 1 > /proc/sys/net/ipv4/ip_forward
然後就是設定適當的路由,還有加入防火牆,保險一些...PPTP使用TCP port 1723

參考連結:
http://ericbbs.blogspot.com/2007/10/vpn-pptp.html
http://cha.homeip.net/blog/archives/2006/10/pptp_vpn.html
http://www.phparchitecture.com/howto_show.php?id=3&showall
http://en.wikipedia.org/wiki/Microsoft_Point-to-Point_Encryption
http://en.wikipedia.org/wiki/MS-CHAP

然後實做client:
下載pptp-1.7.2.tar.gz,make,install
安裝後,除了執行檔,還會產生一個設定檔/etc/ppp/options.pptp,裡面有註解,其看起來像是為了連到Microsoft VPN所設定的...

編輯/etc/ppp/options

編輯/etc/ppp/peer/$TUNNEL
pty "pptp $SERVER --nolaunchpppd"
name $DOMAIN\\$USERNAME
#這裡remotename的定義可以對應到/etc/ppp/chap-secrets
remotename PPTP
#這是通道加密的方法,開啟這個,可以使用40bits或128bits的加密方式,(參考Microsoft的加密等級)
require-mppe
file /etc/ppp/options.pptp
ipparam $IPPARAM

註解: $TUNNEL  所要呼叫的設定檔,裡面有server的位置,還有相關設定
        $SERVER  server的IP位置
        $DOMAIN   還不了解...可以省略
        $USERNAME  帳號的名稱,需對應/etc/ppp/chap-secrets內的某一列的”user_name”
        $IPPARAM 這個參數,會變成ip-up script的第六個輸入參數,我們可以在ip-up.local建立自己的script,並且使用它

編輯/etc/ppp/chap-secrets
“user_name”    “pptpd_hostname”    “password”    “allow-source-ip”
第二欄可以關聯/etc/ppp/options.pptpd的name的設定,所以這裡設定為PPTP,也可設定”*”,代表wildcard
第四欄設為”*”,應該代表不限制pptp server的目的ip

啟動pptp-client
pppd call $TUNNEL
#可以cat /var/log/messages,查看運作情形, 如果成功連結到server,可以透過ifconifg可以看到ppp的介面

關閉pptp-client
ps -e | grep pppd #找出pppd的process_id
kill process_id

Routing table for Client:
對於client,當connection建立起來,會有一個host routing entry(就是另一端的IP位址),對於一些簡單的使用情境,像是從家裡連到公司網路,基本上還是需要手動設定routing table,才能使用公司的網路資源,而pppd的package(for FC5 or RedHat),有提供機制來自己寫script增加所需要的routing entry...
在/etc/ppp目錄下,可以看ip-up和ip-down及其他的script,例如只要加入ip-up.local檔案就可以寫自己的script...細節可以man pppd和看if-up的script內容....
這裡要記錄的是,其script的執行時,stdin.stdout and stderror都導到/dev/null,要注意
這樣就可以客製化自己的routing table

PS:一般的情形,都是default routing entry設成另一端VPN的IP位址,或是介面ppp0之類,總之,除了特別的設定,大部分的流量都希望經由VPN...所以pppd也提供一個選項defaultroute來做這樣的事,幫你增加default routing entry到介面ppp0...
所以我一開始很高興的用,不過不會增加...後來想一下,才知道原因
因為我們的pppd就是利用原來default routing entry才能連接到VPN server的,如果真的多增加default routing entry,就代表有兩個default routing entry,當然可以用metric來決定優先權,不過不管用哪一個,對於VPN的建立和流量的導向,都有一個是我們不希望的(因為routing table是所有程式共用的).....所以pppd不會多增加一個default routing entry(/var/log/messages有顯示),除非VPN的建立不是透過default routing entry,而是透過自己LAN上的一台VPN Server

參考連結:
http://pptpclient.sourceforge.net/howto-debian.phtml#configure_by_hand
http://ppc52776.blogspot.com/2008/12/linux-pptp-client-windows-vpn-server.html
http://www.cyberciti.biz/tips/howto-configure-ubuntu-fedora-linux-pptp-client.html