IoT devices on the home network rely on the router to be accessible from the internet. It functions as a remote proxy and translates between HTTPS used on the internet and HTTP on the local area network.
Reverse proxy messages
Reverse proxy
Wildcard CNAME record
A CNAME record maps a domain name to another domain name. In this case the “other” domain name is the DDNS name of our router. By using a wildcard CNAME, such as *.home.domain.com, we can match requests for non-existent sub-domain domain names to home.domain.com. If we would open https://ir.home.domain.com in a browser, the DNS server will give the IP address of home.domain.com to the browser. The browser will then sent an HTTP request to that IP address requesting the page ir.home.domain.com.
Add the CNAME records to your DNS configuration
home.domain.com 3600 IN CNAME dyndns.com
*.home.domain.com 3600 IN CNAME dyndns.com
Remember to replace domain.com with your domain name, and dyndns.com with the dynamic DNS address of your router.
Access Router (pound)
The wildcard CNAME is only part of the equation. Since we configured home.domain.com to map to the IP address of the access router, this router will need to forward HTTP requests to the real IR device on our home network. We do this using a reverse proxy.
Reverse proxy
A reverse proxy uses the Host: field from the HTTP header, to determine where to forward the request to. This allows a server may use a single IP address or interface to accept requests for multiple DNS host names.
We choose the pound implementation because it seemed versatile. We installed pound on the /jffs partition, so that it will survive firmware updates. This guide is written for a Kong build of DD-WRT, but should work with any firmware that has access to lighttpd. You will need a JFFS partition and need to use command line tools via ssh/telnet.
To get up and running, we need the binaries, a script that starts it and configuration files. These files are available through this GitHub page. The scripts are based on Frater’s post.
Enable JFFS partition. From the router’s GUI, enable JFFS (Administration » Management). On first use, check the box to “clean internal flash storage”. Reboot as needed.
Pound binaries. Our router’s firmware didn’t include pound binaries, so we copied it from an older firmware (kongac’s r33010M)
Install startup script. Copy the script /jffs/sbin/pound.sh and its helper write_pound_cfg from GitHub.
Configure port to listen on. The file /jffs/etc/pound/pound.pt1 specifies what port to listen at. The example below uses port 81 since port 80 is already in use for the DD-WRT UI.
TimeOut 120
Alive 30
Control "/tmp/pound.ctl"
ListenHTTP
Address 0.0.0.0
Port 81
Configure forward rules. The file /jffs/etc/pound/pound.pt2 specifies where to forward the HTTP request to. In the example below, we do route both on URL and Host.
Service "ir-url" # route home.domain.com/ir to 10.0.1.234:80
Url "/ir.*"
BackEnd
Address 10.0.1.234
Port 80
End
End
Service "ir-host" # route ir.home.domain.com to 10.0.1.234:80
HeadRequire "Host:.ir.home.domain.com.*"
BackEnd
Address 10.0.1.234
Port 80
End
End
End
Start pound using /jffs/sbin/pound.sh start
Give it a spin by pointing a web browser to either
http://home.domain.com:81/ir
http://ir.home.domain.com:81/
Transport Layer Security
With a way to contact our IR device from the internet, let’s secure the connection using TLS with a free certificates from Let’s Encrypt by loosely following Neilpang’s instructions. We use a slightly modified acme.sh script that fixes a mistake in the regular expression [ticket968] and to avoid problems with binding to a non-existing IPV6 address, we added -4 to the call to openssl. The modified script can be found here.
Get CA certificates using opkg
mkdir /jffs/opt; mount --bind /jffs/opt /opt # mount /opt on /jffs/opt
( nvram get rc_startup; echo "mount --bind /jffs/opt /opt" ) \
> /tmp/a; nvram set rc_startup="$(cat /tmp/a); nvram commit"
bootstrap # install opkg (for CA-certificates)
opkg update; opkg install ca-certificates # install CA certificates
Make port 443 available. Disable the existing service on that port (Administration » Web Management » disable HTTPS for web access), and open port 443 on the firewall (Administration » Commands » Firewall » Edit; add the line “iptables -I INPUT 1 -p tcp -m state –state NEW -m tcp –dport 443 -j ACCEPT”).
Try to request a certificate. Remember to replace domain.com with your domain name.
If all goes well, remove the --test parameter and request the certificate for real.
Automatically renew the certificate, by setting up a cron job to update the certificate before it expires (Administration » Management » Additional Cron Jobs).
Create host.pem by Combine the SSL Private Key, the signed x.509 certificate, and all the certificates in the chain of trust in /jffs/etc/pound/host.pem so that pound can use them
This post shows how a $180 consumer class router can support two different networks. Besides the usual primary network, it will create a secondary network supporting both wireless and wired connections. The secondary network could be used to provide internet access to customers or visitors. The secondary network consists of a 2.4G and 5G radios and two LAN ports. If you only need one radio, you should read Ric’s article instead.
The router is assumed to be flashed with open source DD-Wrt firmware. This firmware adds some business class features to your router. The configuration will take advantage of two features that allow network traffic to be separated:
VLANs, allows wired LAN ports to be grouped and each group to be treated differently.
multiple SSIDs, allows multiple wireless network names (SSID) and security settings. The traffic over each SSID can be treated differently.
Before we start
The router is assumed to be running open source DD-Wrt firmware and configured for a single wired and wireless network. The router should also be configured for shell access (ssh) or telnet. Further, the reader should have a basic understanding of
the web based user interface (WebGUI)
networking concepts such as IP addresses, sub nets, routing, bridging and network interfaces. Some of the more specific terminology used in this article is:
A broadcast domain, is a network segment, in which all nodes can communicate directly by layer-2 broadcasts. Examples are a wired GigE network, or a wireless network.
A switch, handles frames at the data link layer (layer 2).
A router, handles packets at the network layer (layer 3). A router forms a boundary between broadcast domains.
A bridge, connects two or more network segments into a single broadcast domain (layer 2).
A virtual LAN(VLAN), creates distinct broadcast domains within one ore more physical networks. A VLAN is a switched network that is logically segmented by functions, project teams, or applications without regard to the physical location of users.
The configuration presented here has been tested on an Asus RT-AC68U router running DD-Wrt kongac build 23770M . For the Asus RT-N16 refer to my older article. The approach outlined might also apply to other routers or builds, albeit with minor changes.
Inside the router
To create a secondary network, we need to separate the four LAN ports and create an virtual wireless network. The following section builds a basic understanding of the default data paths in the router. The following section describes how the software configuration
Hardware block diagram
The Asus RT-AC68U router that is build around:
System-on-Chip BCM4708, provides the CPU, USB, WAN port and four LAN ports
Wireless NICBCM4360, provides the radio transceiver
This GigE routers has the port number assigned as illustrated below.
RT-AC58 block before
The block diagram above shows the data paths within the router. Note:
the LAN port numbers on the case may not correspond to the port numbers on the switch;
the WAN port connects to a special interface on the switch and can’t be reassigned;
port 5 connects the VLAN trunk from the switch to interface eth0 on the CPU.
The switch tags incoming frames with a VLAN identifier. Frames arriving on the WAN port are tagged as VLAN2, while frames from the LAN ports are tagged as VLAN1. The frames destined for the CPU are sent on CPU internal port 5.
The CPU receives the frames over port eth0. Frames with a VLAN2 tag are treated as WAN traffic. Frames with a VLAN1 tag are combined (bridged) with frames from the wireless module (eth1) and treated as LAN traffic.
Firmware mapping
The configuration for the DD-Wrt is stored in nonvolatile memory (nvram). The configuration can be shown as described in the DD-Wrt document Switched Ports. An excerpt:
The tagging configuration is stored in vlan#ports variables where ‘*’ symbolizes the default path. Note that the vlan0ports variable is unused on GigE routers. For the switch to move frames outside of any vlan, it needs to include port 5. This allows the SoC to route the packet. The vlan with the default is used for packets that do not have a vlan tag (see here). SSH/Telnet into the router and:
nvram show | grep vlan.*ports | sort
vlan1ports=1 2 3 4 5*
vlan2ports=0 5
An other important variable is port5vlans. It identifies every active VLAN plus the number 16 that indicates that tagging is enabled. The other variables appear only for the WebGUI.
nvram show | grep port.*vlan | sort
port0vlans=2
port1vlans=1
port2vlans=1
port3vlans=1
port4vlans=1
port5vlans=1 2 16
Every active VLAN needs to have its name set to et0.
nvram show | grep vlan.*hwname | sort
vlan1hwname=et0
vlan2hwname=et0
Creating to separate networks
To create a second network, we need to introduce an additional VLAN and an additional SSID for the wireless. The two can then be bridged together and given an unique subnet address. Before you start, I highly recommend making a backup of your current configuration.
RT-AC68 block after
Create a virtual wireless network (wl0.1, wl1.1)
Using a web browser, connect to the router and bring up the WebGUI.
We will use the shell (ssh) interface to configure the VLANs (because the GUI on Broadcom based routers have some related bugs). Login using SSH/Telnet, and run the following commands:
nvram set vlan3hwname=et0 # enable VLAN3
nvram set vlan1ports=’1 2 5*’ # assign LAN1/LAN2 to VLAN1
nvram set vlan2ports=’0 5u’ # assign WAN to VLAN2
nvram set vlan3ports=’3 4 5*’ # assign LAN3/LAN4 to VLAN3
nvram set port0vlans=2 # WAN is part of VLAN2
nvram set port1vlans=1 # LAN1 is part of VLAN1 (for GUI only)
nvram set port2vlans=1 # LAN2 is part of VLAN1 (for GUI only)
nvram set port3vlans=3 # LAN3 is part of VLAN3 (for GUI only)
nvram set port4vlans=3 # LAN4 is part of VLAN3 (for GUI only)
nvram set port5vlans=’1 2 3 16′ # CPU receives tagged VLAN1/VLAN2/VLAN3
nvram commit
reboot
Bridge vlan3 and wl0.1 (br1)
To make the new wired and wireless network to behave as one, we logically combine interfaces vlan3 and wl0.1 using a new bridge interface br1:
Bridge the vlan3, wl0.1 and wl1.1 interfaces together as br1
Setup » Networking » Bridging » Create Bridge
Click Add
enter br1 in the first field (optionally disable MSTP)
apply settings.
For br1 enter a
private IP address (e.g. 10.1.1.1), and
subnet mask (e.g. 255.255.255.0)
apply settings.
Setup » Networking » Bridging » Assign to bridge
Click Add twice. You should now have 3 assignment entries.
br1, interface vlan3 (LAN3 and LAN4)
br1, interface wl0.1 (the virtual 2.4G WiFi i/f)
br1, interface wl1.1 (the virtual 5G WiFi i/f)
Click Apply Settings
Verify that vlan3, wl0.1 and wl1.1 are set to default (we’ll enable NAT later on the bridge)
Setup » Networking » Port Setup
Network Configuration vlan3 = Default
Network Configuration wl0.1 = Default
Network Configuration wl1.1 = Default
Enable DHCP server for bridge br1
Setup » Networking » DHCPD » Multiple DHCP Server
Click Add
Select br1 and fill in the first address, maximum number of DHCP addresses and lease time in minutes. E.g. 200, 50 and 1440.
Click Apply Settings.
Separate the networks
Now that we have the two networks up and running, it is time to separate them. The firewall rules listed below added to Administration > Commands > Save Firewall. If you use an USB memory stick, the rules can also be stored in an executable /jffs/etc/config/*.wanup script. Such a script runs automatically each time the WAN link and firewall are up (see Script Execution).
Enable NAT for br1 (use “iptables -nvL -t nat” to verify)
iptables -t nat -I POSTROUTING -o `get_wanface` \
–src `nvram get br1_ipaddr`/`nvram get br1_netmask` -j SNAT \
–to `nvram get wan_ipaddr`
To restrict br1 from accessing br0 and visa versa,
iptables -I FORWARD -i br0 -o br1 -m state –state NEW -j DROP
iptables -I FORWARD -i br1 -o br0 -m state –state NEW -j DROP
Optionally, restrict br1 from accessing the management interface of the router.
iptables -I INPUT -i br1 -m state –state NEW -j DROP
iptables -I INPUT -i br1 -p udp –dport 67 -j ACCEPT
iptables -I INPUT -i br1 -p udp –dport 53 -j ACCEPT
iptables -I INPUT -i br1 -p tcp –dport 53 -j ACCEPT
Test
To test the interfaces, configure a space computer interface for DHCP and connect it to each of the LAN ports. Then verify that the assigned IP address matches the subnet of the network. Do the same with the wireless networks.
Shows how you can use a $75 consumer class router and dd-wrt to support 2 networks. It will create a secondary network for guests and visitors. Besides the usual primary network, it will create a secondary network supporting both wireless and wired connections. The secondary network could be used to provide internet access to customers or visitors.
The router is assumed to be flashed with open source DD-Wrt firmware. This firmware adds some business class features to your router. The router will be configured by taking advantage of two features that allow network traffic to be separated:
VLANs, allows wired LAN ports to be grouped and each group to be treated differently.
multiple SSIDs, allows multiple wireless network names (SSID) and security settings. The traffic over each SSID can be treated differently.
Before we start
The router is assumed to be running open source DD-Wrt firmware and configured for a single wired and wireless network. The router should also be configured for shell access (ssh) or telnet. Further, the reader should have a basic understanding of
the web based user interface (WebGUI)
networking concepts such as IP addresses, sub nets, routing, bridging and network interfaces. Some of the more specific terminology used in this article is:
A broadcast domain, is a network segment, in which all nodes can communicate directly by layer-2 broadcasts. Examples are a wired GigE network, or a wireless network.
A switch, handles frames at the data link layer (layer 2).
A router, handles packets at the network layer (layer 3). A router forms a boundary between broadcast domains.
A bridge, connects two or more network segments into a single broadcast domain (layer 2).
A virtual LAN(VLAN), creates distinct broadcast domains within one ore more physical networks. A VLAN is a switched network that is logically segmented by functions, project teams, or applications without regard to the physical location of users.
The configuration presented here has been tested on an Asus RT-N16 router running DD-Wrt mega build 15943. The approach outlined might also apply to other routers or builds, albeit with minor changes.
Inside the router
To create a secondary network, we need to separate the four LAN ports and create an virtual wireless network. The following section builds a basic understanding of the default data paths in the router. The following section describes how the software configuration
Hardware block diagram
Many consumer class routers are based on a chipset consisting of a IP switch and System-on-Chip. For example, the Asus RT-N16 router that is build around:
System-on-Chip BCM4718, provides the CPU, WiFi and USB.
Switch FabricBCM53115, provides the WAN and four LAN ports
Other GigE routers such as the Cisco/Linksys E2000 or E3000 are very similar. I you have an Asus RT-AC68, refer to my updated post.
Block diagram before
The block diagram above shows the data paths within the router. Note:
the LAN port numbers on the case do not correspond to the port numbers on the switch;
the WAN port connects to a special interface on the switch and can’t be reassigned;
port 8 connects the VLAN trunk from the switch to interface eth0 on the CPU.
The switch tags incoming frames with a VLAN identifier. Frames arriving on the WAN port are tagged as VLAN2, while frames from the LAN ports are tagged as VLAN1. The frames destined for the CPU are sent on port 8.
The CPU receives the frames over port eth0. Frames with a VLAN2 tag are treated as WAN traffic. Frames with a VLAN1 tag are combined (bridged) with frames from the wireless module (eth1) and treated as LAN traffic.
Firmware mapping
The configuration for the DD-Wrt is stored in nonvolatile memory (nvram). The configuration can be shown as described in the DD-Wrt document Switched Ports. An excerpt:
The tagging configuration is stored in vlan#ports variables where ‘*’ symbolizes the default path. Note that the vlan0ports variable appears to be unused on GigE routers. For the switch to move frames outside of any vlan, it needs to include port 8. This allows the SoC to route the packet. The vlan with the default is used for packets that do not have a vlan tag (see here).
An other important variable is port5vlans. It identifies every active VLAN plus the number 16 that indicates that tagging is enabled. The other variables appear only for the WebGUI.
Every active VLAN needs to have its name set to et0.
nvram show | grep vlan.*hwname | sort
vlan0hwname=et0
vlan1hwname=et0
vlan2hwname=et0
Creating to separate networks
To create a second network, we need to introduce an additional VLAN and an additional SSID for the wireless. The two can then be bridged together and given an unique subnet address. Before you start, I highly recommend making a backup of your current configuration.
Block diagram after
Create a virtual wireless network (wl0.1)
Using a web browser, connect to the router and bring up the WebGUI.
Wireless > Virtual Interfaces > Add. Specify the basic wireless settings. For the network configuration, choose bridged. Click Save.
Wireless > Wireless Security > Virtual Interface wl0.1. Specify the security settings. Click Apply Settings, to save and apply the changes.
Create a virtual local area network (vlan3)
We will use the shell (ssh) interface to configure the VLANs (because the GUI on Broadcom based routers have some related bugs). Login using ssh, and run the following commands:
nvram set vlan3hwname=et0 # VLAN3 is enabled
nvram set vlan1ports="3 4 8*" # assign LAN1/LAN2 to VLAN1
nvram set vlan3ports="1 2 8*" # assign LAN3/LAN4 to VLAN3
nvram set port4vlans="1 18 19" # LAN1 is part of VLAN1 (GUI only)
nvram set port3vlans="1 18 19" # LAN2 is part of VLAN1 (GUI only)
nvram set port2vlans="3 18 19" # LAN3 is part of VLAN3 (GUI only)
nvram set port1vlans="3 18 19" # LAN4 is part of VLAN3 (GUI only)
nvram commit
reboot
Bridge vlan3 and wl0.1 (br1)
To make the new wired and wireless network to behave as one, we logically combine interfaces vlan3 and wl0.1 using a new bridge interface br1:
Bridge the vlan3 and wl0.1 interfaces together as br1
Setup > Networking > Bridging > Create Bridge > Add. Enter br1 in the first field and click Apply Settings.
Setup > Networking > Bridging > Create Bridge > For br1 enter a private IP address and subnet mask. E.g. 10.0.4.1 and 255.255.255.0. Click Apply Settings.
Setup > Networking > Assign to bridge > Add. Select br1, interface vlan3 (LAN3 and LAN4) and click Apply Settings.
Setup > Networking > Assign to bridge > Add. Select br1, interface wl0.1 (the virtual wireless interface) and click Apply Settings.
Configure the DHCP server for br1
Setup > Networking > DHCPD > Multiple DHCP Server > Add. Select br1 and fill in the first m maximum number of DHCP addresses and lease time in minutes. E.g. 200, 50 and 1440. Click Apply Settings.
Separate the networks
Now that we have the two networks up and running, it is time to separate them. The firewall rules listed below added to Administration > Commands > Save Firewall. If you use an USB memory stick, the rules can also be stored in an executable /jffs/etc/config/*.wanup script. Such a script runs automatically each time the WAN link and firewall are up (see Script Execution).
To restrict br1 from accessing br0 and visa versa,
iptables -I FORWARD -i br0 -o br1 -m state --state NEW -j DROP
iptables -I FORWARD -i br1 -o br0 -m state --state NEW -j DROP
Optionally, to restrict br1 from accessing the management interface of the router.
To test the interfaces, configure a space computer interface for DHCP and connect it to each of the LAN ports. Then verify that the assigned IP address matches the subnet of the network. Do the same with the wireless networks.
In a virtual private network (VPN) a group of two or more computer systems communicate securely over the public internet. Security is provided by authentication and encryption. Computers that connect through a VPN have access to private network as if they were physically connected to it.
This article focuses on the OpenVPN implementation as it is included in the DD-Wrt router firmware. Besides security, one of its prominent features is that its traffic can traverse network address translators (NAT) and firewalls.
Two examples are given that describe the typical configurations:
remote access, providing remote users access to a private network, and
site-to-site, connecting a remote network to a private network.
These examples have been tested on two Asus RT-N16 routers running DD-Wrt mega build 15943. The approach outlined here might apply to other routers or builds that support OpenVPN and a writable file system such as JFFS, albeit with minor changes.
Before you start
This article assumes that readers possess a prior understanding of basic networking concepts such as IP addresses, DNS names, sub nets, routing, bridging, network interfaces, LANs and firewall rules.
Prior to configuring OpenVPN, we need to gain shell access to the routers, give the server a domain name, and create writable storage, keys and certificates.
Writable storage
The most obvious method of configuring OpenVPN is through the DD-Wrt web interface (WebGUI). This stores the configuration, certificates and keys in nonvolatile memory (nvram). In many routers, there may not be enough nvram to store all this information. To show the amount of nvram available, use the command “nvram show | grep size:”.
The approach presented here, has no nvram footprint. Instead it stores the configuration, keys and certificates on an USB memory stick. To format this memory stick, use the WebGUI as described in the DD-Wrt JFFS Wiki. An excerpt:
Insert the memory stick into any available USB port on the back of your DD-Wrt router.
In the WebGUI:
Administration >! JFFS2 Support > Enable = true, click Save
Wait a few seconds, the click Apply, wait a few seconds
Wait for the router to finish formatting the memory stick and brings up the WebGUI again.
Administration > JFFS2 Support > Clean JFFS = true, click Save
Reboot the router (just to make sure)
The memory stick will auto mount at /jffs.
Certificates and keys
OpenVPN uses bidirectional authentication with X.509 certificates. In this model the Certifying Authority (CA) is a third party that is trusted by the owner of the certificate and the party verifying the certificate.
To establish mutual trust, the client authenticates the server certificate, and the server authenticates the client certificate. It first ensures that the presented certificate was signed by a certifying authority (CA) , and verifies the common name (CN) and certificate type (client or server). For details refer to the OpenVPN Howto.
In the example below, we will setup our own CA and generate self signed certificates using a Windows host. The procedure of generating the certificates is similar for the Other flavors of OpenVPN.
You can then import the certificates in windows by running certmgr.msc and importing the ca.crt to the Trusted Root Certificate Authority, and the client.p12 to the Personal certificates.
set NAME=Client Name
set PASSWD_OUT=changeme
openssl pkcs12 -in "pki\pkcs12\${NAME}.p12" -out pki\pkcs12\${NAME}-tmp.pem -passin pass: -passout "pass:${PASSWD_OUT}"
openssl pkcs12 -export -in keys\temp.pem -out keys\%NAME%_passwd.p12 -passin pass:%PASSWD_OUT% -passout pass:%PASSWD_OUT%
keytool -importkeystore -srckeystore keys\%NAME%_passwd.p12 -destkeystore keys\%NAME%.jks -srcstoretype pkcs12 -srcstorepass %PASSWD_OUT% -deststorepass %PASSWD_OUT%
del keys\temp.pem
The JKS keypair can then be imported in e.g. Android Studio.
The previous method:
In the examples below, we will setup our own CA and generate self signed certificates using a Linux host. The procedure of generating the certificates is similar for the Windows version of OpenVPN.
Copy the easy-rsa directory and initialize:
cp -R /usr/share/openvpn/easy-rsa/2.0 ~/openvpn-ca # easy-rsa may be elsewhere
cd ~/openvpn-ca
vi vars
# update the fields at the end of the file
# change KEY_SIZE value to 2048
vi openssl-1.0.0.cnf
# change default_md value to sha512
vi pkitool
# change the two occurrences of -sha1 to -sha512
. ./vars
./clean-all
While we’re at it, assign extended key usage that will allow you to use the client certificates for other purposes such as code signing and email.
vi .`whichopensslcnf` # open openssl-1.0.0.cnf with Notepad under Windows
# under [ usr_cert ]
# extendedKeyUsage=clientAuth, emailProtection, codeSigning
# keyUsage=digitalSignature
later if so desired, you can convert client certificates to PKCS12 format usi
(optional) To use the key pair on Windows, you need to convert it to PKCS12 format
You can then import the certificates in windows by running certmgr.msc and importing the ca.crt to the Trusted Root Certificate Authority, and the client.p12 to the Personal certificates.
The JKS keypair can then be imported in e.g. Android Studio.
Create a certifying authority certificate and corresponding secret key. Use your name followed by CA as the common name:
./build-ca
Create Diffie Hellman parameters and shared secret key for tls-auth:
./build-dh
openvpn --genkey --secret keys/ta.key
Show the certificate details:
openssl x509 -in keys/ca.crt -noout -text
Real-time clock
Certificates have introduction and expiration dates, and therefore require the real-time clock and time zone to be set correctly.
The Network Time Protocol (NTP) can be used to automatically set the clocks. To configure NTP on the DD-Wrt server and clients:
Setup > Basic Setup > Time Settings. For my locality the settings are:
Time Zone = UTC-08:00
Summer Time = 2nd Sun Mar – first Sun Nov
Server IP/Name = 0.north-america.pool.ntp.org
Domain name
Usually the client will find the server by its public DNS name. If your router gets a dynamic WAN address, you should configure a Dynamic DNS (DDNS) service on the router used as OpenVPN server. This will give the router a public domain name whose address is automatically updated.
Setup > DDNS > Dynamic Domain Name System (my personal favorite is afraid.org)
The examples below assume that routers are accessible using secure shell (ssh). This also enable ssh features in an editor such as emacs. For example, on the Linux host used as the certifying authority:
emacs /rtr:/jffs/etc/config/rtr-server.wanup
Where rtr corresponds to an entry in your ~/.ssh/config file.
Routing versus Bridging
OpenVPN can connect clients using network routing or bridging. For a comparison between routing and bridging, refer to Bridging vs. Routing. An excerpt:
Routing uses the kernel device TUN to simulate a network layer device. It operates at the network layer where it handles IP packets. As a result, it:
has a low overhead, because it does not support broadcasts or require Ethernet headers;
for IPv6, OpenVPN version >=2.3 is required.
devices such as Android only support TUN.
Bridging uses the kernel device TAP to simulates a link layer device. It operates at the link layer and handles Ethernet frames. Consequently it:
supports non-IP based traffic;
supports Windows network neighborhood discovery without using WINS;
broadcasts and Ethernet headers cause overhead (for examples, you need to tell DHCP server not to respond to request coming over TAP).
Routing example: Site-to-Site
OpenVPN can be used to connect two local area networks (LANs). In this example, two DD-Wrt routers are used. One serves as the server, and the other as the client. Note that the private network numbers are fairly arbitrary. They were chosen to match my existing networks.
rtr, the server, with
WAN address rtr.yourdomain.com
LAN network 10.0.1.0/24
rtr2, the client.
LAN network 10.0.2.0/24
The server will use network 10.0.3.0/24 for the VPN. Of that allocates the first address (10.0.3.1) for itself. Clients will be allocated one of the remaining addresses.
srtr-erver
The examples presented here, do not use the WebGUI nor NVRAM. Instead they use bash scripts store on an memory stick and mounted as /jffs. The scripts are automatically started by DD-Wrt each time the WAN link and firewall are up. For more information refer to DD-Wrt Script Execution.
Certificates
On the Linux host, create certificates and corresponding secret keys for the server and client.
./build-key-server rtr-server # common name = rtr-server, no passwd
./build-key rtr2 # common name = rtr2, no passwd
OpenVPN Server
From the Linux host, copy the certificates/keys files to /jffs/etc/openvpn on the server.
Create a startup script /jffs/etc/openvpn/config/rtr-server.wanup on the server. Make the script executable (chmod 755). DD-Wrt will call this script each time the WAN link comes up.
Create the client specific configuration file /jffs/etc/openvpn/ccd/rtr2 on the server
iroute 10.0.2.0 255.255.255.0 # OpenVPN server to remote clients
Start the OpenVPN server
/jffs/etc/config/rtr-server.wanup
See how it is going. Note that you can also use the WebGUI (Status > OpenVPN) to inspect the OpenVPN log messages.
more /tmp/rtr-server/log # a treasure trove of debug information
netstat -lu # should be listening on port 1194
iptables -nvL # INPUT chain should have port 1194 open
OpenVPN Client
From the Linux host, copy the certificates/keys files to /jffs/etc/openvpn
Create a startup script /jffs/etc/openvpn/config/rtr2-to-rtr.wanup on the server. Remember to make the script executable (chmod 755). DD-Wrt will call this script each time the WAN link comes up.
See how things are going. Note that you can also use the WebGUI (Status > OpenVPN) to inspect the OpenVPN log messages.
more /tmp/rtr2-to-rtr/log
Bridging example: Remote Access
OpenVPN can also be used to connect remote computers to a local area network. The VPN gives the remote computers access to resources on the local area network such as files, printers, databases or internal websites.
In this example, one DD-Wrt router is configured as an OpenVPN server. Road warrior clients can connect to this router to gain access to the server’s LAN. The systems are:
rtr2, the server with:
LAN network 10.0.2.0/24
WAN address rtr2.yourdomain.com
client, connecting from a public IP address, running either
On the Linux host, create certificates and corresponding secret keys for the server and clients.
./build-key-server rtr2-server # common name = rtr2-server, no passwd
./build-key username1 # common name = username1, no passwd
./build-key username2 # common name = username2, no passwd
OpenVPN Server
From the Linux host, copy the certificates/keys files to /jffs/etc/openvpn on the server.
Create a startup script /jffs/etc/openvpn/config/rtr2-server.wanup on the server. Make the script executable (chmod 755). DD-Wrt will call this script each time WAN link comes up.
Create an helper script /jffs/etc/openvpn/rtr2-server.helper on the server. Make the script executable (chmod 755).
Note that the tap interface will get a random MAC address and the bridge (br0) picking up the lowest address. This confuses Windows Network Discovery in Windows 7, triggering a “Set Network Location” dialog. To prevent this, you can take the last random MAC address and reuse it for subsequent tap interfaces. (More details here.)
See how it is going. Note that you can also use the WebGUI (Status > OpenVPN) to inspect the OpenVPN log messages.
more /tmp/rtr2-server/log # a treasure trove of debug information
netstat -lu # should be listening on port 1194
iptables -nvL # INPUT chain should have port 1194 open
OpenVPN Server (using WebGUI)
Alternatively, the server can be configured using the DD-Wrt WebGUI. The config will be stored in nvram, except for the large certificates and key files that are stored on a memory stick. In this configuration, DD-Wrt generate matching files in /tmp/openvpn/.
Copy the certificates/keys files. Remember to limit access to the key files (chmod 600).
ca.crt
rtr2-server.crt
rtr2-server.key
dh2048.pem
ta.key
Services > VPN > OpenVPN Server. These values will be used to create the configuration file /tmp/openvpn/openvpn.conf
Import Certificates (from paragraph 6.4.1 in my document SISO).
From the start menu run certmgr.msc
Under the Certificates, right-click on Trusted Root Certification Authorities. From All Tasks choose Import.
Click Next
Browse to select the Personal Information Exchange certificate CAcert.crt.
Click Next
Type in the password, and Mark this key as exportable
Click Next
Place all certificates in Personal Certificates Store
Click Next; Click Finish
Verify that the certificate is listed under the Root Certification Authorities
Under the Certificates, right-click on Personal. From All Tasks choose Import.
Click Next
Browse to select the Personal Information Exchange certificate (yourname.p12).
Click Next
Type in the password, and Mark this key as exportable
Click Next
Place all certificates in Personal Store
Click Next; Click Finish
Verify that the certificate displays correctly, and the Root CA is known.
Use explorer to show the directory “C:\Program Files (x86)\OpenVPN\config\”
Populate the directory with the certificate and key files from the Linux host:
ca.crt
username1.crt
username1.key
ta.key
Create the configuration file rtr2.ovpn in that same directory
remote rtr2.yourdomain.com 1194
client
ca ca.crt
cert username1.crt
key username1.key
tls-auth ta.key 1
ns-cert-type server
dev tap
proto udp
nobind
resolv-retry infinite
persist-key
persist-tun
remote-cert-tls server
float
script-security 2
cipher BF-CBC
auth SHA1
verb 3
mute 5
With OpenVPN running, right-click on its icon in the task area (bottom right) > connect > rtr2.
OpenVPN Client, running OS X
Create folder rtr2.yourdomain.com on your Desktop. (details can be found in the wiki)
Copy the certificate/key files to that folder
ca.crt
username2.crt
username2.key
ta.key
In that folder, create configuration file rtr2.ovpn
remote rtr2.yourdomain.com 1194 # update me
client
ca ca.crt
cert username2.crt
key username2.key
tls-auth ta.key 1
ns-cert-type server
dev tap
proto udp
nobind
resolv-retry infinite
persist-key
persist-tun
remote-cert-tls server
float
script-security 2
cipher BF-CBC
auth SHA1
verb 3
mute 5
Append the extension .tblk to the folder name. This will change the folder icon into a Tunnelblick VPN Configuration.
Double-click the folder’s new icon to install it. Choose private configuration when asked.
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie
Duration
Description
cookielawinfo-checkbox-analytics
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional
11 months
The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy
11 months
The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.