歡迎您光臨本站 註冊首頁

SUSE筆記:在Linux下實現PPTP VPN拔號

←手機掃碼閱讀     火星人 @ 2014-03-29 , reply:0

1. PPTP VPN 客戶端軟體

我使用的PPTP客戶端軟體的名稱就叫作「PPTP Client」。
軟體的主頁是 http://pptpclient.sourceforge.net/

2、安裝

源代碼編譯安裝,這樣乾淨利索。

shell> tar pptp-1.7.1.tar.gz
shell> cd pptp-1.7.1
shell> more INSTALL
...
shell> make
shell> make install
shell> cp /usr/share/doc/packages/ppp/scripts/pon /usr/sbin
shell> cp /usr/share/doc/packages/ppp/scripts/poff /usr/sbin
shell> chmod +x /usr/sbin/pon /usr/sbin/poff

安裝前看看INSTALL和README是個好習慣。
pon和poff命令可在ppp源碼目錄下的scripts目錄中找到(find /usr/share -name pon)。


3、建立拔號連接

長話短說吧,我選擇在命令行下直接配置拔號連接,而沒有採用圖形工具配置。因為圖形配置工具需要單獨安裝,我們的基本目標是建立PPTP連接,而它並不是決定能否成功的關鍵因素。


環境描述:

PPTP-Server.IP: 202.202.202.202
Client.IP: 10.10.10.10/24
Client.Gateway: 10.10.10.1
Client.Hostname: dream

pptp.uid: jack
pptp.pwd: rose

pptp.dial-name: titanic



配置描述:

默認情況下,pptp client 1.7.1 安裝后的配置文件存放在 /etc/ppp 目錄中。


3.1 設置拔號使用的用戶名和口令

編輯/etc/ppp/chap-secrets或/etc/ppp/pap-secrets,加入以下內容
"jack" "titanic" "rose" *
"titanic" "jack" "rose" *

chap-secrets和pap-secrets分別在什麼情況下使用呢?
默認情況的PPTP認證都會使用ms-chap或ms-chap2,這時使用chap-secrets。
但如果PPTP VPN伺服器配置了radius等認證就會採用pap認證模式,這時使用pap-secrets。


3.2 創建拔號使用的連接文件(profile)

shell> touch /etc/ppp/peers/titanic
shell> vi /etc/ppp/peers/titanic
pty "pptp 202.202.202.202 --nolaunchpppd"
name jack
remotename titanic
file /etc/ppp/options.pptp
ipparam connect



4、拔號

需要以root身份執行

shell> /usr/sbin/pon titanic &
[1] 5065
dream:shell # Using interface ppp0
Connect: ppp0 <--> /dev/pts/2
CHAP authentication succeeded
local IP address 192.168.0.236
remote IP address 192.168.0.129
Script /etc/ppp/ip-up finished (pid 5078), status = 0x0

shell>

上面的提示信息基本表明PPTP拔號成功,根據提示信息檢查一下ppp0的狀態:

shell> ifconfig ppp0
ppp0 Link encap:Point-to-Point Protocol
inet addr:192.168.0.236 P-t-P:192.168.0.129 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:12 errors:0 dropped:0 overruns:0 frame:0
TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:199 (199.0 b) TX bytes:97 (97.0 b)

shell>

OK,PPTP拔號成功。



5、設置路由

a) 將pptp server的IP指向本地網關,以保證在路由發生變化時pptp連接不被中斷
shell> route add -host 202.202.202.202 gw 10.10.10.1

b) 刪除默認路由
shell> route del -net 0.0.0.0

c) 將默認路由指向pptp連接
shell> route add default ppp0


OK,現在可以盡情訪問網路了。



6、斷開拔號連接

shell> /usr/sbin/poff



7、小結

我沒有仔細介紹每條命令的含義,但相信只要按照上面步驟操作,可以成功地建立PPTP拔號連接。



8、一個拔pptp vpn的腳本,設計的初衷是為了滿足公司RSA動態口令認證密碼錄入的問題,很簡陋。
QUOTE:
#!/bin/sh

echo
echo "*************************************************************************"
echo "* usage: -f connection_file -u pptp_username -p pptp_password *"
echo "*************************************************************************"
echo

# get parameter
while getopts ":f:u:p:" opt; do
case $opt in
"f") conn_file="$OPTARG" ;;
"u") user_id="$OPTARG" ;;
"p") user_pwd="$OPTARG" ;;
esac
done

if [ -z "$EUID" -a -x /usr/bin/id ]; then
EUID=`id -u`
fi

if [ "$EUID" = "0" ]; then

secrets_file="/etc/ppp/pap-secrets"
pincode="********"
user_pwd="$pincode$user_pwd"

echo "# Secrets for authentication using PAP" > $secrets_file
echo "# client server secret IP addresses" >> $secrets_file
echo "\"$user_id\" \"$conn_file\" \"$user_pwd\" *" >> $secrets_file
echo "\"$conn_file\" \"$user_id\" \"$user_pwd\" *" >> $secrets_file

/sbin/ifconfig ppp0 > /dev/null 2>&1
if [ "$?" = "0" ]; then
echo "*** pptp is alreay established, now disconnect it ... ***"
echo
/sbin/ifconfig ppp0
/usr/sbin/poff -a
fi

echo
echo "*** Connecting $conn_file ... ***"
echo
/usr/sbin/pon $conn_file &
echo "."
/bin/sleep 1
echo ".."
/bin/sleep 1
echo "..."
/bin/sleep 1
echo "...."
/bin/sleep 1
echo "....."
/bin/sleep 1
/sbin/ifconfig ppp0 > /dev/null 2>&1
if [ "$?" = "0" ]; then
/sbin/ifconfig ppp0
echo
echo "*** PPTP VPN $conn_file is established! ***"
echo
exit 0
fi

else

echo "PPTP Client: Permission denied"
echo
exit 1

fi

【已有1位網友發表了看法】 【列印】 【關閉】

[火星人 ] SUSE筆記:在Linux下實現PPTP VPN拔號已經有590次圍觀

http://coctec.com/docs/linux/show-post-192726.html