Linux-Shell-VPN

技术分享
 1 #!/bin/bash
 2 
 3 function installVPN(){
 4     echo "begin to install VPN services";
 5     #check wether vps suppot ppp and tun
 6     
 7     yum remove -y pptpd ppp
 8     iptables --flush POSTROUTING --table nat
 9     iptables --flush FORWARD
10     rm -rf /etc/pptpd.conf
11     rm -rf /etc/ppp
12     
13     arch=`uname -m`
14     
15     wget http://www.hi-vps.com/downloads/dkms-2.0.17.5-1.noarch.rpm
16     wget http://wty.name/linux/sources/kernel_ppp_mppe-1.0.2-3dkms.noarch.rpm
17     wget http://www.hi-vps.com/downloads/kernel_ppp_mppe-1.0.2-3dkms.noarch.rpm
18     wget http://www.hi-vps.com/downloads/pptpd-1.3.4-2.el6.$arch.rpm
19     wget http://www.hi-vps.com/downloads/ppp-2.4.5-17.0.rhel6.$arch.rpm
20 
21 
22     yum -y install make libpcap iptables gcc-c++ logrotate tar cpio perl pam tcp_wrappers
23     rpm -ivh dkms-2.0.17.5-1.noarch.rpm
24     rpm -ivh kernel_ppp_mppe-1.0.2-3dkms.noarch.rpm
25     rpm -qa kernel_ppp_mppe
26     rpm -Uvh ppp-2.4.5-17.0.rhel6.$arch.rpm    
27     rpm -ivh pptpd-1.3.4-2.el6.$arch.rpm
28 
29     mknod /dev/ppp c 108 0 
30     echo 1 > /proc/sys/net/ipv4/ip_forward 
31     echo "mknod /dev/ppp c 108 0" >> /etc/rc.local
32     echo "echo 1 > /proc/sys/net/ipv4/ip_forward" >> /etc/rc.local
33     echo "localip 172.16.36.1" >> /etc/pptpd.conf
34     echo "remoteip 172.16.36.2-254" >> /etc/pptpd.conf
35     echo "ms-dns 8.8.8.8" >> /etc/ppp/options.pptpd
36     echo "ms-dns 8.8.4.4" >> /etc/ppp/options.pptpd
37 
38     pass=`openssl rand 6 -base64`
39     if [ "$1" != "" ]
40     then pass=$1
41     fi
42 
43     echo "vpn pptpd ${pass} *" >> /etc/ppp/chap-secrets
44 
45     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}`
46     iptables -A FORWARD -p tcp --syn -s 172.16.36.0/24 -j TCPMSS --set-mss 1356
47     service iptables save
48 
49     chkconfig iptables on
50     chkconfig pptpd on
51 
52     service iptables start
53     service pptpd start
54 
55     echo "VPN service is installed, your VPN username is vpn, VPN password is ${pass}"
56     
57 }
58 
59 function repaireVPN(){
60     echo "begin to repaire VPN";
61     mknod /dev/ppp c 108 0
62     service iptables restart
63     service pptpd start
64 }
65 
66 function addVPNuser(){
67     echo "input user name:"
68     read username
69     echo "input password:"
70     read userpassword
71     echo "${username} pptpd ${userpassword} *" >> /etc/ppp/chap-secrets
72     service iptables restart
73     service pptpd start
74 }
75 
76 echo "which do you want to?input the number."
77 echo "1. install VPN service"
78 echo "2. repaire VPN service"
79 echo "3. add VPN user"
80 read num
81 
82 case "$num" in
83 [1] ) (installVPN);;
84 [2] ) (repaireVPN);;
85 [3] ) (addVPNuser);;
86 *) echo "nothing,exit";;
87 esac
VPN
sh vpn.sh

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。