# Restarting socks proxy

## Massimo B.

A Restarting Socks Proxy

I try to create some restarting socks proxy that restarts when the link is lost like on network switches or suspend to ram. I wonder that there is no packaged solution yet.

The only thing working so far:

```
while true;do logger "Launching SOCKS...";ssh -N -D 8080 gw;done
```

Trying to put that into some script that can be run with autostart of the Window Manager fails even if backgrounded and disowned. It is killed after the script is finished due to STDIN binding. Trying -n for redirecting stdin from /dev/null results in an infinite loop restarting ssh as it quits after started. This is normal with -n but this way I can't check if it is alive.

```
#!/usr/bin/env bash

(

    while sleep 1; do

       logger "Launching SOCKS..."

       ssh -CNn -D 8080 gw

    done

) &

disown
```

More advanced checks for keeping ssh alive is done by autossh, but this doesn't work as documented:

```
# autossh -M 20000 -f -N -g -D 8080 gw
```

This quits right after launching ssh, so it does not check the connection status anymore. So I tried combinations of

```
# autossh -M 20000 -N -g -D 8080 gw &
```

or

```
# autossh -M 20000 -CNn -D 8080 gw &
```

This first of those is staying alive but cannot be put inside a script as well as it quits after script is finished. The second one is dying as well inside a script.

Looking around I only found few solutions for this like https://github.com/PHLAK/Soxy. But investigating the script, that AUTO_RECONNECT does only restart on triggering status like polling by a cron job.

Best solution would be an init script or some script connected to Networkmanger itself.

Doesn't some of the real socks proxies like net-proxy/dante provide a solution?

----------

