From 42a8edfa0458d67832a8ef4c892f76403dc3a79c Mon Sep 17 00:00:00 2001 From: Faicker Mo Date: Wed, 15 May 2019 15:46:48 +0800 Subject: [PATCH] support Table option to disable route add --- README.md | 8 ++++++++ client.conf.tpl | 1 + server.conf.tpl | 1 + user.sh => wg.sh | 24 ++++++++++++++++++------ 4 files changed, 28 insertions(+), 6 deletions(-) rename user.sh => wg.sh (90%) diff --git a/README.md b/README.md index 0adfc52..60bb575 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,14 @@ Running as root. This will generate a client conf and qrcode in users directory which name is alice and add alice to the wg server config. +client will route all traffic to server. + +```bash +./user.sh -a alice -r +``` + +This will disable default route change. Route traffic Manually. + #### delete a user ```bash diff --git a/client.conf.tpl b/client.conf.tpl index f45c317..9495142 100644 --- a/client.conf.tpl +++ b/client.conf.tpl @@ -1,6 +1,7 @@ [Interface] Address = $_VPN_IP PrivateKey = $_PRIVATE_KEY +Table = $_TABLE [Peer] PublicKey = $_SERVER_PUBLIC_KEY diff --git a/server.conf.tpl b/server.conf.tpl index d31f6ec..2e4178f 100644 --- a/server.conf.tpl +++ b/server.conf.tpl @@ -2,3 +2,4 @@ Address = $_SERVER_IP ListenPort = $_SERVER_PORT PrivateKey = $_SERVER_PRIVATE_KEY +Table = off diff --git a/user.sh b/wg.sh similarity index 90% rename from user.sh rename to wg.sh index 31c2c5d..d675b7b 100755 --- a/user.sh +++ b/wg.sh @@ -71,17 +71,24 @@ add_user() { echo "no available ip" exit 1 fi + _TABLE=auto + if [[ ! -z "$route" ]]; then + _TABLE=off + fi eval "echo \"$(cat "${template_file}")\"" > $userdir/wg0.conf qrencode -o $userdir/$user.png < $userdir/wg0.conf # change wg config local ip=${_VPN_IP%/*}/32 + if [[ ! -z "$route" ]]; then + ip="0.0.0.0/0,::/0" + fi local public_key=`cat $userdir/publickey` wg set $interface peer $public_key allowed-ips $ip if [[ $? -ne 0 ]]; then - echo "wg set failed" - rm -rf $user - exit 1 + echo "wg set failed" + rm -rf $user + exit 1 fi echo "$user $_VPN_IP $public_key" >> ${SAVED_FILE} && echo "use $user is added. config dir is $userdir" @@ -115,8 +122,11 @@ generate_and_install_server_config_file() { # server config file eval "echo \"$(cat "${template_file}")\"" > $WG_TMP_CONF_FILE while read user vpn_ip public_key; do - ip=${vpn_ip%/*}/32 - cat >> $WG_TMP_CONF_FILE <> $WG_TMP_CONF_FILE <