I have the following scenario:
I would like your help to get as close as possible to @Anav's "DEFACTO DEFAULT FIREWALL Setup" with failover using recursive routing and policy based routing (PBR).
I don´t know even if this is possible. I´m still learning...
My start point was the new documentation at https://help.mikrotik.com/docs/display/ ... figuration
Failover with recursive routing appears to be working. But I put gateway IP from ISP-2 "manually". I don´t know how to "automate" this task. At some point ISP-2 gateway IP will change.
Need to do PBR and whatever suggestions you have to improve this configuration.
Another thing I don´t fully understand is: using PBR will clients of the failed ISP automatically use the other? And what about clients that aren´t in any of the lists, for example a guest that gets an IP from DHCP pool? Which ISP they will use?
---
Code: Select all
# make sure you have absolutely clean router
/system reset-configuration no-defaults=yes skip-backup=yes
# create a new admin account, remove default admin account, disconnect and connect with your new admin account
/user add name=<your_choosen_username> password=<password> group=full
/user remove admin
# rename interfaces for better visualization/understanding
/interface ethernet set [ find default-name=ether1 ] name=ether1_ISP-1
/interface ethernet set [ find default-name=ether2 ] name=ether2_ISP-2
/interface ethernet set [ find default-name=ether3 ] name=ether3_LAN-A
/interface ethernet set [ find default-name=ether4 ] name=ether4_LAN-B
/interface ethernet set [ find default-name=ether5 ] name=ether5_LAN-C
# some interface lists for better visualization/understanding/configuration
/interface list add name=WAN_list
/interface list member add list=WAN_list interface=ether1_ISP-1
/interface list member add list=WAN_list interface=ether2_ISP-2
/interface list add name=LAN_list
/interface list member add list=LAN_list interface=ether3_LAN-A
/interface list member add list=LAN_list interface=ether4_LAN-B
/interface list member add list=LAN_list interface=ether5_LAN-C
/interface list add name=trusted_list
/interface list member add list=trusted_list interface=ether3_LAN-A
# some protection and services configuration
/tool mac-server set allowed-interface-list=trusted_list
/tool mac-server mac-winbox set allowed-interface-list=trusted_list
/tool bandwidth-server set enabled=no
/ip neighbor discovery-settings set discover-interface-list=trusted_list
/ip service disable api,api-ssl,ftp,telnet,www
/ip service set ssh port=<port for SSH>
/ip service set winbox port=<port for WinBox>
/ip proxy set enabled=no
/ip socks set enabled=no
/ip upnp set enabled=no
/ip cloud set ddns-enabled=no update-time=no
/ip ssh set strong-crypto=yes
# set public static IP on ISP-1
/ip address add interface=ether1_ISP-1 address=a.b.c.d/24
# get public DHCP IP from ISP-2
/ip dhcp-client add interface=ether2_ISP-2 disabled=no add-default-route=no use-peer-dns=no use-peer-ntp=no
# set LAN IPs
/ip address add interface=ether3_LAN-A address=10.22.22.10/24 network=10.22.22.0
/ip address add interface=ether4_LAN-B address=172.16.1.172/24 network=172.16.1.0
/ip address add interface=ether5_LAN-C address=192.168.1.192/24 network=192.168.1.0
# disable sfp1 interface
/interface set sfp1 disabled=yes
# set dns
/ip dns set servers=1.1.1.1,8.8.8.8 allow-remote-requests=yes
# define pools for LAN DHCP
/ip pool add name=LAN-A_pool ranges=10.22.22.230-10.22.22.250
/ip pool add name=LAN-B_pool ranges=172.16.1.230-172.16.1.250
/ip pool add name=LAN-C_pool ranges=192.168.1.230-192.168.1.250
# define some static DHCP leases
/ip dhcp-server lease add address=10.22.22.1 mac-address=B8:27:EB:BD:59:19
/ip dhcp-server lease add address=10.22.22.2 mac-address=DC:A6:32:68:FD:5C
/ip dhcp-server lease add address=10.22.22.3 mac-address=DC:A6:32:03:51:6D
# configure DHCP servers
/ip dhcp-server add address-pool=LAN-A_pool interface=ether3_LAN-A lease-time=2d name=DHCP_for_LAN-A
/ip dhcp-server add address-pool=LAN-B_pool interface=ether4_LAN-B lease-time=2d name=DHCP_for_LAN-B
/ip dhcp-server add address-pool=LAN-C_pool interface=ether5_LAN-C lease-time=2d name=DHCP_for_LAN-C
/ip dhcp-server network add address=10.22.22.0/24 gateway=10.22.22.10 dns-server=10.22.22.10
/ip dhcp-server network add address=172.16.1.0/24 gateway=172.16.1.172 dns-server=172.16.1.172
/ip dhcp-server network add address=192.168.1.0/24 gateway=192.168.1.192 dns-server=192.168.1.192
# create ISP routing tables for PBR
/routing table add disabled=no fib name=route_to_ISP-1
/routing table add disabled=no fib name=route_to_ISP-2
# create some addresses lists
/ip firewall address-list add address=10.0.0.0/8 list=RFC1918
/ip firewall address-list add address=172.16.0.0/12 list=RFC1918
/ip firewall address-list add address=192.168.0.0/16 list=RFC1918
/ip firewall address-list add address=10.22.22.1 list=clients_to_ISP-1
/ip firewall address-list add address=10.22.22.2 list=clients_to_ISP-2
/ip firewall address-list add address=10.22.22.3 list=clients_to_ISP-2
# firewall stuff
/ip firewall filter add chain=input connection-state=established,related action=accept
/ip firewall filter add chain=input connection-state=invalid action=drop
/ip firewall filter add chain=input in-interface-list=WAN_list protocol=icmp action=accept
/ip firewall filter add chain=input in-interface-list=WAN_list protocol=tcp port=<port for SSH> action=accept
/ip firewall filter add chain=input in-interface-list=WAN_list protocol=tcp port=<port for WinBox> action=accept
/ip firewall filter add chain=input in-interface-list=WAN_list action=drop
# marks for PBR - disabled for now as I can't get it to work correctly
#/ip firewall mangle add action=mark-routing chain=prerouting dst-address-list=!RFC1918 in-interface-list=LAN_list new-routing-mark=route_to_ISP-1 passthrough=no src-address-list=clients_to_ISP-1
#/ip firewall mangle add action=mark-routing chain=prerouting dst-address-list=!RFC1918 in-interface-list=LAN_list new-routing-mark=route_to_ISP-2 passthrough=no src-address-list=clients_to_ISP-2
/ip firewall nat add chain=srcnat out-interface-list=WAN_list action=masquerade
/ip firewall filter add chain=forward action=fasttrack-connection connection-state=established,related
/ip firewall filter add chain=forward action=accept connection-state=established,related
/ip firewall filter add chain=forward action=drop connection-state=invalid
/ip firewall filter add chain=forward action=drop connection-state=new connection-nat-state=!dstnat in-interface-list=WAN_list
# failover with recursive routing
ip route add dst-address=1.0.0.1 scope=10 gateway=<ISP-1 gateway>
ip route add distance=5 gateway=1.0.0.1 check-gateway=ping target-scope=11
ip route add dst-address=8.8.4.4 scope=10 gateway=<ISP-2 gateway>
ip route add distance=7 gateway=8.8.4.4 check-gateway=ping target-scope=11
# ntp stuff
/system clock set time-zone-autodetect=no time-zone-name=<your time zone>
/system ntp client set enabled=yes
/system ntp client servers add address=<ntp server address>
/system ntp client servers add address=<ntp server address>