linux中安裝VPN伺服器pptpd步驟教程

來源:互聯網
上載者:User

環境:

[root@vpn_server network-scripts]# cat /etc/redhat-release

CentOS release 6.6 (Final)

[root@vpn_server network-scripts]# uname -m

x86_64

 
準備:

c64

rpm -ivh http://mirrors.aliyun.com/epel/6/x86_64/epel-release-6-8.noarch.rpm

yum install yum-priorities -y

 
c32

rpm -ivh http://mirrors.aliyun.com/epel/6/i386/epel-release-6-8.noarch.rpm

yum install yum-priorities -y

 

加入 yum 源

rpm -Uvh http://poptop.sourceforge.net/yum/stable/rhel6/pptp-release-current.noarch.rpm
 

實驗拓撲:

OS IP Role
Linux eth0: 198.168.136.137 pptp_server(vpn_server)
win7   vpn_client
 

目標:

使用者(vpn_client)通過pptp(vpn_server),實現翻牆上網功能。

 

檢查伺服器是否有必要的支援.如果檢查結果沒有這些支援的話,是不能安裝pptp的,執行指令:

modprobe ppp-compress-18 && echo ok

這條執行執行後,顯示”ok”則表明通過.不過接下來還需要做另一個檢查,輸入指令:

cat /dev/net/tun

如果這條指令顯示結果為下面的文本,則表明通過:

cat: /dev/net/tun: File descriptor in bad state

上述兩條均通過,才能安裝pptp.否則就只能考慮openvpn,或者請你的服務商來解決這個問題

 

[root@vpn_server soft]# modprobe ppp-compress-18 && echo ok

ok

[root@vpn_server soft]# cat /dev/net/tun

cat: /dev/net/tun: File descriptor in bad state

 

Cent os 6.4核心版本在2.6.15以上,都預設整合了MPPE和PPP

 

1安裝ppp,pptpd和iptables(iptables可選).

預設情況下,完整的CentOS是帶有這兩個組件的,但是精簡版的系統可能沒有.我們輸入下面的命令來確認,如果沒有則進行安裝

yum install pptpd -y

 

2配置pptp.

首先我們要編輯/etc/pptpd.conf檔案

locapip”和”remoteip”這兩個配置項,將前面的”;”注釋符去掉,或者更改為你期望的IP段值.

localip表示伺服器的IP,

remoteip表示分配給用戶端的IP地址

 

[root@vpn_server soft]# echo “localip 198.168.136.137” >>/etc/pptpd.conf

[root@vpn_server soft]# echo “remoteip 172.16.1.10-15” >>/etc/pptpd.conf

[root@vpn_server soft]# tail -2 /etc/pptpd.conf

localip 198.168.136.137

remoteip 172.16.1.10-15

 

在編輯/etc/ppp/options.pptpd檔案,為VPN添加DNS:

 

[root@vpn_server soft]# echo “ms-dns 114.114.114.114” >>/etc/ppp/options.pptpd

[root@vpn_server soft]# echo “ms-dns 8.8.8.8” >>/etc/ppp/options.pptpd

[root@vpn_server soft]# tail -2 /etc/ppp/options.pptpd

ms-dns 8.8.8.8

ms-dns 114.114.114.114
 

設定pptp VPN帳號密碼.我們需要編輯/etc/ppp/chap-secrets

這個檔案:#vim /etc/ppp/chap-secrets在這個檔案裡面,按照”使用者名稱 pptpd 密碼 *”的形式編寫,一行一個帳號和密碼

比如添加使用者名稱為test,密碼為123456的使用者,則編輯如下內容:test pptpd 123456 *

 

[root@vpn_server soft]# echo “test pptpd 123456 *” >>/etc/ppp/chap-secrets

[root@vpn_server soft]# tail -1 /etc/ppp/chap-secrets

test pptpd 123456 *

 

修改核心設定,使其支援轉寄.編輯/etc/sysctl.conf檔案:

#vim /etc/sysctl.conf將”net.ipv4.ip_forward”改為1,變成下面的形式.net.ipv4.ip_forward=1

儲存退出,並執行下面的命令來生效它:

#sysctl -p

 

添加iptables轉寄規則.輸入下面的指令:

iptables -t nat -A POSTROUTING -s 172.16.1.0/24 -o eth0 -j MASQUERADE

iptables -A INPUT -i eth0 -p tcp –dport 1723 -j ACCEPT

iptables -A FORWARD -i ppp+ -o eth0 -j ACCEPT

iptables -A FORWARD -i eth0 -o ppp+ -j ACCEPT

iptables -A INPUT -i eth0 -p gre -j ACCEPT

iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT

需要注意的是,這個指令中的” 172.16.1.0 /24″是根據之前的設定檔中的”localip”網段來改變的

service iptables save

啟動pptpd

[root@vpn_server soft]# /etc/init.d/pptpd start

Starting pptpd:                                            [  OK  ]

[root@vpn_server soft]# netstat -lntp|grep pptpd

tcp        0      0 0.0.0.0:1723                0.0.0.0:*                   LISTEN      4129/pptpd

在vpn-client上操作

建立一個新的網路連接,略

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.