歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> centos/redhat 安裝VPN腳本... 適用 5 6 7版本的系統

centos/redhat 安裝VPN腳本... 適用 5 6 7版本的系統

日期:2017/3/3 12:34:12   编辑:Linux技術
echo -n "Your System Version:"
cat /etc/redhat-release
echo -n "Kernel Version:"
uname -r
function menu() {
echo -e "\033[33m
1 Install PPTPD Server
2 Install Vsftpd Server
3 Exit Menu
\033[0m"
read -p "Please choose:" ch
if [ $ch == 1 ];then
        echo "You choose pptpd-Server"
        vpn
elif [ $ch == 2 ];then
        echo "You choose Vsftpd"
else
        exit
fi
}

function epel() {
cz=`rpm -qa | grep epel | wc -l`
if [ $cz == 0 ];then
ver=`uname -r | awk -F "." '{print $4}'`
        if [ $ver == "el7" ];then
                rpm -Uvhhttps://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm         elif [ $ver == "el6" ];then
                rpm -Uvhhttps://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm         elif [ $ver == "el5" ];then
                rpm -Uvhhttps://dl.fedoraproject.org/pub/epel/epel-release-latest-5.noarch.rpm         else
                echo "Your System Not Support This Scripts. Bye Bye!"
        fi
fi
}
function vpn() {
read -p "Are you sure install pptpd-server?: Y/n: " re
                if [ $re == 'y' -o $re == 'Y' ];then
                        echo "Start install ........"
                        epel
                        yum install ppp pptpd iptables -y
                        setvpn
                        exit
                else [ $re == 'n' -o $re == 'N' ]
                        clear
                        menu
                fi
}

function setvpn() {
sed -i 's/net.ipv4.tcp_syncookies = 1/#net.ipv4.tcp_syncookies = 1/g' /etc/sysctl.conf
state=`cat /proc/sys/net/ipv4/ip_forward`
        if [ $state == 0 ];then
                echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
                sysctl -w net.ipv4.ip_forward=1
        fi
mv /etc/pptpd.conf /etc/pptpd.conf.bak
echo "ppp /usr/sbin/pppd
option /etc/ppp/options.pptpd
#debug
# stimeout 10
#noipparam
logwtmp
#vrf test
#bcrelay eth1
connections 100
localip 192.168.8.1
remoteip 192.168.8.8-100" > /etc/pptpd.conf

mv /etc/ppp/options.pptpd /etc/ppp/options.pptpd.bak
echo "name pptpd
refuse-pap
refuse-chap
refuse-mschap
require-mschap-v2
require-mppe-128
ms-dns 8.8.8.8
ms-dns 8.8.4.4
proxyarp
#debug
#dump
lock
nobsdcomp
novj
novjccomp
nologfd" > /etc/ppp/options.pptpd

vpnusername="vpnuser"
vpnpassword="vpnmima2019"
echo $vpnusername "pptpd" $vpnpassword "*" >> /etc/ppp/chap-secrets
iptables -t nat -A POSTROUTING -s 192.168.8.0/24 -o eth1 -j MASQUERADE
iptables -A INPUT -p tcp --dport 1723 -j ACCEPT
iptables -A INPUT -p gre -j ACCEPT

osver=`uname -r | awk -F "." '{print $4}'`
if [ $osver == "el7" ];then
        systemctl enable pptpd.service
        systemctl restart pptpd.service
else
        chkconfig pptpd on
        service pptpd stop
        service pptpd start
fi

echo "Your VPN UserName:"$vpnusername
echo "Your VPN Password:"$vpnpassword
}

menu
復制代碼在系統裡面存為 vpn.sh 然後執行 sh vpn.sh 選擇1 選擇y 然後會自動安裝。
Copyright © Linux教程網 All Rights Reserved