Tag Archives: Tunnel

Open SSH Tunnel for Specific Hosts

Hey guys,

you need to reach specific sites of your company from outside the companies network but don’t want to pipe all your traffic through a tunnel. Then you are right here. The below script lets you specify the hosts and ports that should be tunneled. Just enter the host to the array   IP_MAP  with the following syntax:

Although you must change the following variables to match your configuration

This script automatically backups the existing file /etc/hosts and creates a new one including existing as well as obligatory entries you need to use the tunnels conveniently. When ever the script exits, it will restore the original hosts file.

As prerequesite you need to have the bash in version 4 or later installed. You can do this on a Mac by using Homebrew or any other Packagemanager suitable.

Before running the script you need to make it executable by typing

After that you can run this script with

If you encounter any errors or have any tips please feel free to comment or send me an email.