Jump to content

How to run a bash script on startup - Pineapple Nano


stevancw

Recommended Posts

I really loved the last two episodes on creating a VPN. I have a Wifi Pineapple Nano and have setup a VPN server and can manually connect

. I used the forwarding 'foo' code in the video to get client forwarding working.

Now I wanted to make it so that the openvpn client and the forwarding script works on startup but I cannot seem to get it working. I've done some searching but cannot think of where to go from here. 

I've put this in /etc/init.d/

#!/bin/sh

# Start the openvpn service
openvpn client.ovpn

#Setup forwarding for clients
iptables -t nat -A POSTROUTING -s 172.16.42.0/24 -o tun0 -j MASQUERADE
iptables -A FORWARD -s 172.16.42.0/24 -o tun0 -j ACCEPT
iptables -A FORWARD -d 172.16.42.0/24 -m state --state ESTABLISHED,RELATED -i tun0 -j ACCEPT


 

And created a symlink to /etc/rc.d/

 

If I run the commands separately it all works however I cannot get it to run on boot.

Should they be run as two different processes? Is it because openvpn is running the second won't trigger.

Not sure if it's my lack of understanding of Unix/bash scripting or something else.

 

Thanks for your time guys.

Link to comment
Share on other sites

  • 1 year later...
On 7/2/2016 at 8:31 AM, stevancw said:

I really loved the last two episodes on creating a VPN. I have a Wifi Pineapple Nano and have setup a VPN server and can manually connect

. I used the forwarding 'foo' code in the video to get client forwarding working.

Now I wanted to make it so that the openvpn client and the forwarding script works on startup but I cannot seem to get it working. I've done some searching but cannot think of where to go from here. 

I've put this in /etc/init.d/


#!/bin/sh

# Start the openvpn service
openvpn client.ovpn

#Setup forwarding for clients
iptables -t nat -A POSTROUTING -s 172.16.42.0/24 -o tun0 -j MASQUERADE
iptables -A FORWARD -s 172.16.42.0/24 -o tun0 -j ACCEPT
iptables -A FORWARD -d 172.16.42.0/24 -m state --state ESTABLISHED,RELATED -i tun0 -j ACCEPT


 

And created a symlink to /etc/rc.d/

 

If I run the commands separately it all works however I cannot get it to run on boot.

Should they be run as two different processes? Is it because openvpn is running the second won't trigger.

Not sure if it's my lack of understanding of Unix/bash scripting or something else.

 

Thanks for your time guys.

Stev, did you find a resolution for this? I have the same problem and putting the commands in rc.local did not help. Did you finally accomplished the goal of booting the router and have the VPN running without having to run the commands yourself using the Y cable and leaving the SSH sessions alive?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...