Set up Linux PPTP Client from the Terminal

Ubuntu
回覆文章
yehlu
Site Admin
文章: 3244
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

Set up Linux PPTP Client from the Terminal

文章 yehlu »

https://www.jamescoyle.net/how-to/963-s ... e-terminal

Set up Linux PPTP Client from the Terminal
Tags : firewalliptablesLinuxPPTPVPN

Category : How-to

Get Social!
Linux penguinA Virtual Private Network, or VPN, allows the client computer to connect to a remote local network to use it’s resources such as printers and file shares. There are several types of VPN such as PPTP and LP2SEC with varying types of protection. PPTP is not the most secure type of VPN but its the easiest to set up.

PPTP has numerous security risks which means that the data you are transferring through your VPN can easily be unencrypted. L2TP/IPsec is becoming the standard VPN technology of choice. PPTP should not be used unless security of each end point and the data transferred is not required.

Take the quick VPN Poll to tell us what type of VPN you use.

This tutorial assumes you have a PPTP server already set up with the following details:

Hostname: pptp.jamescoyle.net
Username: pptpuser
Password: pptppassword
Open a Terminal and install the required PPTP client packages.

1

代碼: 選擇全部

apt-get install pptp-linux network-manager-pptp
Create a credentials file with the username and password of the PPTP server:

1

代碼: 選擇全部

vi /etc/ppp/chap-secrets
Add your entry using the below attributes

[USER] – user name to log in to the VPN server
[SERVER] – name of server to use, PPTP in our case.
[SECRET] – password of the above [USER].
[IP] – ip of the server, * means all IPs.
1
[USER] [SERVER] [SECRET] [IP]
Example:

1

代碼: 選擇全部

pptpuser    PPTP    pptppassword    *
Create a file which will be executed when the PPTP connection is started. This can contain additional commands to run when the connection is started such as adding new routes or firewall exceptions.

1
vi /etc/ppp/ip-up.d/route-traffic
The below examle script adds a route from the PPTP connection to any computers on the PPTP servers local network with IPs in the 10.0.0.0 or 192.0.0.0 ranges. This means that on the PPTP client, any machines on the above IP ranges will be accessible. This script may not be required for your environment and is simply used as an example. Note: a route should automatically be added to your VPN gateway.

1
2
3
4
5
6
#!/bin/bash
NET1="10.0.0.0/8"
NET2="192.0.0.0/8"
IFACE="ppp0"
route add -net ${NET1} dev ${IFACE}
route add -net ${NET2} dev ${IFACE}
Allow execution of the script:

1
chmod +x /etc/ppp/ip-up.d/route-traffic
Add the PPTP client connection pool and any additional settings which are required. The connection name, jamescoyle.net, can be changed to suite your connection.

1

代碼: 選擇全部

vi /etc/ppp/peers/jamescoyle.net
Add the details of the PPTP server. The below are the basic options required to connect to the server using mppe-128 encryption. Edit the below attributes to match your environment:

[USER] – user name to log in to the VPN server
[HOST] – host name or IP address of the PPTP server.
1
2
3
4
5
6

代碼: 選擇全部

pty "pptp [HOST] --nolaunchpppd"
name [USER]
remotename [HOST]
require-mppe-128
file /etc/ppp/options.pptp
ipparam jamescoyle.net
You must add rules to your firewall to allow connections to and from this interface as well as through your existing public interface to make the PPTP connection. The below rules open all traffic on the new pptp interface using iptables. You may need to change this once the connection has been tested to increase security.

1
2
iptables -A INPUT -i pptp -j ACCEPT
iptables -A OUTPUT -i pptp -j ACCEPT
Finally you will need to start your PPTP client connection. Use pon and poff to start and stop your PPTP client. Replace [CONNECTION] with the name you gave to the file in /etc/ppp/peers/.

1
2

代碼: 選擇全部

pon [CONNECTON]
poff [CONNECTION]
See my script on automatically detecting a disconnect and restarting the PPTP client connection.

Related Posts:
Linux PPTP Client Error: “pty option precludes specifying device name”
Script to Automatically Detect and Restart Linux PPTP Client
Setup Headless Dropbox Sync Client on Linux
Create a permanent virtual IP address in Linux
Mount a Windows/ Samba Share in Linux
Linux User Management Cheat Sheet
yehlu
Site Admin
文章: 3244
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

Re: Set up Linux PPTP Client from the Terminal

文章 yehlu »

http://jamyy.us.to/blog/2012/12/4278.html

在 Linux 命令列進行 PPTP VPN 連線
by Jamyy on 十二月.13, 2012, under Linux
環境:
PPTP VPN Server: Vigor2920, Remote Dial-in User 採用 PPTP 撥入

前置作業
Fedora / CentOS: # yum install pptp-setup
Ubuntu: 預設即有 pppd 與 pptpsetup 指令
建立 PPTP VPN 連線設定檔
# pptpsetup --create toVigor --server my.router.hostname.or_public_ip \
> --username myname --encrypt

# vi /etc/ppp/chap-secrets
#登入名稱 對應peers檔名 密碼 *
username toVigor mypassword *
# vi /etc/ppp/peers/toVigor
pty "pptp my.router.hostname.or_public_ip --nolaunchpppd"
name username
remotename toVigor
require-mppe-128
file /etc/ppp/options.pptp
建立 PPTP VPN 連線
# pppd call toVigor
中斷 PPTP VPN 連線
# pkill pppd
經由遠端 Gateway 上網
方式一: 寫在設定檔中, 每次連線均自動使用遠端 Gateway
# vi /etc/ppp/peers/toVigor
#於檔案底部加入
defaultroute
replacedefaultroute
方式二: 設置 Shell Script
# vi /etc/ppp/ip-up.d/route-traffic
1
#!/bin/bash
2

3
route del -net 0.0.0.0
4
route add -net 0.0.0.0 dev ppp0
# chmod +x /etc/ppp/ip-up.d/route-traffic
方式三: 連線後再手動設置
# route del -net 0.0.0.0
# route add -net 0.0.0.0 dev ppp0
不想透過遠端 Gateway 上網, 但仍要與遠端 LAN 聯繫的設置
# route add -net 192.168.1.0/24 dev ppp0
(假設遠端 network 為 192.168.1.0/24)
使用 PPTP VPN Server 提供的 DNS 設置
# echo 'usepeerdns' >> /etc/ppp/peers/toVigor
讓近端其他電腦透過本機 PPTP VPN 上網
# sysctl -w net.ipv4.ip_forward=1
# iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -o ppp0 -j MASQUERADE
(假設近端 network 為 10.0.0.0/24)
Ref: Linux configure point to point tunneling PPTP VPN client for Microsoft PPTP vpn server - nixCraft

(Visited 3,096 times, 13 visits today)

Related Posts
在 CentOS 6 架設 OpenVPN Server
網路監聽 vs. 反監聽
DKIM with Sendmail 設置備忘
在 Chrome OS 使用 OpenVPN 連線
SSH Chroot Jail 實作
回覆文章

回到「Ubuntu」