Update get IP address method

This commit is contained in:
Teddysun 2015-07-14 10:01:39 +08:00
parent a6930479b9
commit a622d6beb1
3 changed files with 27 additions and 23 deletions

14
l2tp.sh
View File

@ -1,19 +1,19 @@
#!/bin/bash #!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH export PATH
#=============================================================================================== #===================================================================
# SYSTEM REQUIRED: CentOS 6 (32bit/64bit) # SYSTEM REQUIRED: CentOS 6 (32bit/64bit)
# DESCRIPTION: Auto install L2TP for CentOS 6 # DESCRIPTION: Auto install L2TP for CentOS 6
# Author: Teddysun <i@teddysun.com> # Author: Teddysun <i@teddysun.com>
#=============================================================================================== #===================================================================
if [[ "$USER" != 'root' ]]; then if [[ $EUID -ne 0 ]]; then
echo "Sorry, you need to run this as root" echo "Error:This script must be run as root!"
exit 1 exit 1
fi fi
if [[ ! -e /dev/net/tun ]]; then if [[ ! -e /dev/net/tun ]]; then
echo "TUN/TAP is not available" echo "TUN/TAP is not available!"
exit 1 exit 1
fi fi
@ -27,9 +27,9 @@ echo "# Author: Teddysun <i@teddysun.com> #"
echo "#############################################################" echo "#############################################################"
echo "" echo ""
tmpip=`ifconfig |grep 'inet' | grep -Evi '(inet6|127.0.0.1)' | awk '{print $2}' | cut -d: -f2 | tail -1` tmpip=`ip addr | egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | egrep -v "^192\.168|^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-2]\.|^10\.|^127\.|^255\." | head -n 1`
if [[ "$tmpip" = "" ]]; then if [[ "$tmpip" = "" ]]; then
tmpip=$(curl -4 icanhazip.com) tmpip=`curl -s -4 icanhazip.com`
fi fi
echo "Please input IP-Range:" echo "Please input IP-Range:"

View File

@ -1,19 +1,19 @@
#!/bin/bash #!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH export PATH
#=============================================================================================== #===================================================================
# SYSTEM REQUIRED: Ubuntu (32bit/64bit) # SYSTEM REQUIRED: Ubuntu (32bit/64bit)
# DESCRIPTION: Auto install L2TP for Ubuntu # DESCRIPTION: Auto install L2TP for Ubuntu
# Author: Teddysun <i@teddysun.com> # Author: Teddysun <i@teddysun.com>
#=============================================================================================== #===================================================================
if [[ "$USER" != 'root' ]]; then if [[ $EUID -ne 0 ]]; then
echo "Sorry, you need to run this as root" echo "Error:This script must be run as root!"
exit 1 exit 1
fi fi
if [[ ! -e /dev/net/tun ]]; then if [[ ! -e /dev/net/tun ]]; then
echo "TUN/TAP is not available" echo "TUN/TAP is not available!"
exit 1 exit 1
fi fi
@ -27,21 +27,21 @@ echo "# Author: Teddysun <i@teddysun.com> #"
echo "#############################################################" echo "#############################################################"
echo "" echo ""
tmpip=`ifconfig |grep 'inet' | grep -Evi '(inet6|127.0.0.1)' | awk '{print $2}' | cut -d: -f2 | tail -1` tmpip=`ip addr | egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | egrep -v "^192\.168|^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-2]\.|^10\.|^127\.|^255\." | head -n 1`
if [[ "$tmpip" = "" ]]; then if [[ "$tmpip" = "" ]]; then
tmpip=$(curl -4 icanhazip.com) tmpip=`curl -s -4 icanhazip.com`
fi fi
echo "Please input IP-Range:" echo "Please input IP-Range:"
read -p "(Default Range: 10.1.2):" iprange read -p "(Default Range: 10.1.2):" iprange
if [ "$iprange" = "" ]; then if [ "$iprange" = "" ]; then
iprange="10.1.2" iprange="10.1.2"
fi fi
echo "Please input PSK:" echo "Please input PSK:"
read -p "(Default PSK: vpn):" mypsk read -p "(Default PSK: vpn):" mypsk
if [ "$mypsk" = "" ]; then if [ "$mypsk" = "" ]; then
mypsk="vpn" mypsk="vpn"
fi fi
clear clear

18
pptp.sh
View File

@ -7,13 +7,13 @@ export PATH
# Author: Teddysun <i@teddysun.com> # Author: Teddysun <i@teddysun.com>
#=================================================================== #===================================================================
if [[ "$USER" != 'root' ]]; then if [[ $EUID -ne 0 ]]; then
echo "Sorry, you need to run this as root" echo "Error:This script must be run as root!"
exit 1 exit 1
fi fi
if [[ ! -e /dev/net/tun ]]; then if [[ ! -e /dev/net/tun ]]; then
echo "TUN/TAP is not available" echo "TUN/TAP is not available!"
exit 1 exit 1
fi fi
@ -35,6 +35,7 @@ iptables --flush FORWARD
rm -f /etc/pptpd.conf rm -f /etc/pptpd.conf
rm -rf /etc/ppp rm -rf /etc/ppp
arch=`uname -m` arch=`uname -m`
IP=`ip addr | egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | egrep -v "^192\.168|^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-2]\.|^10\.|^127\.|^255\." | head -n 1`
# Download pptpd # Download pptpd
if [ -s pptpd-1.3.4-2.el6.$arch.rpm ]; then if [ -s pptpd-1.3.4-2.el6.$arch.rpm ]; then
@ -42,7 +43,7 @@ if [ -s pptpd-1.3.4-2.el6.$arch.rpm ]; then
else else
echo "pptpd-1.3.4-2.el6.$arch.rpm not found!!!download now......" echo "pptpd-1.3.4-2.el6.$arch.rpm not found!!!download now......"
if ! wget http://lamp.teddysun.com/files/pptpd-1.3.4-2.el6.$arch.rpm;then if ! wget http://lamp.teddysun.com/files/pptpd-1.3.4-2.el6.$arch.rpm;then
echo "Failed to download pptpd-1.3.4-2.el6.$arch.rpm,please download it to $cur_dir directory manually and rerun the install script." echo "Failed to download pptpd-1.3.4-2.el6.$arch.rpm,please download it to $cur_dir directory manually and retry."
exit 1 exit 1
fi fi
fi fi
@ -68,7 +69,7 @@ fi
echo "vpn pptpd ${pass} *" >> /etc/ppp/chap-secrets echo "vpn pptpd ${pass} *" >> /etc/ppp/chap-secrets
iptables -t nat -A POSTROUTING -s 192.168.8.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 -t nat -A POSTROUTING -s 192.168.8.0/24 -j SNAT --to-source ${IP}
iptables -A FORWARD -p tcp --syn -s 192.168.8.0/24 -j TCPMSS --set-mss 1356 iptables -A FORWARD -p tcp --syn -s 192.168.8.0/24 -j TCPMSS --set-mss 1356
service iptables save service iptables save
chkconfig --add pptpd chkconfig --add pptpd
@ -77,8 +78,11 @@ service iptables restart
service pptpd start service pptpd start
echo "" echo ""
echo "VPN service is installed, your VPN username is vpn, VPN password is ${pass}" echo "PPTP VPN service is installed."
echo "Welcome to visit: http://teddysun.com" echo "ServerIP:${IP}"
echo "Username:vpn"
echo "Password:${pass}"
echo "Welcome to visit: http://teddysun.com/134.html"
echo "" echo ""
exit 0 exit 0