For anyone doing remote lab work or demonstrations which include jump servers, this is your new best friend.
In MacOS, you can simply use brew
to install sshuttle
:
brew install sshuttle
Or on any other system, you can simply use python-pip3
:
pip3 install -U sshuttle
Add the following directory: mkdir -p $HOME/.sshuttle/pid/
Then add the following to your ~/.bashrc
or ~/.zshrc
file:
export REMOTE_TUN_IP="172.25.186.2"
export REMOTE_TUN_NETS="172.25.179.0/24 172.25.180.0/24 172.25.181.0/24"
export REMOTE_SESSION_NAME="sshuttle_session"
alias sshtup='sudo sshuttle --daemon --pidfile=$HOME/.sshuttle/pid/'"$REMOTE_SESSION_NAME"'.pid --dns -vr $USERNAME@'"$REMOTE_TUN_IP":22' '"$REMOTE_TUN_NETS"' && echo "Connected to $REMOTE_TUN_IP"'
alias sshtdown='[[ -f $HOME/.sshuttle/pid/'"$REMOTE_SESSION_NAME"'.pid ]] && sudo kill $(cat $HOME/.sshuttle/pid/'"$REMOTE_SESSION_NAME"'.pid) && echo "Disconnecting from $REMOTE_TUN_IP"'
Next, source your ~/.bashrc
or ~/.zshrc
file:
source ~/.bashrc
# or
source ~/.zshrc
Then type the following to connect to the remote host using sshuttle
(with networks and remote host DNS):
sshtup
To disconnect, type:
sshtdown
NOTE: Not required, but you could also configure your SSH config file with the following settings for quality of life improvements...
In your ~/.ssh/config
file, add the following:
Host *
ConnectTimeout 5
ControlMaster auto
ControlPath ~/.ssh/active-%r@%h.%p
ServerAliveCountMax 120
ServerAliveInterval 60
TCPKeepAlive no
ForwardX11Trusted yes
AddKeysToAgent yes
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null