DD-WRT A Linux based Firmware
With client software available for iOS, Android, Windows, Linux, OS X and most SOHO routers and NAS devices, OpenVPN has gained quite some popularity in the home/SOHO network domain. The problem is that most home/SOHO network devices have a not so decent CPU while OpenVPN, being crypto software, needs decent processing power in order to perform properly. I will keep this article simple and clean and not bother you with lots of details or irrelevant information. I will not elaborate on the problem of low-end CPU’s in this article. Basically I will provide you with a script to setup an OpenVPN client using the dd-wrt firmware. The reason for not providing a script for setting up OpenVPN on the tomato firmware is because I think that the GUI on the tomato provides enough options as such that reverting back to the command line is not needed.
##########################################################################
#
# I Know - dd-wrt is not that much user friendly.
#
# If you want an all GUI solution providing advanced options
# then I really advise you to use the tomato firmware instead.
#
# It looks funny that we are doing this in the /tmp partition
# but that is because only the /tmp and /jffs partitions are
# writable.
# One more thing, just realize that your Linksys or whatever
# comsumer network device you might be using might not have
# the adequate processing power to drive OpenVPN decently.
# For instance, on a Linksys E1200 I get like 6 Mbit/s down.
# With a faster client device on the same line, same config
# and same server, I get about 80 Mbit/s down.
# So the advice here is; don't waste your time trying to figure out
# how to get faster download speeds if you have a low-end network
# client device.
#
##########################################################################
OPVPNENABLE=`nvram get openvpncl_enable | awk '$1 == "0" {print $1}'`
if [ "$OPVPNENABLE" != 0 ]; then
nvram set openvpncl_enable=0
nvram commit
fi
sleep 10
mkdir /tmp/2u2
cat > /tmp/2u2/openvpn.conf << CLIENTCONF
client
dev tun
proto udp
sndbuf 393216
rcvbuf 393216
remote 11.11.111.111 1194
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
comp-lzo no
cipher BF-CBC
fast-io
tun-mtu 1500
mssfix 1460
verb 1
status vpn-status
CLIENTCONF
cat > /tmp/2u2/ca.crt << CACERT
-----BEGIN CERTIFICATE-----
MIIDKzCCAhOgAwIBAgIJAP+yPIj7vwFaMA0GCSqGSIb3DQEBCwUAMBMxETAPBgNV
BAMTCENoYW5nZU1lMB4XDTE1MTIyNzA1MDEyN1oXDTI1MTIyNDA1MDEyN1owEzER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x0+omMyyohF5CIsxwmT9g9nnKWYx5YbEqwoCxL1AE54Ao8hJAdf
RuXCQA7LcAPn84jMnT1xi0NvlIsqlOjNg92m8cSHXyjNTSnebbsb7TQjXCM1cuVa
8072+8zxJgFkXLgoUAwfEdSSqOYzoRnwjdWI335G1L4cT8/XAcV4737jQH8a225y
Mlt/9STg+82z/KpAvBzm1ATiQdpkRPcp8CdplNovZOf/+pUiy2BSfsAQgPCWVfBn
gcLAK3CaiwKBgEaZA25cL1wzZmslNCoy/ONPda45WfcVMkwnQw5EizqRRjtB9owM
6pVZuhmLI98OEBGn5iKf02pVVy8Ef3yypSY+MEFCZYXMtHKunAPEyfKpTwNSZ6aP
PNMckzGNcNJPvRFwDuCfFnEqNNDdajpJt+w2YbSpnKiRA8D4tSQ6FFc1AoGBALI/
8bs3FGM8erYsdm62nMNzgVuIeUyThqlUEtCMlEG3KJ/KjNSfxn+3ZoMnDb5Xfrtr
uw1pFJn1STXcW9r7l4dgat/TdZhe1pNZuZOtFqjd22KIP1yqY6+XXxutxDuzkVNe
TIVcmL9n5JUWwmXIumo00rFeLYEXJD/cM7lJoOlBAoGBAIQVRLTJ7bQbPFYU9ESJ
7v8RDP4CX9Ivkdti7Z8GYewrX3yKgN5Ibp+yB/WszDBLg/z8HlSBFkwGR0JtqiQl
+1EIP6c1mTTwGpgDehWBzrBAP7j9juZgm3/hQKPulXF/suf0UrXaark5p8bULTR2
fTnFcRmJ4ELDWhcvZNlLU8wT
-----END PRIVATE KEY-----
PRIVATEKEY
cat > /tmp/2u2/rc.openvpn << STARTUPSCRIPT
#!/bin/sh
while :
do
date >> /tmp/2u2/vpn.log
sleep 60
NOPROCS=\`ps w | grep openvpn | grep -v grep | wc -l\`
if [ \$NOPROCS -eq 0 ]
then
echo "openvpn not running, starting again" >> /tmp/2u2/vpn.log
openvpn --config openvpn.conf --daemon --route-up /tmp/2u2/route-up.sh --down /tmp/2u2.nu/route-down.sh
else
echo "openvpn running, going back to sleep" >> /tmp/2u2/vpn.log
fi
done
STARTUPSCRIPT
cat > /tmp/2u2/rc.firewall << FIREWALL
#!/bin/sh
iptables -I FORWARD -i br0 -o tun0 -j ACCEPT
iptables -I FORWARD -i tun0 -o br0 -j ACCEPT
iptables -I INPUT -i tun0 -j REJECT
FIREWALL
cat > /tmp/2u2/route-up.sh << ENABLENAT
#!/bin/sh
iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
ENABLENAT
cat > /tmp/2u2/route-down.sh << DISABLENAT
#!/bin/sh
iptables -t nat -D POSTROUTING -o tun0 -j MASQUERADE
DISABLENAT
chmod a+x /tmp/2u2/rc.openvpn
chmod a+x /tmp/2u2/rc.firewall
chmod a+x /tmp/2u2/route-up.sh
chmod a+x /tmp/2u2/route-down.sh
cd /tmp/2u2
sleep 5
ln -s -f /tmp/2u2/vpn.log /tmp/vpn.log
ln -s -f /tmp/2u2/vpn-status /tmp/vpn-status
sleep 2
/tmp/2u2/rc.firewall
sleep 5
/tmp/2u2/rc.openvpn &
exit 0
##########################################################################
# The End
##########################################################################
Comments
So what do you think? Did I miss something? Is any part unclear? Leave your comment below.