Centos vpn server creation script

Source: Internet
Author: User
Tags flush centos vps iptables

#! /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 maid-254">/etc/pptpd. conf
Echo "ms-dns 8.8.8.8">/etc/ppp/options.ppt pd
Echo "ms-dns 8.8.4.4">/etc/ppp/options.ppt pd

Pass = 'openssl rand 6-base64'
If ["$1 "! = ""]
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 $1 }''
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 is 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? 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

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.