LEDE/OpenWRT — Basic Routing

CT WiFi
LEDE/OpenWrt & IoT
Published in
2 min readMar 23, 2016

Routing allows you to define set paths on your network to send network traffic.

SSH to your LEDE/OpenWRT device

If you are using Windows then start PuTTY and click Session on the left side, select SSH from the options, and then enter in the IP Address of your LEDE/OpenWRT box into the Host Name field.

Once you’ve done this just click on Open to start up the SSH connection.

PuTTY

If you are connecting via terminal, then just SSH to your LEDE/OpenWRT device using the following command, where 192.168.1.1 is your LEDE/OpenWRT device’s IP address.

ssh root@192.168.1.1

Installing Packages

First off we need to install a package. It will allow us to enable more than one routing table and to create rules to apply them, without any additional firewall rules.

Run the following commands:

opkg updateopkg install ip

Create Routing Table

Next we want to create a new routing table.

Run the following command:

vi /etc/iproute2/rt_tables

And then add in the rules that you want. In this case we are adding 10 vpn, but you can use whatever you need and save it. It should look like the following:

#
# reserved values
#
255 local
254 main
253 default
10 vpn
0 unspec
#
# local
#
#1 inr.ruhelp

Once this is done, you will need to add the host rules you want. The hosts could be any address, but in this example we are going to be adding the following hosts; 192.168.1.20 and 192.168.1.30

Run the following commands in the console:

ip rule add from 192.168.1.20 table vpn
ip rule add from 192.168.1.30 table vpn

Now we add a default route to your new table by running the following command, replacing the placeholder sections with your details:

ip route add default via <ip_of_the_far_end_of_your_tunnel> dev <pptp_iface_name> table vpn

And then flush the route cache using the following command:

ip route flush cache

Now all the traffic from hosts using the routing table will go through the VPN. You can use a traceroute to confirm this.

The table created will last throughout reboots, however you will need to apply your route and rules after every boot. To automate this, you can create an init script.

If you found this post helpful please let us know by clicking the ♥ below.

This blog was brought to you by Cucumber Wi-Fi. Cucumber helps you run a more efficient Wi-Fi network. Check it out here.

Cucumber Wi-Fi — control any (Wi-Fi) device from the cloud.

--

--

CT WiFi
LEDE/OpenWrt & IoT

An orchestration tool for WiFi devices — Manage your networks from a single-pane of glass.