Openvpn server - how to install

Hi folks,
6 months ago I followed a guide that's now been removed from openwrt.
I'm running davidc502 luci for my linksys acs1900.

The new guide (basic setup) looks easy enough to do, but the question is:
can I copy and paste every section in putty? Or is it best to create a file/script file of some kind and import that? Or run every line, line by line?
For instance, chapter 3. Basic server.

Configure VPN server

| sed -e "s/^.*\///;s/\.\w*$//" \
| while read VPN_ID
do
VPN_CONF="/etc/openvpn/${VPN_ID}.conf"
VPN_CERT="$(openssl x509 -in "${EASYRSA_PKI}/issued/${VPN_ID}.crt")"
VPN_KEY="$(cat "${EASYRSA_PKI}/private/${VPN_ID}.key")"
cat << EOF > "${VPN_CONF}"
verb 3
user nobody
group nogroup
dev ${VPN_DEV}
port 1194
proto udp
server ${VPN_POOL}
topology subnet
client-to-client
keepalive 10 120
persist-tun
persist-key
push "dhcp-option DNS ${VPN_DNS}"
push "dhcp-option DOMAIN ${VPN_DOMAIN}"
push "redirect-gateway def1"
push "persist-tun"
push "persist-key"
<dh>${NL}${DH_KEY}${NL}</dh>
<tls-crypt>${NL}${TC_KEY}${NL}</tls-crypt>
<ca>${NL}${CA_CERT}${NL}</ca>
<cert>${NL}${VPN_CERT}${NL}</cert>
<key>${NL}${VPN_KEY}${NL}</key>
EOF
chmod "u=rw,g=,o=" "${VPN_CONF}"
done
service openvpn restart`

Line by line would be difficult due to all the sed commands.... EOF ( heredoc / key sections ) and VARIABLE usage....

You could try installing joe ( on the router over putty )

opkg update
opkg install joe

... it's really easy to use ( http://heather.cs.ucdavis.edu/~matloff/Joe/NotesJoe.NM.html ) .... and it may let you just paste a whole section the save. You only really need to know the help KEYS....

Type

#joe TO START it OR #joe script1.sh

The try pasting and saving. ( Use the net to find the HELP KEYS )

Then make the file executable;

chmod +x filename.sh

Then run it by using a ./ in the front.

./filename.sh

Thanks wulfy23, I will give it a shot. :slight_smile:

Is this how all other users also install/edit from putty?
I'm asking because I couldn't find any good explanation on how to install, but clearly all the commands are there..ready to be copied in :slight_smile:

Edit: Been a long time since i've used the basic editors... Yup, that's pretty much the main tools....

A remote session ( putty or ssh or whatever )
An editor ( nano, joe, vim, emacs )
The other one is straight copy.... winscp or similar can commands and copies two quite smoothly.....

I mean't to recommend nano...... it's easier.... ( sorry about the soundtrack :frowning: )

But, can I use notepad, copy all text to a file and save it as something.sh, and use winscp copy to tmp folder and then run it from there? Or does it need a compilation before doing so? If thats easier than using joe or nano?

Yes, save and copy is fine.

Copy it.... chmod +x ( make executable )

Then putty in, change directory and run.

The problem arises for most in that they are not aware that some editors save in various ENCODINGs. So lookup the net for tutorials about editing basic linux files and encoding if your using windows ( notepad++ ) was an editor I used to use alot.

OK what I did was copy two files (chapter 3 and chapter 4) to tmp/tmp/ on the router.
Did chmod +x /tmp/tmp/filenames.sh and the did ./tmp/tmp/filename.sh to run it.

First file (chapter 3) finished quite quickly, with only one error:
line 47: service: not found
which is: service openvpn restart

However,openvpn service exists.

Next I did chapter 4 and no error message came, but it says that a openvpnclient file is created:
/etc/openvpn/vpnclient.ovpn

Checking in the web gui, I can't find a openvpn instance called openvpn, is this ok?

Edit: testing on my iphone, and it looks like it's working.
I will have to add default gateway 1 or something to the config file, so I can send all traffic thru the vpnserver. I'll let you know

Ok, good job!

In script 3.... change

service openvpn restart

to

/etc/init.d/openvpn restart

Then run the above command once... ( manually in putty .... if you run the whole script again .... it may duplicate things )

In the GUI, unless you install luci-app-openvpn, you will only be able to find the service in SYSTEM > STARTUP

There you can click things like START - STOP - ENABLE - DISABLE

Great stuff :slight_smile: Thanks for your help! It's working nicely now, and no issue with iPhone either (I do remember there was some lz-compression issue or something).

I believe a tutorial for windows users would be appreciated on the openwrt pages tho :smiley:

Yes it's a process running under system - startup as you said, I didn't catch that it would be a service running there and not under the service - openvpn tab in the gui. Doesn't matter to me as long as it works :slight_smile:

1 Like

There are traps with this procedure, as DOS/ windows and UN*X use different line endings. Some applications may accept both, but in many cases it will fail (sometimes spectacularly, sometimes in mire subtle ways). Better editors allow you to choose the line ending style.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.