Last active
May 24, 2017 15:02
-
-
Save yangxuan8282/a8af31e1e879d9705e4b172fdd5f970c to your computer and use it in GitHub Desktop.
temporary fix [dog tunnel lite]( https://github.com/vzex/dog-tunnel/tree/udpVersion ) reconnect port in used issues, from this post: https://www.v2ex.com/t/362833
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# temporary fix [dog tunnel lite]( https://github.com/vzex/dog-tunnel/tree/udpVersion ) reconnect port in used issues | |
# before run this script you need to install `sudo`, `dog-tunnel lite` on server, and install `screen`, `sudo`, `dog-tunnel lite` on client | |
# | |
# you can download `dog-tunnel lite` binary file here ( the offcial prebuilt arm binary file not work for me ): | |
# [amd64]: wget https://raw.githubusercontent.com/yangxuan8282/docker-image/master/dog-tunnel/lite_v1.30/amd64/dog-tunnel | |
# [arm]: wget https://raw.githubusercontent.com/yangxuan8282/docker-image/master/dog-tunnel/lite_v1.30/arm/dog-tunnel | |
# the binary file was built in docker ( https://github.com/yangxuan8282/docker-image/blob/master/dog-tunnel ) | |
# the default installation path of `dog-tunnel lite` is `/usr/local/bin/` | |
# | |
# if you got `Permissions 0644 for '/home/pi/.ssh/id_rsa' are too open.` when ssh into your server, you can fix it by: `chmod 600 ~/.ssh/id_rsa` on client | |
# and before execuate script you have to edit the value in line 31-38 | |
# echo -n "Type your server ip and press [ENTER]:" | |
# read $SERVER_IP | |
# echo -n "Type your server ssh port and press [ENTER]:" | |
# read $SERVER_SSH_PORT | |
# echo -n "Type your server username and press [ENTER]:" | |
# read $SERVER_SSH_USER | |
# echo -n "Type your server user ssh key path(absolute path) and press [ENTER]:" | |
# read $SSH_KEY | |
# echo -n "Type your dog-tunnel port on server and press [ENTER]:" | |
# read $DTUNNEL_PORT | |
# echo -n "Type the port you want to forwarding on local host and press [ENTER]:" | |
# read $LOCAL_PORT | |
# echo -n "Type the remote port on server and press [ENTER]:" | |
# read $REMOTE_PORT | |
# echo -n "Type your xor and press [ENTER]:" | |
# read $XOR | |
#LOCAL_USER=who am i | awk '{print $1}' | |
SERVER_IP= | |
SERVER_SSH_PORT= | |
SERVER_SSH_USER= | |
SSH_KEY= | |
DTUNNEL_PORT= | |
LOCAL_PORT= | |
REMOTE_PORT= | |
XOR= | |
#server: | |
echo "[Unit] | |
Description=Dog tunnel for http | |
After=network.target | |
[Service] | |
ExecStart=/usr/local/bin/dog-tunnel -service :$DTUNNEL_PORT -v -xor $XOR | |
Restart=always | |
RestartSec=60 | |
[Install] | |
WantedBy=multi-user.target" | ssh -i $SSH_KEY $SERVER_SSH_USER@$SERVER_IP -p $SERVER_SSH_PORT "sudo tee /etc/systemd/system/dtunnel-server.service" | |
ssh -f -i $SSH_KEY $SERVER_SSH_USER@$SERVER_IP -p $SERVER_SSH_PORT "sudo systemctl daemon-reload" | |
ssh -f -i $SSH_KEY $SERVER_SSH_USER@$SERVER_IP -p $SERVER_SSH_PORT "sudo systemctl start dtunnel-server" | |
ssh -f -i $SSH_KEY $SERVER_SSH_USER@$SERVER_IP -p $SERVER_SSH_PORT "sudo systemctl enable dtunnel-server" | |
#client: | |
echo "[Unit] | |
Description=Dog tunnel for http | |
After=network.target | |
[Service] | |
ExecStart=/usr/local/bin/dtunnel-up.sh | |
ExecStop=/usr/local/bin/dtunnel-down.sh | |
Restart=always | |
RestartSec=60 | |
[Install] | |
WantedBy=multi-user.target" | sudo tee /etc/systemd/system/http-dtunnel.service | |
echo "#!/bin/bash | |
ssh -f -i $SSH_KEY $SERVER_SSH_USER@$SERVER_IP -p $SERVER_SSH_PORT "sudo systemctl restart dtunnel-server" | |
/usr/local/bin/dog-tunnel -service $SERVER_IP:$DTUNNEL_PORT -v -action 127.0.0.1:$LOCAL_PORT -encrypt -xor $XOR -local :$REMOTE_PORT -pipe 5 -r | |
" | sudo tee /usr/local/bin/dtunnel-up.sh | |
echo "#!/bin/bash | |
ssh -f -i $SSH_KEY $SERVER_SSH_USER@$SERVER_IP -p $SERVER_SSH_PORT "sudo systemctl stop dtunnel-server" | |
" | sudo tee /usr/local/bin/dtunnel-down.sh | |
sudo chmod +x /usr/local/bin/dtunnel-up.sh | |
sudo chmod +x /usr/local/bin/dtunnel-down.sh | |
sudo systemctl daemon-reload | |
sudo systemctl start http-dtunnel | |
sudo systemctl status http-dtunnel | |
sudo systemctl enable http-dtunnel | |
# if you still got connection issues, you can add a cron job to check if website is down, it will check your site with `cURL` every hour | |
# and will restart the `http-dtunnel-service` if your site is down | |
# run this command on client: `sudo crontab -e`, and append this line at the end of the file ( remove the # , and replace $URL with your own url ): | |
# 0 * * * * curl $URL -s -f -m 5 -o /dev/null || systemctl restart http-dtunnel |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment