Good day, Habr!
Recently, I have a need to provide Internet access to all users of the home network via OpenVPN. Initially, the ancient
IBM NetVista 6646-Q1G with Linux Centos 6 was used for these purposes.
He coped with this task well, but, as they say, there is no limit to perfection. I wanted to replace it with something more compact. Initially, the choice fell on the
Raspberry Pi Model B , but confused by the price of $ 50, because with the task that he had to perform, the current server successfully coped. I started exploring alternatives. And I found, as it seemed to me, the ideal solution - the router + firmware
DD-WRT , which contains the OpenVPN client. Then came the turn of the choice of the router. I stopped at
TP-Link WR841N . A
database search revealed that DD-WRT supports it.
')
Literally on the same day, the device was purchased and flashed. But here I was disappointed - in the web interface on the VPN tab there was no possibility to configure the OpenVPN client. The google helped to find the cause of this unfairness very quickly: “
OpenVPN is only available (except the Broadcom VPN build.) ”.
As they say the wisest, carefully read the
contract documentation.
Okay, so even more interesting. A quick search for alternative firmware led me to
OpenWRT . Its difference from DD-WRT is that it has an
opkg package
manager with a good repository and the ability to flexibly configure the system to fit your needs. In fact, this is a very lightweight version of linux.
In OpenWRT, OpenVPN could not be configured out of the box - the problem is the same as with DD-WRT. But, thanks to the architecture of this firmware, there was a hope that everything will turn out. Quite a lot of free space was found in tmpfs:
root@OpenWrt:~
As the name implies, the memory of the router is mounted in / tmp. A few minutes of googling led me to a
page with a solution to this issue.
Unfortunately, it didn’t work for me, since after installing the kmod-tun, liblzo and libopenssl packages in the root file system, there is critically little space left. Therefore, it was decided to slightly upgrade this manual. Here's what I got.
1. Connect to the router via ssh and execute the commands:
opkg update opkg install kmod-tun zlib liblzo mkdir /etc/openvpn touch /etc/init.d/openvpn chmod +x /etc/init.d/openvpn
2. Edit the init script:
vi /etc/init.d/openvpn
3. Copy the configuration file (in our case my.conf), certificates and key into the / etc / openvpn folder.
4. Run openvpn:
/etc/init.d/openvpn start
If everything went well, then if you run the ifconfig command, you will see a new tun or tap interface. Example:
tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 inet addr:10.8.0.54 PtP:10.8.0.53 Mask:255.255.255.255 UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1 RX packets:100558 errors:0 dropped:0 overruns:0 frame:0 TX packets:78362 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:85115045 (81.1 MiB) TX bytes:16184384 (15.4 MiB
If the connection is not established, you can try to find the error with the command:
logread -f
Next, you need to add a network interface and configure the firewall in order to allow client traffic through a VPN. This can be done using the web interface. Examples in the screenshots below:


This solution has been successfully tested and works on the TP-Link WR841N router; it is also suitable for other
devices supported by OpenWRT that have a ROM of 4 megabytes.