Skip to content

Instantly share code, notes, and snippets.

@gianrubio
Last active December 17, 2023 22:01
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gianrubio/dce37ee9b9c024937832d776597e2603 to your computer and use it in GitHub Desktop.
Save gianrubio/dce37ee9b9c024937832d776597e2603 to your computer and use it in GitHub Desktop.
Socks proxy to connect private hosts with circleci
machine:
services:
- docker
post:
- wget https://gist.githubusercontent.com/gianrubio/dce37ee9b9c024937832d776597e2603/raw/4cdb30e5075e8e6064ac48a258e05f518f8c88c0/circleci-tunnel.sh ~/ && chmod +x ~/circleci-tunnel.sh
- ~/circleci-tunnel.sh start:
background: true
#!/bin/bash -x
set -e
function tunnel_up(){
sudo apt-get install redsocks -y
ssh -o StrictHostKeyChecking=no -v user@cmyhost -22 -i ~/.ssh/my-private-key -D 9999 -nf "sleep 90000" &
echo 'base{log_debug = on; log_info = on; log = "file:/tmp/reddi.log";daemon = on; redirector = iptables;}redsocks { local_ip = 127.0.0.1; local_port = 12345; ip = 127.0.0.1;port = 9999; type = socks5; }' > ~/redsocks.conf
sudo redsocks -c ~/redsocks.conf &
sudo iptables -t nat -N REDSOCKS
sudo iptables -t nat -A REDSOCKS -p tcp -d 10.0.0.0/8 -j DNAT --to 127.0.0.1:12345
sudo iptables -t nat -A OUTPUT -d 10.0.0.0/8 -j REDSOCKS
sudo iptables -t nat -I PREROUTING 1 -d 10.0.0.0/8 -j REDSOCKS
}
if [ $1 == "start" ]; then
tunnel_up
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment