chntunnel add l2tp for nat or else.

master
livejq 2 years ago
parent 53d671d28a
commit 536c5adc39
  1. 17
      chntunnel/chntunnel.sh

@ -42,6 +42,7 @@ Usage: chntunnel [OPTION...]
options:
-c, --collect genrate route files from apnic.
-g, --gre-tunnel create a gre tunnel.
-p, --l2tp-tunnel create a l2tp tunnel.
-w, --white-list whitelist mode, only manually.[TODO]
-f, --gfw-list gfwlist mode.
EOF
@ -91,6 +92,13 @@ MY_INNER_IPADDR=$1
EOF
}
newL2tp() {
# yum install epel-release NetworkManager-l2tp -y
# nmcli connection add type vpn con-name "l2tp0" ifname "*" vpn-type l2tp vpn.data "gateway=103.116.76.233 username=txecs password=txecs ipsec-enabled=yes ipsec-psk=88889999"
# nmcli connection up "l2tp0"
wget https://get.vpnsetup.net -O vpn.sh && sudo sh vpn.sh && rm -f vpn.sh
}
addRoutes() {
cat << EOF > /etc/rc.local
#!/bin/bash
@ -129,7 +137,8 @@ collecting() {
source /etc/os-release || source /usr/lib/os-release
[[ $ID = 'centos' ]] || error=1
[[ $error -eq 1 ]] && msg_err "Sorry! current system is not supported." && exit 1
[[ ! -f $RUNPATH || `find $RUNPATH -mtime +1` ]] && cp $C_DIR/$FILENAME $RUNPATH && chmod 755 $RUNPATH
[[ -f $RUNPATH ]] && rm -f $RUNPATH
cp $C_DIR/$FILENAME $RUNPATH && chmod 755 $RUNPATH
if [ $# != 0 ]; then
for param in {$1,$2,$3}
do
@ -169,6 +178,12 @@ if [ $# != 0 ]; then
ifup ${TUNNEL_NAME:-tun0}
ping -c 3 $PEER_INNER_IPADDR >/dev/null && result=$? && [[ $result -eq 0 ]] && msg_pass "Tunnel created successfully!" && exit 0
msg_err "Connection failed, please contact the administrator." && exit 1
elif [[ $param = '-p' || $param = '--l2tp-tunnel' ]]; then
peer=$(ip addr | grep ppp0 | grep inet | awk -F ' ' {'print $2'})
[[ -n $peer ]] && msg_err "This tunnel already exists, please do not create it again." && exit 1
newL2tp
MY_INNER_IPADDR=${peer%%/*}
ping -c 3 $MY_INNER_IPADDR >/dev/null && result=$? && [[ $result -eq 0 ]] && msg_pass "Tunnel created successfully!" && exit 0
elif [[ $param = '-f' || $param = '--gfw-list' ]]; then
peer=$(ip addr | grep peer | grep inet | awk -F ' ' {'print $4'})
PEER_INNER_IPADDR=${peer%%/*}

Loading…
Cancel
Save