Jump to content
stevancw

How to run a bash script on startup - Pineapple Nano

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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...