diff --git a/chntunnel/chntunnel.sh b/chntunnel/chntunnel.sh index d470d09..c27e81a 100644 --- a/chntunnel/chntunnel.sh +++ b/chntunnel/chntunnel.sh @@ -80,34 +80,35 @@ cidr() { newGre() { cat << EOF > /etc/sysconfig/network-scripts/ifcfg-$4 - DEVICE=$4 - BOOTPROTO=none - ONBOOT=yes - DEVICETYPE=tunnel - TYPE=GRE - PEER_INNER_IPADDR=$2 - PEER_OUTER_IPADDR=$3 - MY_INNER_IPADDR=$1 +DEVICE=$4 +BOOTPROTO=none +ONBOOT=yes +DEVICETYPE=tunnel +TYPE=GRE +PEER_INNER_IPADDR=$2 +PEER_OUTER_IPADDR=$3 +MY_INNER_IPADDR=$1 EOF } addRoutes() { cat << EOF > /etc/rc.local - #!/bin/bash - # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES - # - # It is highly advisable to create own systemd services or udev rules - # to run scripts during boot instead of using this file. - # - # In contrast to previous versions due to parallel execution during boot - # this script will NOT be run after all other services. - # - # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure - # that this script will be executed during boot. - touch /var/lock/subsys/local - ip route flush table $1 - ip route add default via $2 dev $3 src $4 table $1 - ip rule add from $4 table $1 +#!/bin/bash +# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES +# +# It is highly advisable to create own systemd services or udev rules +# to run scripts during boot instead of using this file. +# +# In contrast to previous versions due to parallel execution during boot +# this script will NOT be run after all other services. +# +# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure +# that this script will be executed during boot. +touch /var/lock/subsys/local + +ip route flush table $1 +ip route add default via $2 dev $3 src $4 table $1 +ip rule add from $4 table $1 EOF } @@ -156,8 +157,8 @@ if [ $# != 0 ]; then # echo $IPADDR/$CIDR >> $GFWLIST || exit # done elif [[ $param = '-g' || $param = '--gre-tunnel' ]]; then - lsmod | grep ip_gre && result=$? && [[ $result != '0' ]] && modprobe ip_gre - lsmod | grep ip_gre && result=$? && [[ $result != '0' ]] && msg_err "The current system does not support GRE tunnel." && exit 1 + lsmod | grep ip_gre >/dev/null && result=$? && [[ $result != '0' ]] && modprobe ip_gre + lsmod | grep ip_gre >/dev/null && result=$? && [[ $result != '0' ]] && msg_err "The current system does not support GRE tunnel." && exit 1 msg "Prepare to establish a gre tunnel" read -rp "TUNNEL_NAME (default: tun0)" TUNNEL_NAME [[ -f "/etc/sysconfig/network-scripts/ifcfg-${TUNNEL_NAME:-tun0}" ]] && msg_err "This tunnel already exists, please do not create it again." && exit 1 @@ -166,8 +167,7 @@ if [ $# != 0 ]; then read -rp "PEER_OUTER_IPADDR: " PEER_OUTER_IPADDR newGre $MY_INNER_IPADDR $PEER_INNER_IPADDR $PEER_OUTER_IPADDR ${TUNNEL_NAME:-tun0} ifup ${TUNNEL_NAME:-tun0} - ping -c 3 $PEER_INNER_IPADDR && result=$? - [[ $result -eq 0 ]] && msg_pass "Tunnel created successfully!" && exit 0 + ping -c 3 $PEER_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%%/*} @@ -179,9 +179,10 @@ if [ $# != 0 ]; then done msg_pass "GFWlist is active, enjoy~" elif [[ $param = '-w' || $param = '--white-list' ]]; then + msg_err "TODO: not yet implemented, only manually." && exit 1 local_gw=$(ip route | grep default | awk -F ' ' {'print $3'}) - local_dev=$(ip route | grep src | awk -F ' ' {'print $3'}) - local_addr=$(ip route | grep src | awk -F ' ' {'print $9'}) + #local_dev=$(ip route | grep src | awk -F ' ' {'print $3'}) + #local_addr=$(ip route | grep src | awk -F ' ' {'print $9'}) local_table='cn' peer=$(ip addr | grep peer | grep inet | awk -F ' ' {'print $4'}) PEER_INNER_IPADDR=${peer%%/*} @@ -195,8 +196,8 @@ if [ $# != 0 ]; then ip route add $line via $local_gw echo "any net $line gw $local_gw" >>/etc/sysconfig/static-routes || exit done - ip route del default via $local_gw - ip route add default via $PEER_INNER_IPADDR + #ip route del default via $local_gw + #ip route add default via $PEER_INNER_IPADDR else help fi @@ -204,5 +205,3 @@ if [ $# != 0 ]; then else help fi -#TODO:白名单 -#TODO:设置DNS