CentOS 6.5 Example of a VPN environment (Digitalocean host)

Source: Internet
Author: User
Tags flush centos vps iptables

Script

The code is as follows Copy Code

#!/bin/bash

function Installvpn () {
echo "Begin to install VPN services";
#check Wether VPS Suppot PPP and Tun

Yum Remove-y pptpd PPP
Iptables--flush postrouting--table NAT
Iptables--flush FORWARD
Rm-rf/etc/pptpd.conf
Rm-rf/etc/ppp

Arch= ' Uname-m '

wget http://www.hi-vps.com/downloads/dkms-2.0.17.5-1.noarch.rpm
wget http://wty.name/linux/sources/kernel_ppp_mppe-1.0.2-3dkms.noarch.rpm
wget http://www.hi-vps.com/downloads/kernel_ppp_mppe-1.0.2-3dkms.noarch.rpm
Wget http://www.hi-vps.com/downloads/pptpd-1.3.4-2.el6. $arch. rpm
Wget http://www.hi-vps.com/downloads/ppp-2.4.5-17.0.rhel6. $arch. rpm


Yum-y install make Libpcap iptables gcc-c++ logrotate tar cpio perl Pam Tcp_wrappers
RPM-IVH dkms-2.0.17.5-1.noarch.rpm
RPM-IVH kernel_ppp_mppe-1.0.2-3dkms.noarch.rpm
Rpm-qa Kernel_ppp_mppe
RPM-UVH ppp-2.4.5-17.0.rhel6. $arch. rpm
Rpm-ivh pptpd-1.3.4-2.el6. $arch. rpm

MKNOD/DEV/PPP C 108 0
Echo 1 >/proc/sys/net/ipv4/ip_forward
echo "MKNOD/DEV/PPP C 108 0" >>/etc/rc.local
echo "Echo 1 >/proc/sys/net/ipv4/ip_forward" >>/etc/rc.local
echo "Localip 172.16.36.1" >>/etc/pptpd.conf
echo "Remoteip 172.16.36.2-254" >>/etc/pptpd.conf
echo "Ms-dns 8.8.8.8" >>/etc/ppp/options.pptpd
echo "Ms-dns 8.8.4.4" >>/etc/ppp/options.pptpd

pass= ' OpenSSL rand 6-base64 '
If ["!="]
Then pass=$1
Fi

echo "VPN pptpd ${pass} *" >>/etc/ppp/chap-secrets

Iptables-t nat-a postrouting-s 172.16.36.0/24-j SNAT--to-source ' ifconfig | grep ' inet addr: ' | Grep-v ' 127.0.0.1 ' | Cut-d:-f2 | awk ' nr==1 {print $} '
Iptables-a forward-p TCP--syn-s 172.16.36.0/24-j TCPMSS--SET-MSS 1356
Service Iptables Save

Chkconfig iptables on
Chkconfig pptpd on

Service Iptables Start
Service PPTPD Start

echo "VPN service is installed, your VPN username are VPN, VPN password is ${pass}"

}

function Repairevpn () {
echo "Begin to Repaire VPN";
MKNOD/DEV/PPP C 108 0
Service Iptables Restart
Service PPTPD Start
}

function Addvpnuser () {
echo "Input user name:"
Read username
echo "Input password:"
Read UserPassword
echo "${username} pptpd ${userpassword} *" >>/etc/ppp/chap-secrets
Service Iptables Restart
Service PPTPD Start
}

echo "Which do you want to?input the number."
echo "1. Install VPN Service "
echo "2. Repaire VPN Service "
echo "3. Add VPN User "
Read num

Case "$num" in
[1]) (INSTALLVPN);;
[2]) (REPAIREVPN);;
[3]) (addvpnuser);;
*) echo "nothing,exit";;
Esac


But use Windows to connect VPN when prompted 800 error, found that the firewall does not open the corresponding port, the online tutorial does not mention this, to join in the firewall

The code is as follows Copy Code

-A rh-firewall-1-input-p tcp-m state–state new-m tcp–dport 1723-j ACCEPT

This sentence opens 1723 ports, simple to say script usage

After downloading the vpn.sh

The code is as follows Copy Code


#wget http://www.pztai.com/vpn.sh

#chmod a+x vpn.sh

#./vpn.sh

Which do you want to?input the number.
1. Install VPN Service--Installation
2. Repaire VPN Service--Repair
3. Add VPN User--Add new user

The code is as follows Copy Code

#iptables-A input-m State--state new-m tcp-p TCP--dport 1723-j ACCEPT

#service iptables Save

#service iptables Restart

Public places are not sure WiFi security, you can connect their own VPN, then go to the Internet.

Related Article

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.