fix bug x1.

master
livejq 2 years ago
parent d42620801a
commit aee9f67970
  1. 65
      chntunnel/chntunnel.sh

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

Loading…
Cancel
Save