9a894e2015a86ceb951946b8fc8a9b114979b0b3
howto/mikrotik.md
... | ... | @@ -227,8 +227,240 @@ Since version 6.47 have added functionality that can redirect DNS queries accord |
227 | 227 | ``` |
228 | 228 | /ip dns static |
229 | 229 | add comment=DN42 forward-to=172.23.0.53 regexp=".*\\.dn42" type=FWD |
230 | +``` |
|
231 | + |
|
232 | +# How to connect to dn42 using Mikrotik RouterOS |
|
233 | + |
|
234 | + |
|
235 | +## Legend |
|
236 | + |
|
237 | + * 1.1.1.1 - peer external IP |
|
238 | + * 2.2.2.2 - your external IP |
|
239 | + * A private /30 range for the GRE endpoints: 192.168.200.128/30 |
|
240 | + * 192.168.200.129 - remote GRE IPv4 address |
|
241 | + * 192.168.200.130 - local GRE IPv4 address |
|
242 | + * fd42:c644:5222:3222::40 - remote GRE IPv6 address |
|
243 | + * fd42:c644:5222:3222::41 - local GRE IPv6 address |
|
244 | + * YOUR_AS - your AS number (numbers only) |
|
245 | + * PEER_AS - peer AS number (numbers only) |
|
246 | + |
|
247 | +## RouterOS limitations |
|
248 | + |
|
249 | + * IPSec only supports IKEv1 |
|
250 | + * OpenVPN only works in tcp mode |
|
251 | + * OpenVPN does not support LZO compression |
|
252 | + * You can't use /31 subnet for Point-to-Point (PtP) links |
|
230 | 253 | |
231 | -## Specifying BGP Community |
|
254 | +Mikrotik/RouterOS can't handle very well /32 on Point-to-Point links (like GRE). There is a [separate howto](/howto/mikrotik/ptp32) to explain how to setup /32 between in a GRE link (or even a OpenVPN). What is the easy way? Just use any /30 on the GRE Link, either from your assigned DN42 pool address or use a private address like 192.168. Please don't choose from 172.16.0.0/12 or 10.0.0.0/8 because they may overlap with DN42 or ChaosVPN. |
|
255 | + |
|
256 | +RouterOS v7.2 has some nasty bugs when using PTP configuration or IPv6 link local addresses as NEXTHOP. It won't work (confirmed for v7.2 by their support staff). |
|
257 | + |
|
258 | +## Tunnel |
|
259 | + |
|
260 | +### IPSec |
|
261 | +First, let's add IPSec peer and encryption policy. |
|
262 | +Peer most likely provided you with encryption details. |
|
263 | +If not, ask them about it. |
|
264 | +Here we're gonna use aes256-sha256-modp1536 |
|
265 | + |
|
266 | +``` |
|
267 | +/ip ipsec peer |
|
268 | +add address=1.1.1.1 comment=gre-dn42-peer dh-group=modp1536 \ |
|
269 | +enc-algorithm=aes-256 hash-algorithm=sha256 local-address=2.2.2.2 secret=PASSWORD |
|
270 | + |
|
271 | +``` |
|
272 | +``` |
|
273 | +/ip ipsec policy |
|
274 | +add comment=gre-dn42-peer dst-address=1.1.1.1/32 proposal=dn42 protocol=gre \ |
|
275 | +sa-dst-address=1.1.1.1 sa-src-address=2.2.2.2 src-address=2.2.2.2/32 |
|
276 | +``` |
|
277 | + |
|
278 | +### GRE |
|
279 | +Pretty straightforward here |
|
280 | + |
|
281 | +``` |
|
282 | +/interface gre |
|
283 | +add allow-fast-path=no comment="DN42 somepeer" local-address=2.2.2.2 name=gre-dn42-peer \ |
|
284 | +remote-address=1.1.1.1 |
|
285 | +``` |
|
286 | + |
|
287 | +### IPs inside the GRE tunnel |
|
288 | +Your peer most likely provided you with IP adresses for GRE tunnel. |
|
289 | +As I said before, you can't use /31 for PtP links, so, in the "easy way" we will be using /30. |
|
290 | +If you want to avoid wasting a whole /30 for your peering, please check the [point-to-point configuration for RouterOS](/howto/mikrotik/ptp32) |
|
291 | + |
|
292 | +Add the IP your peer provided you: |
|
293 | + |
|
294 | +#### IPv4 |
|
295 | + |
|
296 | +``` |
|
297 | +/ip address |
|
298 | +add address=192.168.200.130/30 interface=gre-dn42-peer network=192.168.200.128 |
|
299 | +``` |
|
300 | + |
|
301 | +#### IPv6 |
|
302 | +Here we can use /127, so it's simple: |
|
303 | + |
|
304 | +``` |
|
305 | +/ipv6 address |
|
306 | +add address=fdc8:c633:5319:3300::41/127 advertise=no interface=gre-dn42-peer |
|
307 | +``` |
|
308 | + |
|
309 | +If you configured everything correctly, you should be able to ping |
|
310 | + |
|
311 | +## BGP |
|
312 | + |
|
313 | +### Filters |
|
314 | +Both BGP and routing filters were redone from the ground up on RoS 7.x |
|
315 | +The official migration guide can be found [here](https://help.mikrotik.com/docs/display/ROS/Routing) |
|
316 | + |
|
317 | +It's a good idea to setup filters for BGP instances, both IN (accept advertises) and OUT (send advertises) |
|
318 | +In this example, we will be filtering IN: 192.168.0.0/16 and 169.254.0.0/16 |
|
319 | +OUT: 192.168.0.0/16 and 169.254.0.0/16, you really don't want to advertise this networks. |
|
320 | +This filter will not only catch /8 or /16 networks, but smaller networks inside this subnets as well. |
|
321 | + |
|
322 | +#### RoS 6.x |
|
323 | +``` |
|
324 | +/routing filter |
|
325 | +add action=discard address-family=ip chain=dn42-in prefix=192.168.0.0/16 prefix-length=16-32 protocol=bgp |
|
326 | +add action=discard address-family=ip chain=dn42-in prefix=169.254.0.0/16 prefix-length=16-32 protocol=bgp |
|
327 | +add action=discard address-family=ip chain=dn42-out prefix=192.168.0.0/16 prefix-length=16-32 protocol=bgp |
|
328 | +add action=discard address-family=ip chain=dn42-out prefix=169.254.0.0/16 prefix-length=16-32 protocol=bgp |
|
329 | +``` |
|
330 | + |
|
331 | +If you want only DN42 connection, you can filter IN 10.0.0.0/8 (ChaosVPN / freifunk networks): |
|
332 | + |
|
333 | +``` |
|
334 | +/routing filter |
|
335 | +add action=discard address-family=ip chain=dn42-in prefix=10.0.0.0/8 prefix-length=8-32 protocol=bgp |
|
336 | +``` |
|
337 | + |
|
338 | +#### RoS 7.x |
|
339 | +``` |
|
340 | +/routing filter rule |
|
341 | +add chain=dn42-in rule="if (dst in 192.168.0.0/16 && dst-len > 16) { reject }" |
|
342 | +add chain=dn42-in rule="if (dst in 169.254.0.0/1 && dst-len > 16) { reject }" |
|
343 | +add chain=dn42-out rule="if (dst in 192.168.0.0/16 && dst-len > 16) { reject }" |
|
344 | +add chain=dn42-out rule="if (dst in 169.254.0.0/1 && dst-len > 16) { reject }" |
|
345 | +``` |
|
346 | + |
|
347 | +If you want only DN42 connection, you can filter IN 10.0.0.0/8 (ChaosVPN / freifunk networks): |
|
348 | + |
|
349 | +``` |
|
350 | +/routing filter |
|
351 | +add chain=dn42-in rule="if (dst in 10.0.0.0 && dst-len > 8) { reject }" |
|
352 | + |
|
353 | +``` |
|
354 | + |
|
355 | +### BGP |
|
356 | +Now, for actual BGP configuration. |
|
357 | + |
|
358 | +#### RoS v6 |
|
359 | +``` |
|
360 | +/routing bgp instance |
|
361 | +set default disabled=yes |
|
362 | +add as=YOUR_AS client-to-client-reflection=no name=bgp-dn42-somename out-filter=dn42-in router-id=1.1.1.1 |
|
363 | +``` |
|
364 | +Let's add some peers. Right now we have just one, but we still need two connections - to IPv4 and IPv6 |
|
365 | + |
|
366 | +IPv4: |
|
367 | +``` |
|
368 | +/routing bgp peer |
|
369 | +add comment="DN42: somepeer IPv4" in-filter=dn42-in instance=bgp-dn42-somename multihop=yes \ |
|
370 | +name=dn42-somepeer-ipv4 out-filter=dn42-out remote-address=192.168.200.129 remote-as=PEER_AS \ |
|
371 | +route-reflect=yes ttl=default |
|
372 | +``` |
|
373 | +IPv6 (if needed): |
|
374 | + |
|
375 | +``` |
|
376 | +/routing bgp peer |
|
377 | +add address-families=ipv6 comment="DN42: somepeer IPv6" in-filter=dn42-in \ |
|
378 | +instance=bgp-dn42-somename multihop=yes name=dn42-somepeer-ipv6 out-filter=dn42-out \ |
|
379 | +remote-address=fd42:c644:5222:3222::40 remote-as=PEER_AS route-reflect=yes ttl=default |
|
380 | +``` |
|
381 | + |
|
382 | +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. |
|
383 | + |
|
384 | +#### BGP Advertisements |
|
385 | +You want to advertise your allocated network (most likely), it's very simple: |
|
386 | + |
|
387 | +``` |
|
388 | +/routing bgp network |
|
389 | +add network=YOUR_ALLOCATED_SUBNET synchronize=no |
|
390 | +``` |
|
391 | +You can repeat that with as much IPv4 and IPv6 networks which you own. |
|
392 | + |
|
393 | +#### RoS 7.x |
|
394 | + |
|
395 | +First difference from v 6.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. |
|
396 | + |
|
397 | +Adding a network list: |
|
398 | +``` |
|
399 | +IPv4 |
|
400 | +/ip firewall address-list |
|
401 | +add address=YOUR_ALLOCATED_SUBNET list=DN42_allocated_v4 |
|
402 | + |
|
403 | +IPv6 |
|
404 | +/ipv6 firewall address-list |
|
405 | +add address=YOUR_ALLOCATED_SUBNET list=DN42_allocated_v6 |
|
406 | +``` |
|
407 | + |
|
408 | +Adding a static route to your full allocated network: |
|
409 | +``` |
|
410 | +/ipv6 route |
|
411 | +add blackhole disabled=no distance=1 dst-address=YOUR_ALLOCATED_SUBNET |
|
412 | +``` |
|
413 | + |
|
414 | +Let's create a template for DN42. It isn't strictly necessary, but makes our life easier. |
|
415 | +``` |
|
416 | +/routing bgp template |
|
417 | +add afi=ipv4 as=YOUR_AS_NUMBER name=DN42_template_v4 output.network=DN42_allocated_v4 router-id=1.1.1.1 |
|
418 | +add afi=ipv6 as=YOUR_AS_NUMBER name=DN42_template_v6 output.network=DN42_allocated_v6 router-id=1.1.1.1 |
|
419 | +``` |
|
420 | + |
|
421 | +Now is time to add one peer: |
|
422 | + |
|
423 | +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". |
|
424 | + |
|
425 | +RoS 7.17 and newer can set the link local address. |
|
426 | + |
|
427 | + |
|
428 | +``` |
|
429 | +IPv4 peer |
|
430 | +add address-families=ipv4 disabled=no input.filter=dn42-in \ |
|
431 | +local.address=ADDRESS_YOUR_PEER_USE_TO_CONNECT_ON_YOU .role=ebgp \ |
|
432 | +multihop=yes name=PEER_NAME output.filter-chain=dn42-out \ |
|
433 | +.network=DN42_allocated_v4 remote.address=YOUR_PEER_REMOTE_ADDRESS \ |
|
434 | +.as=PEER_AS_NUMBER routing-table=main templates=DN42_template_v4 |
|
435 | + |
|
436 | +IPv6 peer |
|
437 | +add address-families=ipv6 disabled=no input.filter=dn42-in \ |
|
438 | +local.address=ADDRESS_YOUR_PEER_USE_TO_CONNECT_ON_YOU .role=ebgp \ |
|
439 | +multihop=yes name=PEER_NAME output.filter-chain=dn42-out \ |
|
440 | +.network=DN42_allocated_v6 remote.address=YOUR_PEER_REMOTE_ADDRESS \ |
|
441 | +.as=PEER_AS_NUMBER routing-table=main templates=DN42_template_v6 |
|
442 | +``` |
|
443 | + |
|
444 | + |
|
445 | +## Split DNS |
|
446 | +Separate dns requests for dn42 tld from your default dns traffic with L7 filter in Mikrotik. |
|
447 | +Change network and LAN GW to mach your network configuration. |
|
448 | + |
|
449 | +``` |
|
450 | +/ip firewall layer7-protocol |
|
451 | +add name=DN42-DNS regexp="\\x04dn42.\\x01" |
|
452 | +/ip firewall nat |
|
453 | +add action=src-nat chain=srcnat comment="NAT to DN42 DNS" dst-address=172.23.0.53 dst-port=53 protocol=udp src-address=192.168.0.0/24 to-addresses=192.168.0.1 |
|
454 | +add action=dst-nat chain=dstnat dst-address-type=local dst-port=53 layer7-protocol=DN42-DNS protocol=udp src-address=192.168.0.0/24 to-addresses=172.23.0.53 to-ports=53 |
|
455 | + |
|
456 | +``` |
|
457 | +Since version 6.47 have added functionality that can redirect DNS queries according to special rules. If you used to do Layer-7 rules in the firewall, now it's simple and elegant: |
|
458 | +``` |
|
459 | +/ip dns static |
|
460 | +add comment=DN42 forward-to=172.23.0.53 regexp=".*\\.dn42" type=FWD |
|
461 | +``` |
|
462 | + |
|
463 | +## Specifying BGP Communities (v7) |
|
232 | 464 | |
233 | 465 | ``` |
234 | 466 | /routing/filter/community-list |
... | ... | @@ -237,4 +469,4 @@ add list=dn42 communities=64511:5 |
237 | 469 | |
238 | 470 | /routing/filter/rule/ |
239 | 471 | add chain=dn42-out rule="append bgp-communities dn42" |
240 | -``` |
|
472 | +``` |
|
... | ... | \ No newline at end of file |