Ubuntu配置PPTP VPN Client

下载 PPTP 客户端

sudo apt-get install pptp-linux

VPN 配置

sudo pptpsetup --create office --server office.chenqiwei.com --username hello --password hello3456 --encrypt --start

配置成功后,用ifconfig查看,就有ppp0接口出现,表示添加成功,如图: Screen Shot 2016-07-12 at 下午4.10.08.png

开关PPTP

sudo pon office
sudo poff office

添加路由表

此时虽然已经连接上 vpn,但是如果要访问192.168.199.100内网的服务器,还是走不同。因为网络流量会默认走 default:

kavi@iZ94r2kcxvtZ:/var/www/platform$ ip route
default via 120.24.3.247 dev eth1
10.0.0.0/8 via 10.44.95.247 dev eth0
10.44.88.0/21 dev eth0  proto kernel  scope link  src 10.44.93.210
100.64.0.0/10 via 10.44.95.247 dev eth0
113.76.118.249 via 120.24.3.247 dev eth1  src 120.24.0.18
113.76.118.249 dev ppp0  proto kernel  scope link  src 192.168.199.101
113.76.125.229 via 120.24.3.247 dev eth1  src 120.24.0.18
120.24.0.0/22 dev eth1  proto kernel  scope link  src 120.24.0.18
172.16.0.0/12 via 10.44.95.247 dev eth0

192.168.199.100服务器加入路由表规则,如下:

sudo /sbin/ip route add 192.168.199.100 dev ppp0

再次打印路由表看下

kavi@iZ94r2kcxvtZ:/var/www/platform$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         120.24.3.247    0.0.0.0         UG    0      0        0 eth1
10.0.0.0        10.44.95.247    255.0.0.0       UG    0      0        0 eth0
10.44.88.0      0.0.0.0         255.255.248.0   U     0      0        0 eth0
100.64.0.0      10.44.95.247    255.192.0.0     UG    0      0        0 eth0
113.76.118.249  120.24.3.247    255.255.255.255 UGH   0      0        0 eth1
113.76.118.249  0.0.0.0         255.255.255.255 UH    0      0        0 ppp0
113.76.125.229  120.24.3.247    255.255.255.255 UGH   0      0        0 eth1
120.24.0.0      0.0.0.0         255.255.252.0   U     0      0        0 eth1
172.16.0.0      10.44.95.247    255.240.0.0     UG    0      0        0 eth0
192.168.199.100 0.0.0.0         255.255.255.255 UH    0      0        0 ppp0

最后一条表明已经添加成功,这时 ping 192.168.199.100,也能通了,表示成功。

删除路由表

sudo ip route del 113.76.125.229

参考

Ubuntu通过PPTP协议使用VPN

Jul 21st, 2016

Comments