Mikrotik

Collection of notes for running a Mikrotik Router


SSH

Generate a key, which must be RSA (I prefer ed25519 but it’s not supported so make the key size large)

ssh-keygen -t rsa -b 4096 -f ~/.ssh/mikrotik

Copy the public key to the router.

scp ~/.ssh/mikrotik.pub admin@192.168.88.1:/mikrotik.pub
ssh \
  admin@192.168.88.1 \
  '/user ssh-keys import user=admin public-key-file=/mikrotik.pub

In ~/.ssh/config configure the PubkeyAcceptedAlgorithms setting to make your client will do RSA.

Host router.lan
    Hostname 192.168.88.1
    IdentityFile ~/.ssh/mikrotik.pub
    PubkeyAcceptedAlgorithms +ssh-rsa

Firewall

References

Filter

The firewall filters are a list of commands executed in order that describe how to handle packets in the firewall.

Filter Concepts:

  1. Chains
  2. Actions
  3. Other Filter Options…

Chains

Chains describe the logical flow that the router uses to handle specific types of packets.

chaindescription
inputhandles packets going into the router
outputhandles packets going out of the router (originating from router)
forwardhandles packets going through the router

Actions

The action tells a filter what do do with a packet at the current filter step.

actiondescription
rejectRespond with a reject “error message”
dropSilently drop the packet. Clients will assume router is unreachable.
acceptAccept the packet
fasttrack connectionSkip all next firewall rules and push packet out quickely.
passthrough
return
tarpit
jump
log
add dst to address list
add src to address list

Other Filter Options

Scripting

Idempotent Updates

Update if entry was not found.

:put [/ip firewall address-list find where list=cloudflare address=131.0.72.0/22]

:if ([:len [/ip firewall address-list find where list=dns address=1.1.1.1]]=0) do={
  /ip firewall address-list add list=dns address=1.1.1.1 comment="Cloudflare dns"
}

Check for a single entry.

:put [/ip firewall address-list get [find where list=cloudflare address=131.0.72.0/22]]

:if ([/ip firewall address-list get [find where list=cloudflare address=131.0.72.0/22]]) do={
  :put "yes i found it"
}