0

I have modified this script (changed ip addresses) to make my wifi hotspot run through my VPN connection but every time my internet connection changes towers, or changes from LTE to 3G and vice versa, or my vpn disconnects and reconnects, this script has to be run again or my tethering activity stops going through my vpn. I think if I make this script loop every 10 seconds my problem will be solved (Not ideal I know, but I am desperately noobish). Does anyone know what to add to the script to make it loop with a timer? Or any suggestions for a better way to accomplish what I am trying to do?

iptables -t filter -F FORWARD
iptables -t nat -F POSTROUTING
iptables -t filter -I FORWARD -j ACCEPT
iptables -t nat -I POSTROUTING -j MASQUERADE
ip rule add from 192.168.1.0/24 lookup 61
ip route add default dev tun0 scope link table 61
ip route add 192.168.1.0/24 dev wlan0 scope link table 61
ip route add broadcast 255.255.255.255 dev wlan0 scope link table 61
fweigl
  • 21,278
  • 20
  • 114
  • 205
JJenkx
  • 9
  • 2
  • You probably want to make sure your connection enforces VPN, rather than running this in a loop. Unless you don't care about leaking some of your traffic, at which point - why are you using VPN in the first place? – l0b0 Feb 28 '15 at 07:52
  • It isn't ideal, but my main goal is to mask my unauthorized wifi tethering. Worse case scenario is my phone getting disconnected for not paying extra for data I already pay for. It would be awesome if there were a way to code a data blocking feature when tun0 goes down but I am clueless in scripting. – JJenkx Apr 28 '15 at 05:22

1 Answers1

0
#!/bin/bash

while sleep 10; do
    ... your commands here ...
done
rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • That seems like breaking security according to OP. – l0b0 Feb 28 '15 at 07:53
  • 1
    While this may be a very insecure way to keep a vpn up, this is exactly what the OP asked for so the answer should not be downvoted. – ccarton Feb 28 '15 at 10:25