Example of using PPTP Client in CentOS6

Source: Internet
Author: User
Tags chmod sleep


The openwrt firmware needs to be compiled on the local virtual machine, and dependencies need to be continuously downloaded during the compilation process. Due to the existence of GFW, compilation may fail, so you need to compile the VM to connect to the VPN.

The virtual machine system is CentOS6. The connection to PPTP is used as an example.

First install the pptp client:

Yum install pptp-setup

Create a VPN connection:

Pptpsetup -- create myvpn -- server 123.456.789.123 -- username vpnuser -- password 123456 -- encrypt # This
Create a VPN connection named myvpn
If the error "FATAL: Module ppp_mppe not found." occurs, you must register the Module:

Modprobe ppp_mppe

Connect to VPN

Pppd call myvpn

Verify connection:

Ip a | grep ppp
If no information is available, the connection fails. For details, see/var/log/message troubleshooting.


After the connection is successful, if you want to access other clients of the VPN server, add the route:

Route add-net 192.168.0.0 netmask 255.255.255.0 dev ppp0 #192.168.0.0 is the intranet segment of the VPN server

If you want all traffic to pass through the VPN, add the route after the VPN connection is successful:

Ip route replace 123.456.789.123 via 192.168.1.1 dev eth0 src 192.168.1.188 #123.456.789.123 is the ip address of the VPN server, and 192.168.1.1 is the virtual machine Gateway (because the virtual machine uses bridging, it is also the ip address of my router).
Ip route replace default dev ppp0

After the VPN is disconnected, you also need to delete the route:

Ip route del 123.456.789.123 via 192.168.1.1 dev eth0 src 192.168.1.188
Ip route add default via 192.168.1.1

Ppp also provides a more convenient way to connect to and disconnect a VPN:

Cp/usr/share/doc/ppp-2.4.5/scripts/pon/usr/sbin/
Cp/usr/share/doc/ppp-2.4.5/scripts/poff/usr/sbin/
Chmod + x/usr/sbin/pon
Chmod + x/usr/sbin/poff
 
Pon myvpn # connect to VPN
Poff myvpn # disconnect the VPN
I have also written a script to integrate the VPN connection and disconnection. No route is required each time. You can modify the ip address as needed before use.

Vpnstart script:


#! /Bin/bash
/Usr/sbin/pon myvpn
Echo "OK! Change route now! "
Sleep 5
/Sbin/ip route replace 123.456.789.123 via 192.168.1.1 dev eth0 src 192.168.1.188
Ip route replace default dev ppp0
Echo "Successful! VPN is start! "

Vpnstop script:


#! /Bin/bash
/Usr/sbin/poff myvpn
Echo "Wait! Change route now! "
Sleep 5
/Sbin/ip route del 123.456.789.123 via 192.168.1.1 dev eth0 src 192.168.1.188
/Sbin/ip route add default via 192.168.1.1
Echo "Successful! VPN is stop! "

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.