以下是一份適用於 CentOS/RedHat 5、6、7 版本的 VPN 一鍵安裝腳本,可交互式選擇安裝 PPTPD 或 Vsftpd 服務。
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 -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
elif [ $ver == "el6" ];then
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
elif [ $ver == "el5" ];then
rpm -Uvh https://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
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
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
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,腳本就會自動完成安裝與設定。