This post was first published on April 15, 2018 ! Its contents might be outdated!
Features and limitations
RIPv1 was introduced in 1988 and RIPv2 in 1993 and it became a standard in 1998. It is easy to use, but has a lot of limitations. The biggest such limitation is that the maximum hop count can only be 15, which means in practice that between the farthest two routers, there can be only 13 other routers. The routing domain can be of course bigger. RIPv2 has the ability to use authentication, however the only method for that is using plain passwords or MD5.
Preparing FreeBSD
In order to send packets between different subnets it is essential to know how one can get to the other subnet. If many subnets have only one common router, this is quite easy, as every local subnet is known and every packet sent to an unknown subnet will be forwarded to another router (aka. to the default gateway).
The information about which network is where is stored in the routing table. The currently known subnets can be listed with the netstat command, where -r is telling netstat to give us the routing information, -n is not to resolve the IP addresses and -4 is to do it for IPv4.
| |
Each network has an associated cost in order to figure out which way is the best. In RIP, this cost is calculated from the number of hops, where one hop is one router. A directly connected subnet has a hop count of 0. With RIP, the whole routing table is sent to the neighbor which then processes it and sends the updated routing table to its neighbor, and so on. In the following examples, there are two FreeBSD machines on the same subnet (192.168.122.45/24 and 192.168.122.169/24). Additionally, they have loopback interfaces:
- lo1 on router1 with the IP Address of 10.0.1.1/24
- lo2 on router2 with the IP Address of 172.16.2.1/24
Naturally not only loopback interfaces can be included in RIP, but other, physical or VLAN interfaces too. Creating a loopback interface and the make it persistent between reboots:
| |
| |
The loopback interfaces on each of the routers exists, though they have no information about the interface on the other machine.
Router1:
| |
Router 2:
| |
Pinging the loopback address on router2 from router1 fails, because router1 has no idea where to send the packets.
| |
In order to be able to reach the subnets behind the routers, the information about the networks has to be exchanged between the two routers. First, enable routing, this makes sure that if router1 receives a packet on the interface with the IP 192.168.122.45, it won’t drop it, but forward it to the loopback interface. Do this on all of the routers.
| |
Starting routed.
RIP on FreeBSD is handled by routed(8). We start routed with 2 flags:
-stells routed to advertise the known routes even if there is only one interface. This is necessary if we want to advertise loopback interfaces.-P ripv2tells routed to use RIPv2.
| |
After around 30 seconds, 10.0.1.1 should be known on router2, and also 172.16.2.1 is known on router1.
| |
| |
With that, RIP is up and running on our routers. Even though MD5 is the only option for authentication, it is worth it to turn it on, and shortening the hold time from the default 30 minutes is also useful, but having a lot of options in rc.conf is not convenient. RouteD by default looks for the /etc/gateways file for parameters.
md5_passwd=P4ssW0rd|1tells routed to use P4ssW0rd as the authentication password. RouteD will only accept routes if the incoming routing table uses this password with the key ID 1. There can be more then 1 password, with different key IDs.rdisc_interval=Ntells routed how often to send the routing table over. The learned routes will stay in the routing table for 3*N.
| |
Make sure that etc/gateway can be only read by root!
| |
Remove the ripv2 parameter from rc.conf
| |
Finally restart routed
| |
If the password matches, the route will still be propagated between the routers.
| |
| |
If the necessary routes are present on both routers, ping will work.
| |
Security and alternatives
Using MD5 is not the best to secure RIP, but this is unfortunately the only way (other then plain passwords of course…). Malicious hosts can advertise routes with better hop count then the other, forcing traffic to flow to them. In bigger networks, OSPF or even BGP can be used to propagate routes between routers.