Today we will write the continuation of the instructions and establish a connection to the previously installed OpenVPN server from the router to OpenWRT.
The instructions. Implement OpenWRT on the router TL-WR1043ND to install OpenVPN We installed OpenWRT firmware and I promised to consider installing OpenVPN and Asterisk on this wifi router a little later, so we continue this instruction.
Update the repository by executing the command:
opkg update
Check which OpenVPN packages are available for installation by following the command:
opkg list | grep openvpn
System response:
collectd-mod-openvpn - 4.10.7-2 - OpenVPN traffic/compression input plugin openvpn - 2.2.2-2 - Open source VPN solution using SSL openvpn-devel-nossl - r5d4f5435a421299ed047485d8d99bdf9a0d22fd1-1 - Open source VPN solution using plaintext (no SSL) openvpn-devel-openssl - r5d4f5435a421299ed047485d8d99bdf9a0d22fd1-1 - Open source VPN solution using OpenSSL openvpn-easy-rsa - 2.2.2-2 - Simple shell scripts to manage a Certificate Authority
Install OpenVPN server by executing the command:
opkg install openvpn
The response of the server installation system:
Installing openvpn (2.2.2-2) to root... Downloading http://downloads.openwrt.org/attitude_adjustment/12.09/ar71xx/generic/packages/openvpn_2.2.2-2_ar71xx.ipk. Installing kmod-tun (3.3.8-1) to root... Downloading http://downloads.openwrt.org/attitude_adjustment/12.09/ar71xx/generic/packages/kmod-tun_3.3.8-1_ar71xx.ipk. Installing libopenssl (1.0.1g-1) to root... Downloading http://downloads.openwrt.org/attitude_adjustment/12.09/ar71xx/generic/packages/libopenssl_1.0.1g-1_ar71xx.ipk. Installing zlib (1.2.7-1) to root... Downloading http://downloads.openwrt.org/attitude_adjustment/12.09/ar71xx/generic/packages/zlib_1.2.7-1_ar71xx.ipk. Installing liblzo (2.06-1) to root... Downloading http://downloads.openwrt.org/attitude_adjustment/12.09/ar71xx/generic/packages/liblzo_2.06-1_ar71xx.ipk. Configuring kmod-tun. Configuring zlib. Configuring libopenssl. Configuring liblzo. Configuring openvpn.
Copy the keys from OpenVPN server installed according to the instructions above on our router with OpenWRT using Putty program instruction.
Unlock the keys and transfer the keys to the folder /etc/openvpn/ And then I did the command.
tar xvf office2.tgz mv office2/ /etc/openvpn/
Checking the contents of the folder. /etc/openvpn/ And then I did the command.
ls /etc/openvpn/
System response:
ca.crt office2.crt office2.key office2.ovpn
Check the configuration of the openvpn client connection to a remote OpenVPN server by replacing ip_openvpn_server 1194 with an external IP of the remote OpenVPN server and your server port:
vi /etc/openvpn/office2.ovpn remote ip_openvpn_server 1194 client dev tun0 proto udp resolv-retry infinite # this is necessary for DynDNS nobind persist-key persist-tun ca /etc/openvpn/ca.crt cert /etc/openvpn/office2.crt key /etc/openvpn/office2.key comp-lzo verb 4 mute 20 verb 3
Modify the file. /etc/config/openvpn
echo '
package openvpn
config openvpn custom_config
option enabled 1
option config /etc/openvpn/office2.ovpn
' > /etc/config/openvpnReboot OpenVPN server executes the command:
/etc/init.d/openvpn restart
Executing the command. ifconfig And see if the interface goes up. tun0If he gets up, he should show up. tun0:
tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:192.168.255.45 P-t-P:192.168.255.46 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Set up a firewall:
vi /etc/rc.local # Put your custom commands here that should be executed once # the system init finished. By default this file does nothing. # openvpn Server iptables -I FORWARD -i br-lan -o tun0 -j ACCEPT iptables -I FORWARD -i tun0 -o br-lan -j ACCEPT iptables -I INPUT -i tun0 -p tcp --dport 80 -j ACCEPT iptables -I INPUT -i tun0 -p tcp --dport 139 -j ACCEPT iptables -I INPUT -i tun0 -p tcp --dport 445 -j ACCEPT iptables -I INPUT -i tun0 -p udp --dport 137 -j ACCEPT iptables -I INPUT -i tun0 -p udp --dport 138 -j ACCEPT iptables -I INPUT -i tun0 -p tcp --dport 901 -j ACCEPT #iptables -I INPUT -i tun0 -p tcp --dport 9100 -j ACCEPT #printer iptables -I INPUT -i tun0 -p ICMP --icmp-type 8 -j ACCEPT iptables -I INPUT -i tun0 -p ICMP --icmp-type 11 -j ACCEPT iptables -t nat -A POSTROUTING -s 192.168.20.0/24 -o tun0 -j MASQUERADE exit 0
Or file. /etc/config/firewall We enter the data by executing the command:
echo '
#--- VPN ---#
config zone
option name 'vpn'
option input 'ACCEPT'
option forward 'ACCEPT'
option output 'ACCEPT'
option network 'vpn'
option family 'ipv4'
#--- VPN to LAN ---#
config forwarding
option dest 'lan'
option src 'vpn'
#--- LAN to VPN ---#
config forwarding
option dest 'vpn'
option src 'lan'
' >> /etc/config/firewall
File in. /etc/config/network We enter the data by executing the command:
echo '
config interface 'vpn'
option ifname 'tun0'
option defaultroute '0'
option peerdns '0'
option proto 'none'
' >> /etc/config/networkTo apply the changes, restart the router.
It happens that OpenVPN auto-starts after restarting the router does not occur, therefore we enter into a file. /etc/rc.local:
vi /etc/rc.local .. /etc/init.d/openvpn restart exit 0
Rebooting the router.
Check ping from the computer connected via wifi remote OpenVPN server:
ping 192.168.20.1 PING 192.168.20.1 (192.168.20.1): 56 data bytes 64 bytes from 192.168.20.1: seq=0 ttl=127 time=39.254 ms 64 bytes from 192.168.20.1: seq=1 ttl=127 time=49.465 ms 64 bytes from 192.168.20.1: seq=2 ttl=127 time=38.769 ms 64 bytes from 192.168.20.1: seq=3 ttl=127 time=37.797 ms
Today, we installed and configured the OpenVPN client connection to the OpenVPN server. A little later, we will consider installing Asterisk on this wifi router.
I was with you. Sergey Lazarenko
Let’s take a short break and watch a video about the social experiment:



comment