4f8c2145e61e792b01502185ac81438be07478f2
howto/mikrotik.md
| ... | ... | @@ -79,10 +79,10 @@ If you configured everything correctly you should be able to ping the remote end |
| 79 | 79 | |
| 80 | 80 | ### Filters |
| 81 | 81 | |
| 82 | -Both BGP and routing filters were redone from the ground up on RoS 7.x |
|
| 83 | -The official migration guide can be found [here](https://help.mikrotik.com/docs/display/ROS/Routing) |
|
| 82 | +Both BGP and routing filters were redone from the ground up for RouterOS v7. If you're updating an existing v6 installation, the official migration guide can be found [here](https://help.mikrotik.com/docs/display/ROS/Routing) |
|
| 83 | + |
|
| 84 | +It's a good idea to setup filters for BGP instances, both IN (advertisements you accept) and OUT (advertisements you send). |
|
| 84 | 85 | |
| 85 | -It's a good idea to setup filters for BGP instances, both IN (accept advertisements) and OUT (send advertisements) |
|
| 86 | 86 | In this example, we will be filtering: |
| 87 | 87 | |
| 88 | 88 | * IN: 192.168.0.0/16 and 169.254.0.0/16, because we don't want other people's routes interfering with out network |
| ... | ... | @@ -90,25 +90,9 @@ In this example, we will be filtering: |
| 90 | 90 | |
| 91 | 91 | This filter will not only catch /8 or /16 networks, but smaller networks inside this subnets as well. |
| 92 | 92 | |
| 93 | -#### RoS 6.x |
|
| 94 | - |
|
| 95 | -``` |
|
| 96 | -/routing filter |
|
| 97 | -add action=discard address-family=ip chain=dn42-in prefix=192.168.0.0/16 prefix-length=16-32 protocol=bgp |
|
| 98 | -add action=discard address-family=ip chain=dn42-in prefix=169.254.0.0/16 prefix-length=16-32 protocol=bgp |
|
| 99 | -add action=discard address-family=ip chain=dn42-out prefix=192.168.0.0/16 prefix-length=16-32 protocol=bgp |
|
| 100 | -add action=discard address-family=ip chain=dn42-out prefix=169.254.0.0/16 prefix-length=16-32 protocol=bgp |
|
| 101 | -``` |
|
| 102 | - |
|
| 103 | -If you want only DN42 connectivity, you can filter IN 10.0.0.0/8 (ChaosVPN / freifunk networks): |
|
| 104 | -``` |
|
| 105 | -/routing filter |
|
| 106 | -add action=discard address-family=ip chain=dn42-in prefix=10.0.0.0/8 prefix-length=8-32 protocol=bgp |
|
| 107 | -``` |
|
| 108 | - |
|
| 109 | 93 | #### RoS 7.x |
| 110 | 94 | |
| 111 | -RoS 7 now defaults to default-reject, meaning if you reach the end of the chain without matching any rules, the route will be rejected. |
|
| 95 | +RoS 7 filters have a default-reject behaviour, meaning if you reach the end of the chain without matching any rules, the route will be rejected. |
|
| 112 | 96 | |
| 113 | 97 | As such, you need to either explicitly accept all the prefixes that you want to keep, or place a final accept at the end of the chain, after rejecting undesired prefixes. |
| 114 | 98 | |
| ... | ... | @@ -130,75 +114,77 @@ If you want only DN42 connectivity, you can also filter IN 10.0.0.0/8 (ChaosVPN |
| 130 | 114 | add chain=dn42-in rule="if (dst in 10.0.0.0 && dst-len > 8) { reject }" |
| 131 | 115 | ``` |
| 132 | 116 | |
| 133 | -### BGP |
|
| 134 | -Now, for actual BGP configuration. |
|
| 117 | +#### RoS 6.x |
|
| 135 | 118 | |
| 136 | -#### RoS v6 |
|
| 137 | -``` |
|
| 138 | -/routing bgp instance |
|
| 139 | -set default disabled=yes |
|
| 140 | -add as=YOUR_AS client-to-client-reflection=no name=bgp-dn42-somename out-filter=dn42-in router-id=1.1.1.1 |
|
| 141 | -``` |
|
| 142 | -Let's add some peers. Right now we have just one, but we still need two connections - to IPv4 and IPv6 |
|
| 119 | +RouterOS v6 does not have a default-reject behaviour. It will apply the rules in the chain, then accept anything that didn't match a rule. |
|
| 143 | 120 | |
| 144 | -IPv4: |
|
| 145 | 121 | ``` |
| 146 | -/routing bgp peer |
|
| 147 | -add comment="DN42: somepeer IPv4" in-filter=dn42-in instance=bgp-dn42-somename multihop=yes \ |
|
| 148 | -name=dn42-somepeer-ipv4 out-filter=dn42-out remote-address=192.168.200.129 remote-as=PEER_AS \ |
|
| 149 | -route-reflect=yes ttl=default |
|
| 122 | +/routing filter |
|
| 123 | +add action=discard address-family=ip chain=dn42-in prefix=192.168.0.0/16 prefix-length=16-32 protocol=bgp |
|
| 124 | +add action=discard address-family=ip chain=dn42-in prefix=169.254.0.0/16 prefix-length=16-32 protocol=bgp |
|
| 125 | +add action=discard address-family=ip chain=dn42-out prefix=192.168.0.0/16 prefix-length=16-32 protocol=bgp |
|
| 126 | +add action=discard address-family=ip chain=dn42-out prefix=169.254.0.0/16 prefix-length=16-32 protocol=bgp |
|
| 150 | 127 | ``` |
| 151 | -IPv6 (if needed): |
|
| 152 | 128 | |
| 129 | +If you want only DN42 connectivity, you can filter IN 10.0.0.0/8 (ChaosVPN / freifunk networks): |
|
| 153 | 130 | ``` |
| 154 | -/routing bgp peer |
|
| 155 | -add address-families=ipv6 comment="DN42: somepeer IPv6" in-filter=dn42-in \ |
|
| 156 | -instance=bgp-dn42-somename multihop=yes name=dn42-somepeer-ipv6 out-filter=dn42-out \ |
|
| 157 | -remote-address=fd42:c644:5222:3222::40 remote-as=PEER_AS route-reflect=yes ttl=default |
|
| 131 | +/routing filter |
|
| 132 | +add action=discard address-family=ip chain=dn42-in prefix=10.0.0.0/8 prefix-length=8-32 protocol=bgp |
|
| 158 | 133 | ``` |
| 159 | 134 | |
| 160 | -Also, as a note, Mikrotik RoS 6.x doesn't deal well with BGP running over link-local addresses (the address starting with fe80). You need to use a fd42:: address in your BGP session, otherwise, BGP will not install any received route. |
|
| 161 | 135 | |
| 162 | -#### BGP Advertisements |
|
| 163 | -You want to advertise your allocated network (most likely), it's very simple: |
|
| 164 | - |
|
| 165 | -``` |
|
| 166 | -/routing bgp network |
|
| 167 | -add network=YOUR_ALLOCATED_SUBNET synchronize=no |
|
| 168 | -``` |
|
| 169 | -You can repeat that with as much IPv4 and IPv6 networks which you own. |
|
| 136 | +### BGP |
|
| 137 | +Now, for actual BGP configuration. |
|
| 170 | 138 | |
| 171 | 139 | #### RoS 7.x |
| 172 | 140 | |
| 173 | -First difference from v6.x: There is no "network" menu. We advertise our networks now by adding them to the firewall address-list and referencing in the BGP configuration. Also, we can only advertise networks that are part of our static routes. Of course, we can still propagate routes received from others peers. |
|
| 141 | +We'll start by defining the subnets that we host and want to advertise. RouterOS v7 uses the firewall's Address Lists to define a list of networks, then our BGP config refers to those lists when making advertisements. |
|
| 174 | 142 | |
| 175 | -Adding a network list: |
|
| 143 | +Create an address list containing your DN42 subnet allocation, one for IPv4 and one for IPv6: |
|
| 176 | 144 | ``` |
| 177 | 145 | IPv4 |
| 178 | 146 | /ip firewall address-list |
| 179 | -add address=YOUR_ALLOCATED_SUBNET list=DN42_allocated_v4 |
|
| 147 | +add address=YOUR_ALLOCATED_SUBNET/MASK list=DN42_allocated_v4 |
|
| 180 | 148 | |
| 181 | 149 | IPv6 |
| 182 | 150 | /ipv6 firewall address-list |
| 183 | -add address=YOUR_ALLOCATED_SUBNET list=DN42_allocated_v6 |
|
| 151 | +add address=YOUR_ALLOCATED_SUBNET/MASK list=DN42_allocated_v6 |
|
| 184 | 152 | ``` |
| 185 | 153 | |
| 186 | -Adding a static route to your full allocated network: |
|
| 154 | +RouterOS will only advertise networks that it has a route to, this helps prevent you from accidentally advertising subnets that aren't usable (eg. due to a typo). If your subnet is already attached to an interface then this isn't a problem, but it's common practice to add a dummy route to the routing table anyway, to ensure that your subnet will always be advertised. |
|
| 155 | + |
|
| 156 | +Add a blackhole route to your DN42 subnet allocation: |
|
| 187 | 157 | ``` |
| 158 | +IPv4 |
|
| 159 | +/ip route |
|
| 160 | +add blackhole distance=1 dst-address=YOUR_ALLOCATED_SUBNET/MASK |
|
| 161 | + |
|
| 162 | +IPv6 |
|
| 188 | 163 | /ipv6 route |
| 189 | -add blackhole disabled=no distance=1 dst-address=YOUR_ALLOCATED_SUBNET |
|
| 164 | +add blackhole distance=1 dst-address=YOUR_ALLOCATED_SUBNET/MASK |
|
| 190 | 165 | ``` |
| 191 | 166 | |
| 192 | -Let's create a template for DN42. It isn't strictly necessary, but it makes our life easier when adding more peers in future. |
|
| 167 | +This behaviour is explained here: https://forum.mikrotik.com/t/rosv7-bgp-blackhole/177053/4 |
|
| 168 | + |
|
| 169 | +In recent releases (around v7.21) this can be done from the BGP connection settings instead. If you enable the `output.network-blackhole` setting, RouterOS will create suitable blackhole routes for the subnets in your Address List, so you don't have to add them yourself. |
|
| 170 | + |
|
| 171 | + |
|
| 172 | +Let's create a connection template for DN42. It isn't strictly necessary, but it makes our life easier when adding more peers in future. |
|
| 193 | 173 | ``` |
| 194 | 174 | /routing bgp template |
| 195 | 175 | add afi=ipv4 as=YOUR_AS_NUMBER name=DN42_template_v4 output.network=DN42_allocated_v4 router-id=1.1.1.1 |
| 196 | 176 | add afi=ipv6 as=YOUR_AS_NUMBER name=DN42_template_v6 output.network=DN42_allocated_v6 router-id=1.1.1.1 |
| 197 | 177 | ``` |
| 198 | 178 | |
| 199 | -Now is time to add one peer: |
|
| 200 | 179 | |
| 201 | -Another difference from RoS v6.x is that v7.x can use link-local adresses (validated with RoS 7.14.3, 7.18.1, 7.18.2 and 7.19rc2). The trick is to add "%INTERFACE" after the address, where "INTERFACE" is the name of the interface the link-local is allocated to - or the interface used to get to that remote link-local. So, if You want to listen on fe80::1 on the "myPeer" interface, the address would be "fe80::1%myPeer". |
|
| 180 | +Create an instance, you can think of this as the BGP daemon that's running. |
|
| 181 | +``` |
|
| 182 | +/routing bgp instance |
|
| 183 | +add as=<YOUR_AS> name=bgp-dn42-somename router-id=1.1.1.1 |
|
| 184 | +``` |
|
| 185 | + |
|
| 186 | + |
|
| 187 | +Now it's time to add a peer. In RouterOS v7 you can use link-local addresses instead of regular routable addresses, which helps simplify config and reduces the number of IP addresses used for routing (validated with RoS 7.14.3, 7.18.1, 7.18.2 and 7.19rc2). The trick is to add `%INTERFACE` after the address, where "INTERFACE" is the name of the interface the link-local address is assigned to, or the interface used to reach your peer's link-local address. So, if You want to listen on fe80::1 on the "myPeer" interface, the address would be "fe80::1%myPeer". |
|
| 202 | 188 | |
| 203 | 189 | RoS 7.17 and newer can set the link local address. |
| 204 | 190 | |
| ... | ... | @@ -207,7 +193,7 @@ RoS 7.17 and newer can set the link local address. |
| 207 | 193 | IPv4 peer |
| 208 | 194 | /routing bgp connection |
| 209 | 195 | add address-families=ipv4 disabled=no input.filter=dn42-in \ |
| 210 | -local.address=ADDRESS_YOUR_PEER_USE_TO_CONNECT_ON_YOU .role=ebgp \ |
|
| 196 | +local.address=ADDRESS_YOUR_PEER_USE_TO_CONNECT_TO_YOU .role=ebgp \ |
|
| 211 | 197 | multihop=yes name=PEER_NAME output.filter-chain=dn42-out \ |
| 212 | 198 | .network=DN42_allocated_v4 remote.address=YOUR_PEER_REMOTE_ADDRESS \ |
| 213 | 199 | .as=PEER_AS_NUMBER routing-table=main templates=DN42_template_v4 |
| ... | ... | @@ -215,13 +201,55 @@ multihop=yes name=PEER_NAME output.filter-chain=dn42-out \ |
| 215 | 201 | IPv6 peer |
| 216 | 202 | /routing bgp connection |
| 217 | 203 | add address-families=ipv6 disabled=no input.filter=dn42-in \ |
| 218 | -local.address=ADDRESS_YOUR_PEER_USE_TO_CONNECT_ON_YOU .role=ebgp \ |
|
| 204 | +local.address=ADDRESS_YOUR_PEER_USE_TO_CONNECT_TO_YOU .role=ebgp \ |
|
| 219 | 205 | multihop=yes name=PEER_NAME output.filter-chain=dn42-out \ |
| 220 | 206 | .network=DN42_allocated_v6 remote.address=YOUR_PEER_REMOTE_ADDRESS \ |
| 221 | 207 | .as=PEER_AS_NUMBER routing-table=main templates=DN42_template_v6 |
| 222 | 208 | ``` |
| 223 | 209 | |
| 224 | 210 | |
| 211 | +#### RoS 6.x |
|
| 212 | + |
|
| 213 | +The older RouterOS 6.x is fairly similar, but the biggest difference is that instead of using Address Lists for your advertised subnets, you specify them directly in the BGP settings, in the Network menu. We'll deal with that later. |
|
| 214 | + |
|
| 215 | +Create an instance, you can think of this as the BGP daemon that's running. |
|
| 216 | +``` |
|
| 217 | +/routing bgp instance |
|
| 218 | +set default disabled=yes |
|
| 219 | +add as=YOUR_AS client-to-client-reflection=no name=bgp-dn42-somename out-filter=dn42-in router-id=1.1.1.1 |
|
| 220 | +``` |
|
| 221 | + |
|
| 222 | +Let's add some peers. Right now we have just one, but we still need two connections - for IPv4 and IPv6 |
|
| 223 | + |
|
| 224 | +IPv4: |
|
| 225 | +``` |
|
| 226 | +/routing bgp peer |
|
| 227 | +add comment="DN42: somepeer IPv4" in-filter=dn42-in instance=bgp-dn42-somename multihop=yes \ |
|
| 228 | +name=dn42-somepeer-ipv4 out-filter=dn42-out remote-address=192.168.200.129 remote-as=PEER_AS \ |
|
| 229 | +route-reflect=yes ttl=default |
|
| 230 | +``` |
|
| 231 | + |
|
| 232 | +IPv6 (if desired): |
|
| 233 | +``` |
|
| 234 | +/routing bgp peer |
|
| 235 | +add address-families=ipv6 comment="DN42: somepeer IPv6" in-filter=dn42-in \ |
|
| 236 | +instance=bgp-dn42-somename multihop=yes name=dn42-somepeer-ipv6 out-filter=dn42-out \ |
|
| 237 | +remote-address=fd42:c644:5222:3222::40 remote-as=PEER_AS route-reflect=yes ttl=default |
|
| 238 | +``` |
|
| 239 | + |
|
| 240 | +NB: Mikrotik RoS 6.x doesn't deal well with BGP running over link-local addresses (addresses that start with with fe80). You need to use an fd42:: address in your BGP session, otherwise BGP will not install any received routes. |
|
| 241 | + |
|
| 242 | +Finally we can advertise our routes. You're presumably advertising your allocated DN42 subnet, it's very simple: |
|
| 243 | + |
|
| 244 | +``` |
|
| 245 | +/routing bgp network |
|
| 246 | +add network=YOUR_ALLOCATED_SUBNET synchronize=no |
|
| 247 | +``` |
|
| 248 | + |
|
| 249 | +You can repeat this for all the IPv4 and IPv6 networks that you host. |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + |
|
| 225 | 253 | ## Split DNS |
| 226 | 254 | |
| 227 | 255 | You can separate DNS requests for the .dn42 TLD from your default DNS traffic. This allows regular (non-DN42) lookups to work as normal, while .dn42 queries are handled on the DN42 network. |