# MikroTik

# Routers

Setup Guides for MikroTik Routers

# MikroTik hAP ax³ Setup Guide

This guide will walk you through setting up a MikroTik hAP ax³ router with the following features:

- **Two SSIDs**: Home and Guest
- **Three VLANs**: Home, Guest, and IoT
- **PPSK (Private Pre-Shared Key)**: Different keys for Home and IoT networks
- **Firewall Rules**: Optimized for streaming and gaming

### Prerequisites

1. **MikroTik hAP ax³**: Ensure your router is powered on and connected to your network.
2. **Winbox or Web Interface**: Use Winbox or a web browser to access the router's management interface.
3. **Basic Network Setup**: Have an existing internet connection.

### Step-by-Step Setup

#### Step 1: Access MikroTik Router

1. **Open Winbox**: Connect to your MikroTik router using Winbox or the web interface at `http://192.168.88.1`.
2. **Log in**: Use the default username `admin` and no password (change this immediately after login for security).

#### Step 2: Update RouterOS

1. **Navigate to**: System &gt; Packages.
2. **Check for updates**: Click on **Check for Updates** and apply any available updates to ensure you have the latest RouterOS version.

#### Step 3: Create VLANs

1. **Navigate to**: Interfaces &gt; VLANs.
2. **Create VLANs** for Home, Guest, and IoT.

**Home VLAN**

- **Name**: Home
- **VLAN ID**: 10
- **Interface**: Select the interface connected to your network.

**Guest VLAN**

- **Name**: Guest
- **VLAN ID**: 20
- **Interface**: Select the interface connected to your network.

**IoT VLAN**

- **Name**: IoT
- **VLAN ID**: 30
- **Interface**: Select the interface connected to your network.

#### Step 4: Configure Bridge and VLAN Filtering

1. **Navigate to**: Bridge &gt; Add a new bridge.

**Bridge Settings**

- **Name**: bridge1

2. **Add VLANs to the Bridge**: 
    - Go to Bridge &gt; VLANs.
    - Add each VLAN to the bridge with the respective VLAN ID and ports.

#### Step 5: Set Up Wireless Networks (SSIDs)

1. **Navigate to**: Wireless &gt; Add new.

**Home SSID**

- **Name**: Home
- **SSID**: Home
- **Security Profile**: Create a new profile with WPA2-PSK.
- **VLAN ID**: 10

**Guest SSID**

- **Name**: Guest
- **SSID**: Guest
- **Security Profile**: Create a new profile with WPA2-PSK.
- **VLAN ID**: 20

2. **Configure PPSK for Home Network**: 
    - Navigate to Wireless &gt; Security Profiles.
    - Create separate security profiles for each key associated with VLAN 10 and VLAN 30.

#### Step 6: Configure DHCP Servers

1. **Navigate to**: IP &gt; DHCP Server.
2. **Create DHCP servers** for each VLAN:

**Home VLAN DHCP**

- **Interface**: VLAN10
- **Address Pool**: Create an address pool for VLAN 10.

**Guest VLAN DHCP**

- **Interface**: VLAN20
- **Address Pool**: Create an address pool for VLAN 20.

**IoT VLAN DHCP**

- **Interface**: VLAN30
- **Address Pool**: Create an address pool for VLAN 30.

#### Step 7: Configure Firewall Rules

1. **Navigate to**: IP &gt; Firewall &gt; Filter Rules.
2. **Create firewall rules** to optimize streaming and gaming:

**Allow Streaming Services**

- **Chain**: forward
- **Action**: accept
- **Src. Address List**: Create an address list for streaming services.

**Allow Gaming Services**

- **Chain**: forward
- **Action**: accept
- **Src. Address List**: Create an address list for gaming services.

**Deny Other Traffic**

- **Chain**: forward
- **Action**: drop
- **Log**: enabled (for troubleshooting purposes).

3. **Prioritize Traffic**: 
    - Use **Mangle** rules to mark packets from specific devices and apply **Queue Trees** to prioritize gaming and streaming traffic.

#### Step 8: Test the Configuration

1. **Connect devices** to the Home and Guest SSIDs.
2. **Test connectivity** to ensure devices are assigned to the correct VLANs.
3. **Verify streaming and gaming performance** to ensure traffic is prioritized correctly.

### Additional Tips

- **Secure Access**: Change the default admin password and secure management access.
- **Regular Backups**: Save your configuration regularly to avoid data loss.
- **Firmware Updates**: Keep your RouterOS and firmware up-to-date for security and performance.

[https://mikrotik.com/product/hap\_ax3](https://mikrotik.com/product/hap_ax3)

# Creating an Option 43 Entry - Ruckus

<details id="bkmrk-introduction-this-op"><summary>Introduction</summary>

This option is used by clients and servers to exchange vendor-specific information. Servers that are not equipped to interpret the information ignore it. Clients that expect but don't receive the information attempt to operate without it.

Option 43 can be especially helpful for pointing Ruckus access points to controller (ZoneDirector or SCG/SZ). The resolution to configure Option 43 is explained below.

</details><details id="bkmrk-method---obtaining-y"><summary>Method - Obtaining your Value</summary>

You will need to know the following prefix both ZoneDirector(s) and SmartCell Gateway/SmartZone(s).

- Zone Director: 0x30c
- SCG/SZ: 0x60c or 0x60f

You will also need to convert the ASCII text of your controller IP address to HEX. I use the following site for converting but feel free to use whichever you like.

- [https://www.rapidtables.com/convert/number/ascii-to-hex.html](https://www.rapidtables.com/convert/number/ascii-to-hex.html)

An example of the HEX converter:

[![image.png](https://techblog.jcditservices.com/uploads/images/gallery/2024-08/scaled-1680-/bKTimage.png)](https://techblog.jcditservices.com/uploads/images/gallery/2024-08/bKTimage.png)

Putting these together will give you your 'value'. For example:

To point a Ruckus AP to a SCG/SZ to example IP 31.3.221.203 would be: 0x60c + 33312e332e3232312e323033 = **0x60c33312e332e3232312e32303**

To point a Ruckus AP to a ZD to IP 192.168.1.1 would be: 0x30c + 3139322e3136382e312e31 = **0x30c3139322e3136382e312e31**

</details><details id="bkmrk-method---setting-thi"><summary>Method - Setting this in the MikroTik</summary>

For the purpose of this article I will assume you have a minimal/basic understanding of the device and know how to login to the MikroTik device.

Open your MikroTik router in Winbox or Webfig. Browse to: **IP** &gt; **DHCP Server** &gt; **Options** &gt; Click the blue '**+**' to create a new profile

Provide the following:

- Name: Defined by yourself
- Code: This MUST be 43
- Value: Defined by your obtained value

Click 'Apply' and then 'OK'.

This then needs to be applied too your network address. To do this go to: **IP** &gt; **DHCP Server** &gt; **Networks** &gt; Double click the network required (the ones which your AP's will be on) &gt; On **DHCP Options** click the dropdown and select the profile.

Any AP's now connected to this network should be pointed towards the controller, and appear in their Staging Zone or on the ZD pending any auto provision rules setup on the controller.

</details>

# Setting Up Port Forwarding for IPSEC IKE Tunnel

<details id="bkmrk-introduction-port-fo"><summary>Introduction</summary>

- Port forwarding, also known as tunnelling, is a network technology procedure that enables external devices to access services on a private network. This is achieved by rerouting communication requests from one address and port number combination to another while packets traverse a network gateway.
- It is extensively used in scenarios where certain applications or services need to be accessible from the internet, including online gaming, torrent downloads, and hosting web servers. These applications typically require direct communication with devices on your private network, which isn’t possible due to NAT (Network Address Translation) mechanisms used by most routers.
- While port forwarding can grant outside access and improve connectivity, it also presents a potential risk as it exposes your internal network to the internet. As such, it’s crucial to exercise due caution by only forwarding necessary ports and implementing robust security measures such as using strong, complex passwords and up-to-date firewall settings.

</details><details id="bkmrk-method-step-1%3A-acces"><summary>Method</summary>

**<span style="font-size: 13.5pt; mso-ligatures: none; mso-fareast-language: EN-GB;">Step 1: Access MikroTik Router</span>**

1. <span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Open Winbox or your web browser and connect to your MikroTik router.</span>
2. <span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Log in using your credentials.</span>

**<span style="font-size: 13.5pt; mso-ligatures: none; mso-fareast-language: EN-GB;">Step 2: Configure Port Forwarding</span>**

1. **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Go to IP &gt; Firewall &gt; NAT</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">.</span>
2. <span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Click on the **+** to add a new rule.</span>

**<span style="font-size: 12.0pt; mso-ligatures: none; mso-fareast-language: EN-GB;">1. Port Forwarding for UDP Port 500 (IKE)</span>**

- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">General Tab</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">:</span>
- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Chain</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">: </span><span style="font-size: 10.0pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">dstnat</span>
- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Protocol</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">: </span><span style="font-size: 10.0pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">udp</span>
- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Dst. Port</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">: </span><span style="font-size: 10.0pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">500 (this may change, request from the client what is needed. Also ensure that it does not interfere with any existing ports configured)</span>

- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Action Tab</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">:</span>
- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Action</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">: </span><span style="font-size: 10.0pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">dst-nat</span>
- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">To Addresses</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">: Internal IP address (e.g., 192.168.1.2)</span>
- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">To Ports</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">: </span><span style="font-size: 10.0pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">500 (this may change, request from the client what is needed. Also ensure that it does not interfere with any existing ports configured)</span>


**<span style="font-size: 12.0pt; mso-ligatures: none; mso-fareast-language: EN-GB;">2. Port Forwarding for UDP Port 4500 (NAT-T)</span>**

- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">General Tab</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">:</span>
- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Chain</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">: </span><span style="font-size: 10.0pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">dstnat</span>
- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Protocol</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">: </span><span style="font-size: 10.0pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">udp</span>
- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Dst. Port</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">: </span><span style="font-size: 10.0pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">4500 (this may change, request from the client what is needed. Also ensure that it does not interfere with any existing ports configured)</span>

- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Action Tab</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">:</span>
- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Action</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">: </span><span style="font-size: 10.0pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">dst-nat</span>
- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">To Addresses</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">: Internal IP address (e.g., 192.168.1.2)</span>
- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">To Ports</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">: </span><span style="font-size: 10.0pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">4500 (this may change, request from the client what is needed. Also ensure that it does not interfere with any existing ports configured)</span>


**<span style="font-size: 13.5pt; mso-ligatures: none; mso-fareast-language: EN-GB;">Step 3: Configure Firewall Rules</span>**

1. **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Go to IP &gt; Firewall &gt; Filter Rules</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">.</span>
2. <span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Click on the **+** to add new rules.</span>

**<span style="font-size: 12.0pt; mso-ligatures: none; mso-fareast-language: EN-GB;">1. Allow UDP Port 500 (IKE)</span>**

- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">General Tab</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">:</span>
- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Chain</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">: </span><span style="font-size: 10.0pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">forward</span>
- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Protocol</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">: </span><span style="font-size: 10.0pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">udp</span>
- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Dst. Port</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">: </span><span style="font-size: 10.0pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">500 (this may change, request from the client what is needed. Also ensure that it does not interfere with any existing ports configured)</span>

- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Action Tab</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">:</span>
- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Action</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">: </span><span style="font-size: 10.0pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">accept</span>


**<span style="font-size: 12.0pt; mso-ligatures: none; mso-fareast-language: EN-GB;">2. Allow UDP Port 4500 (NAT-T)</span>**

- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">General Tab</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">:</span>
- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Chain</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">: </span><span style="font-size: 10.0pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">forward</span>
- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Protocol</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">: </span><span style="font-size: 10.0pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">udp</span>
- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Dst. Port</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">: </span><span style="font-size: 10.0pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">4500 (this may change, request from the client what is needed. Also ensure that it does not interfere with any existing ports configured)</span>

- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Action Tab</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">:</span>
- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Action</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">: </span><span style="font-size: 10.0pt; font-family: 'Courier New'; mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">accept</span>


**<span style="font-size: 13.5pt; mso-ligatures: none; mso-fareast-language: EN-GB;">Step 4: Sort the Filter Rules</span>**

- <span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Drag and drop the filter rules you have created in **Step 3** so that they are above any existing 'drop rules'.</span>

**<span style="font-size: 13.5pt; mso-ligatures: none; mso-fareast-language: EN-GB;">Step 5: Ensure IP Forwarding is Enabled</span>**

1. **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Go to IP &gt; Settings</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">.</span>
2. <span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Make sure **IP Forwarding** is enabled.</span>

**<span style="font-size: 13.5pt; mso-ligatures: none; mso-fareast-language: EN-GB;">Step 6: Verify Configuration</span>**

1. **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Check the NAT Rules</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">:</span>

- <span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Ensure the NAT rules are correctly set up and active.</span>
- <span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Go to **IP &gt; Firewall &gt; NAT** and verify that the new rules are listed and active.</span>
- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Check the Firewall Rules</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">:</span>

- <span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Ensure the firewall rules are correctly set up and active.</span>
- <span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Go to **IP &gt; Firewall &gt; Filter Rules** and verify that the new rules are listed and active.</span>
- **<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Test the VPN Connection</span>**<span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">:</span>

- <span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Attempt to establish the VPN connection from the internal router to Azure.</span>
- <span style="mso-fareast-font-family: 'Times New Roman'; mso-ligatures: none; mso-fareast-language: EN-GB;">Verify the connection by checking the VPN status on the internal router.</span>

</details>

# MikroTik Router Setup Guide with Multiple WAN Connections (SD-WAN) and VLAN Configuration

This guide will help you configure your MikroTik router with the following features:

- **Introduction to Multiple WAN Connections (SD-WAN)**
- **Three WAN Connections**: Fiber (Primary), 5G, and Starlink
- **Load Balancing and Failover**: Prioritize Fiber connection
- **Three VLANs**: Home, Guest, and IoT
- **Firewall Rules**: Optimized for streaming and gaming
- **Traffic Prioritization**: Using Quality of Service (QoS)

---

### **Prerequisites**

- **MikroTik Router**: Ensure your device supports the necessary features (e.g., RB4011, CCR series).
- **Access to Router Management Interface**: Use Winbox or WebFig to configure the router.
- **WAN Connections**: Have your Fiber, 5G, and Starlink connections physically connected to the router.
- **Basic Network Knowledge**: Familiarity with network configurations and terms.

---

### **Step-by-Step Setup**

#### **Step 1: Access the MikroTik Router**

1. **Connect to the Router**: Use an Ethernet cable to connect your computer to the router.
2. **Open Winbox**: Download from the MikroTik website if you haven't already.
3. **Login**: 
    - **MAC Address**: Use the MAC address to connect if the IP is not set.
    - **Default Username**: `admin`
    - **Default Password**: *(Leave blank initially; change immediately for security)*

---

#### **Step 2: Configure WAN Interfaces**

Identify the interfaces connected to your WAN connections.

**Assign Names to WAN Interfaces**

1. **Fiber Connection (Primary)**
    - **Interface**: e.g., `ether1`
    - **Name**: `WAN_Fiber`
2. **5G Connection**
    - **Interface**: e.g., `ether2`
    - **Name**: `WAN_5G`
3. **Starlink Connection**
    - **Interface**: e.g., `ether3`
    - **Name**: `WAN_Starlink`

**Configure IP Addresses for WAN Interfaces**

1. **Go to**: `IP > DHCP Client`
2. **Add DHCP Client** for each WAN interface: 
    - **Interface**: `WAN_Fiber`
    - **Use Peer DNS**: Yes
    - **Add Default Route**: No *(We'll set routes manually)*
    - Repeat for `WAN_5G` and `WAN_Starlink`

---

#### **Step 3: Configure Load Balancing and Failover**

We'll set up routing rules to prioritize the Fiber connection and use the 5G and Starlink as backups.

**Set Default Routes with Different Distances**

1. **Go to**: `IP > Routes`
2. **Add Route for Fiber Connection**
    - **Destination Address**: `0.0.0.0/0`
    - **Gateway**: Select the gateway provided by the DHCP client on `WAN_Fiber` (e.g., `WAN_Fiber` interface)
    - **Distance**: `1` *(Primary connection)*
3. **Add Route for 5G Connection**
    - **Destination Address**: `0.0.0.0/0`
    - **Gateway**: Select the gateway from `WAN_5G`
    - **Distance**: `2`
4. **Add Route for Starlink Connection**
    - **Destination Address**: `0.0.0.0/0`
    - **Gateway**: Select the gateway from `WAN_Starlink`
    - **Distance**: `3`

**Set Up Check Gateway**

1. **Edit Each Route**: Enable `Check Gateway` with `ping` to monitor the connection. 
    - This allows the router to detect when a connection is down and automatically switch to the next available connection.

---

#### **Step 4: Configure VLANs**

**Create VLAN Interfaces**

1. **Go to**: `Interfaces`
2. **Click**: `+` (Add New Interface) 
    - **Type**: `VLAN`

**Home VLAN**

- **Name**: `VLAN_Home`
- **VLAN ID**: `10`
- **Interface**: Physical interface connected to your switch (e.g., `ether5`)

**Guest VLAN**

- **Name**: `VLAN_Guest`
- **VLAN ID**: `20`
- **Interface**: `ether5`

**IoT VLAN**

- **Name**: `VLAN_IoT`
- **VLAN ID**: `30`
- **Interface**: `ether5`

**Configure Bridge Interface**

If using multiple VLANs on a single physical interface, it's good practice to use a bridge.

1. **Go to**: `Bridge`
2. **Add New Bridge**
    - **Name**: `BR_LAN`
3. **Add Ports to Bridge**
    - **Go to**: `Bridge > Ports`
    - **Add**: `ether5` to `BR_LAN`
    - **Add**: `VLAN_Home`, `VLAN_Guest`, `VLAN_IoT` to `BR_LAN`

**Assign IP Addresses to VLAN Interfaces**

1. **Go to**: `IP > Addresses`
2. **Add New Address**

**Home VLAN**

- **Address**: `192.168.10.1/24`
- **Interface**: `VLAN_Home`

**Guest VLAN**

- **Address**: `192.168.20.1/24`
- **Interface**: `VLAN_Guest`

**IoT VLAN**

- **Address**: `192.168.30.1/24`
- **Interface**: `VLAN_IoT`

---

#### **Step 5: Configure DHCP Servers for Each VLAN**

1. **Go to**: `IP > DHCP Server`
2. **Click**: `DHCP Setup`

**Home VLAN DHCP**

- **Interface**: `VLAN_Home`
- **Follow the prompts** to set: 
    - **Address Pool**: `192.168.10.2-192.168.10.254`
    - **Gateway**: `192.168.10.1`
    - **DNS Servers**: Use your preferred DNS (e.g., `8.8.8.8`)

**Guest VLAN DHCP**

- **Interface**: `VLAN_Guest`
- **Address Pool**: `192.168.20.2-192.168.20.254`
- **Gateway**: `192.168.20.1`
- **DNS Servers**: `8.8.8.8`

**IoT VLAN DHCP**

- **Interface**: `VLAN_IoT`
- **Address Pool**: `192.168.30.2-192.168.30.254`
- **Gateway**: `192.168.30.1`
- **DNS Servers**: `8.8.8.8`

---

#### **Step 6: Configure Firewall Rules**

MikroTik uses a default firewall configuration; we'll modify it to suit our needs.

**Enable NAT for Internet Access**

1. **Go to**: `IP > Firewall > NAT`
2. **Add New NAT Rule**
    - **Chain**: `srcnat`
    - **Out Interface List**: `WAN` *(We'll create an interface list for WAN interfaces)*
    - **Action**: `masquerade`

**Create Interface List for WAN**

1. **Go to**: `Interfaces > Interface List`
2. **Add New List**
    - **Name**: `WAN`
    - **Add Interfaces**: `WAN_Fiber`, `WAN_5G`, `WAN_Starlink`

**Allow Traffic from VLANs to WAN**

1. **Go to**: `IP > Firewall > Filter Rules`
2. **Add New Rule**
    - **Chain**: `forward`
    - **Src. Address**: `192.168.10.0/24`, `192.168.20.0/24`, `192.168.30.0/24`
    - **Out Interface List**: `WAN`
    - **Action**: `accept`

**Drop Inter-VLAN Traffic**

1. **Add New Rule**
    - **Chain**: `forward`
    - **Src. Address List**: Create an address list for your VLAN subnets. 
        - **Name**: `VLAN_Networks`
        - **Addresses**: `192.168.10.0/24`, `192.168.20.0/24`, `192.168.30.0/24`
    - **Dst. Address List**: `VLAN_Networks`
    - **Action**: `drop`
    - **Place this rule before the rule that accepts established/related traffic.**

**Allow Established and Related Traffic**

1. **Ensure you have a rule to accept established and related connections**
    - **Chain**: `forward`
    - **Connection State**: `established, related`
    - **Action**: `accept`

**Drop Invalid Traffic**

1. **Add Rule**
    - **Chain**: `forward`
    - **Connection State**: `invalid`
    - **Action**: `drop`

---

#### **Step 7: Configure Traffic Prioritization (QoS)**

We'll use **Simple Queues** to prioritize gaming and streaming traffic.

**Identify Gaming and Streaming Traffic**

1. **Go to**: `IP > Firewall > Mangle`
2. **Add New Rule for Gaming Traffic**
    
    
    - **Chain**: `forward`
    - **Protocol**: Select protocols used by games (e.g., TCP/UDP ports)
    - **Dst. Port**: Add known gaming ports
    - **Action**: `mark-packet`
    - **New Packet Mark**: `Gaming_Traffic`
    - **Passthrough**: `yes`
3. **Add New Rule for Streaming Traffic**
    
    
    - **Chain**: `forward`
    - **Dst. Address List**: Create an address list for streaming services (e.g., Netflix IP ranges)
    - **Action**: `mark-packet`
    - **New Packet Mark**: `Streaming_Traffic`
    - **Passthrough**: `yes`

**Create Simple Queues**

1. **Go to**: `Queues > Simple Queues`

**Gaming Traffic Queue**

- **Name**: `Priority_Gaming`
- **Target**: `192.168.10.0/24` *(Assuming gaming devices are on the Home VLAN)*
- **Max Limit**: Set according to your bandwidth
- **Limit At**: Set minimum guaranteed bandwidth
- **Priority**: `1` *(Highest priority)*
- **Advanced Tab**: 
    - **Packet Marks**: `Gaming_Traffic`

**Streaming Traffic Queue**

- **Name**: `Priority_Streaming`
- **Target**: `192.168.10.0/24`
- **Max Limit**: Set according to your bandwidth
- **Limit At**: Set minimum guaranteed bandwidth
- **Priority**: `2`
- **Advanced Tab**: 
    - **Packet Marks**: `Streaming_Traffic`

---

#### **Step 8: Secure the Router**

**Change the Default Admin Password**

1. **Go to**: `System > Users`
2. **Edit**: `admin`
3. **Set a strong password**

**Disable Unnecessary Services**

1. **Go to**: `IP > Services`
2. **Disable** services you don't use (e.g., FTP, Telnet)
3. **Ensure Winbox and SSH are secured**

**Enable HTTPS for WebFig**

1. **Go to**: `IP > Services`
2. **Enable**: `www-ssl`
3. **Disable**: `www` (HTTP)

---

#### **Step 9: Test the Configuration**

- **VLAN Connectivity**: Connect devices to each VLAN and ensure they receive the correct IP addresses.
- **Internet Access**: Verify that devices can access the internet.
- **Failover**: Disconnect the Fiber connection to test if traffic fails over to 5G or Starlink.
- **Load Balancing**: Monitor traffic using `Tools > Torch` to see if load balancing works as expected.
- **QoS Effectiveness**: Use bandwidth-intensive applications to test if gaming and streaming traffic are prioritized.

---

### **Additional Tips**

- **Regular Backups**: Go to `Files`, select your configuration file, and download it to your computer.
- **Firmware Updates**: Check `System > Packages` for updates and upgrade to the latest stable version.
- **Monitor Traffic**: Use `Tools > Graphing` or `Queues > Queue Tree` to monitor bandwidth usage.
- **Logs**: Check `Log` for any errors or unusual activity.

---

By following this guide, you should have a MikroTik router configured with multiple WAN connections, VLAN segmentation, firewall rules, and QoS prioritization. The Fiber connection is set as the primary WAN, with 5G and Starlink serving as backup connections to ensure uninterrupted internet access.

---

**Note**: MikroTik routers are highly versatile but can be complex. Always make sure to back up your configuration before making significant changes, and consult the <a rel="noopener" target="_new">MikroTik Wiki</a> or <a rel="noopener" target="_new">Forums</a> if you encounter issues.

# Access Points

MikroTik Access Points and Setup Guides

# Switches

MikroTik switches , setup guides for RouterOS and SwitchOS

# RouterOS

Information Regarding MikroTik RouterOS

# Branding Maker

<details id="bkmrk-introduction-routero"><summary>Introduction</summary>

RouterOS allows slight system customization with the help of a branding package. This is a special system package, which you can generate from within your [mikrotik.com account](https://mikrotik.com/client/), in the account section "Branding maker". The resulting file will have a .dpk extension and can be installed by all the same means as an .npk package. The generated package can be installed in any RouterOS version. To install the package in a device you simply need to upload it and reboot the router, you can also use Netinstall tool for the same effect.

**ASCII logo**

This is the text logo shown when logging into the command line interface, i.e. Telnet, SSH, Winbox Terminal. The ASCII logo you can create right there in the browser, or copy from any other plaintext editor. Make sure it is not wider than the form in the branding maker page, or your logo will be distorted.

**Default webpage**

You can customize the default RouterOS information page, which shows up when accessing the router IP address, and a password is set on the device. When making the HTML file, you can use these variables:

<div class="wiki-content"><div class="wiki-content">- %version% will change to the router's current version
- %host% will change to the router's IP address. Use these variables in the Telnet link, or in the header.

</div></div>The file must be named "index2.html". Make sure you use properly nested HTML to make your page compatible with all browsers. You can also upload images or JavaScript files, they must reference to the same path as the index file, no custom folder names can be used.If you wish to only change the MikroTik logo, and not upload the whole HTML file, the name of the default image is mikrotik\_logo.png, uploading another file with the same name, will overwrite the original. Other values

<div class="wiki-content"><div class="wiki-content">- **Router name**: this is the Identity value in RouterOS, it can only be one word, don't use spaces or special characters there.
- **Company URL**: this is the value that appears in the console when you connect to your MikroTik device.
- **Manual URL**: documentation link which opens with a button in Webfig in the web interface.
- **LCD logo**: this will be displayed on devices equipped with LCD screen. Requirements for logo: no more than 160px width and no more than 72px height. CCR series have white (0xffffff) background, 2011 series have black (0x000000) background.
- **Default configuration**: Note that when using the default configuration file, the configuration is appended when simply installing the package, but after using system reset, only the configuration in your file will be used, all other standard default config will not be used during reset. The file must be a text/rsc file with one RouterOS command per line. You can use an export file from the console as a starting point, but we recommend only leaving the exact commands you want to run. This configuration will be kept even after the RouterOS reset.
- **Skins**: For skins, a file your\_file\_name.json must be uploaded into the "skins" directory.

<div class="confluence-information-macro confluence-information-macro-information conf-macro output-block" data-hasbody="true" data-macro-name="info"><div class="confluence-information-macro-body">  
</div></div></div></div>In order to apply particular skin to a specific user group, you don't need to log into the router to do that. You can do it with branding by uploading a Default configuration file.  
Or set the skin for the user group manually after reboot.

<div class="wiki-content" id="bkmrk-custom-files%3A-router"><div class="confluence-information-macro confluence-information-macro-information conf-macro output-block" data-hasbody="true" data-macro-name="info"><div class="confluence-information-macro-body">  
</div></div>- **Custom files**: RouterOS 6.48.3 and above also supports uploading of custom files, they will be simply copied into a folder named "branding" and will be accessible from within RouterOS.

</div><div id="bkmrk-"><div class="pageSection group" id="bkmrk--1"></div></div></details><details id="bkmrk-method-you-must-firs"><summary>Method</summary>

You must first log in to a MikroTik account: [https://mikrotik.com/client/login](https://mikrotik.com/client/login). If you do not have one, you can register here: [https://mikrotik.com/client/register](https://mikrotik.com/client/register)

From the main menu/dashboard, navigate to **OTHER**/**Branding Maker**. This will load up the configurator. Expand and ensure you read the **+Read this first!** section to fully understand the parameters.

Enter a **Router Name**, **Company URL**, **Manual URL** and **Telnet ASCII Logo**. Click **Make** once you are happy. You will then need to **make for either version 6.47** and above or **make for an older version**.

[![image.png](https://techblog.jcditservices.com/uploads/images/gallery/2024-08/scaled-1680-/Jqzimage.png)](https://techblog.jcditservices.com/uploads/images/gallery/2024-08/Jqzimage.png)

[![image.png](https://techblog.jcditservices.com/uploads/images/gallery/2024-08/scaled-1680-/Krjimage.png)](https://techblog.jcditservices.com/uploads/images/gallery/2024-08/Krjimage.png)

The generated package can be installed in any RouterOS version.

The ASCII logo above you can create right here in the browser, or copy from any other plaintext editor. Make sure it is not wider than the form above, or your logo will be distorted.

Then making the HTML file, you can use different kinds of variables. For example %version% will change to the router's current version. %host% will change to the router's IP address. Use these variables in the Telnet link, or in the header.

The "Router name" is actually the Identity in RouterOS, it can only be one word, don't use spaces or special characters there.

LCD logo will be displayed on devices equipped with LCD screens.  
Requirements for logo: no more than 160px width and no more than 72px height.  
CCR series have white (0xffffff) background, 2011 series have black (0x000000) background.

Note that when using the default configuration file, the configuration is appended when simply installing the package, but after using system reset, only the configuration in your file will be used, all other standard default config will not be used during reset.

To install the package on a device you simply need to upload it and reboot the router, you can also use Netinstall tool for the same effect.

To create a complete branding package, you need to upload the following files:

<div class="confluence-information-macro-body">- The main HTML file will appear when entering the router's IP address in a web browser. The file must be named "index2.html". Make sure you use properly nested HTML to make your page compatible with all browsers.
- The images and other files are associated with this file.
- You can also upload just the router web page logo, which should be named "mikrotik\_logo.png".
- The Hotspot login page logo, the file must be named "logobottom.png",
- For skins, a file default.json must be uploaded into the "skins" directory.
- For RouterOS default configuration, a text/rsc file with one RouterOS command per line. You can use an export file from the console. This configuration will be kept even after the RouterOS reset.

</div></details>

# Home and Office Setup Guides

Various MikroTik Setup guides for Home and Office deployments

# Home Office Network Setup Guide

### <span style="text-decoration: underline;">**Below is a MikroTik configuration tailored to your requirements.** </span>

##### **This configuration includes:**

- **4 VLANs**: Home (VLAN 10), Office (VLAN 20), Guest (VLAN 30), and IoT (VLAN 40).
- **Subnetting**: Each VLAN uses the `10.x.x.x/24` subnet, with the subnet identifier matching the VLAN ID.
- **Firewall Rules**: Home and Office VLANs can access the IoT VLAN; IoT and Guest VLANs are isolated from other VLANs.
- **Security Enhancements**: Hardened router security with essential services only and restricted management access.

### **1. Bridge and VLAN Setup**

#### **Create a Bridge Interface with VLAN Filtering**

<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative" id="bkmrk-plaintext-copy-code-"><div class="overflow-y-auto p-4" dir="ltr">`/interface bridgeadd name=bridge1 vlan-filtering=yes`</div></div>#### **Add Physical Ports to the Bridge**

Assuming `ether2` to `ether5` are your LAN ports:

<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative" id="bkmrk-plaintext-copy-code--1"><div class="overflow-y-auto p-4" dir="ltr">`/interface bridge portadd bridge=bridge1 interface=ether2 pvid=10add bridge=bridge1 interface=ether3 pvid=20add bridge=bridge1 interface=ether4 pvid=30add bridge=bridge1 interface=ether5 pvid=40`</div></div>#### **Define VLANs on the Bridge**

<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative" id="bkmrk-plaintext-copy-code--2"><div class="overflow-y-auto p-4" dir="ltr">`/interface bridge vlanadd bridge=bridge1 tagged=bridge1 untagged=ether2 vlan-ids=10add bridge=bridge1 tagged=bridge1 untagged=ether3 vlan-ids=20add bridge=bridge1 tagged=bridge1 untagged=ether4 vlan-ids=30add bridge=bridge1 tagged=bridge1 untagged=ether5 vlan-ids=40`</div></div>#### **Create VLAN Interfaces**

<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative" id="bkmrk-plaintext-copy-code--3"><div class="overflow-y-auto p-4" dir="ltr">`/interface vlanadd interface=bridge1 name=VLAN10 vlan-id=10add interface=bridge1 name=VLAN20 vlan-id=20add interface=bridge1 name=VLAN30 vlan-id=30add interface=bridge1 name=VLAN40 vlan-id=40`</div></div>---

### **2. IP Addressing**

Assign IP addresses to each VLAN interface, matching the subnet with the VLAN ID:

<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative" id="bkmrk-plaintext-copy-code--4"><div class="overflow-y-auto p-4" dir="ltr">`/ip addressadd address=10.10.10.1/24 interface=VLAN10 network=10.10.10.0add address=10.10.20.1/24 interface=VLAN20 network=10.10.20.0add address=10.10.30.1/24 interface=VLAN30 network=10.10.30.0add address=10.10.40.1/24 interface=VLAN40 network=10.10.40.0`</div></div>---

### **3. DHCP Server Configuration**

#### **Create IP Pools for Each VLAN**

<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative" id="bkmrk-plaintext-copy-code--5"><div class="overflow-y-auto p-4" dir="ltr">`/ip pooladd name=dhcp_pool_vlan10 ranges=10.10.10.10-10.10.10.254add name=dhcp_pool_vlan20 ranges=10.10.20.10-10.10.20.254add name=dhcp_pool_vlan30 ranges=10.10.30.10-10.10.30.254add name=dhcp_pool_vlan40 ranges=10.10.40.10-10.10.40.254`</div></div>#### **Set Up DHCP Servers**

<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative" id="bkmrk-plaintext-copy-code--6"><div class="overflow-y-auto p-4" dir="ltr">`/ip dhcp-serveradd address-pool=dhcp_pool_vlan10 interface=VLAN10 lease-time=12h name=dhcp_vlan10add address-pool=dhcp_pool_vlan20 interface=VLAN20 lease-time=12h name=dhcp_vlan20add address-pool=dhcp_pool_vlan30 interface=VLAN30 lease-time=12h name=dhcp_vlan30add address-pool=dhcp_pool_vlan40 interface=VLAN40 lease-time=12h name=dhcp_vlan40`</div></div>#### **Define DHCP Networks**

<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative" id="bkmrk-plaintext-copy-code--7"><div class="overflow-y-auto p-4" dir="ltr">`/ip dhcp-server networkadd address=10.10.10.0/24 dns-server=8.8.8.8,8.8.4.4 gateway=10.10.10.1add address=10.10.20.0/24 dns-server=8.8.8.8,8.8.4.4 gateway=10.10.20.1add address=10.10.30.0/24 dns-server=8.8.8.8,8.8.4.4 gateway=10.10.30.1add address=10.10.40.0/24 dns-server=8.8.8.8,8.8.4.4 gateway=10.10.40.1`</div></div>---

### **4. Firewall Configuration**

#### **Basic Firewall Rules**

- Accept established and related connections.
- Drop invalid packets.

<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative" id="bkmrk-plaintext-copy-code--8"><div class="sticky top-9 md:top-[5.75rem]">  
</div><div class="overflow-y-auto p-4" dir="ltr">`/ip firewall filteradd chain=forward connection-state=established,related action=acceptadd chain=forward connection-state=invalid action=drop`</div></div>#### **Inter-VLAN Communication Rules**

- **Allow** Home and Office VLANs to access the IoT VLAN.

<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative" id="bkmrk-plaintext-copy-code--9"><div class="sticky top-9 md:top-[5.75rem]">  
</div><div class="overflow-y-auto p-4" dir="ltr">`add chain=forward src-address=10.10.10.0/24 dst-address=10.10.40.0/24 action=acceptadd chain=forward src-address=10.10.20.0/24 dst-address=10.10.40.0/24 action=accept`</div></div>- **Allow** Home and Office VLANs to access the internet.

<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative" id="bkmrk-plaintext-copy-code--10"><div class="sticky top-9 md:top-[5.75rem]">  
</div><div class="overflow-y-auto p-4" dir="ltr">`add chain=forward src-address=10.10.10.0/24 action=accept out-interface-list=WANadd chain=forward src-address=10.10.20.0/24 action=accept out-interface-list=WAN`</div></div>#### **Restrict IoT and Guest VLANs**

- **Drop** traffic from IoT VLAN to other VLANs.

<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative" id="bkmrk-plaintext-copy-code--11"><div class="sticky top-9 md:top-[5.75rem]">  
</div><div class="overflow-y-auto p-4" dir="ltr">`add chain=forward src-address=10.10.40.0/24 dst-address=10.10.10.0/24 action=dropadd chain=forward src-address=10.10.40.0/24 dst-address=10.10.20.0/24 action=dropadd chain=forward src-address=10.10.40.0/24 dst-address=10.10.30.0/24 action=drop`</div></div>- **Drop** traffic from Guest VLAN to other VLANs.

<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative" id="bkmrk-plaintext-copy-code--12"><div class="sticky top-9 md:top-[5.75rem]">  
</div><div class="overflow-y-auto p-4" dir="ltr">`add chain=forward src-address=10.10.30.0/24 dst-address=10.10.10.0/24 action=dropadd chain=forward src-address=10.10.30.0/24 dst-address=10.10.20.0/24 action=dropadd chain=forward src-address=10.10.30.0/24 dst-address=10.10.40.0/24 action=drop`</div></div>- **Allow** IoT and Guest VLANs to access the internet.

<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative" id="bkmrk-plaintext-copy-code--13"><div class="sticky top-9 md:top-[5.75rem]">  
</div><div class="overflow-y-auto p-4" dir="ltr">`add chain=forward src-address=10.10.40.0/24 action=accept out-interface-list=WANadd chain=forward src-address=10.10.30.0/24 action=accept out-interface-list=WAN`</div></div>#### **Drop All Other Traffic**

<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative" id="bkmrk-plaintext-copy-code--14"><div class="overflow-y-auto p-4" dir="ltr">`add chain=forward action=drop`</div></div>---

### **5. NAT Configuration**

Ensure that all VLANs can access the internet:

<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative" id="bkmrk-plaintext-copy-code--15"><div class="overflow-y-auto p-4" dir="ltr">`/ip firewall natadd chain=srcnat out-interface-list=WAN action=masquerade`</div></div>---

### **6. Security Hardening**

#### **Restrict Router Access**

- Allow management access only from Home and Office VLANs.

<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative" id="bkmrk-plaintext-copy-code--16"><div class="sticky top-9 md:top-[5.75rem]">  
</div><div class="overflow-y-auto p-4" dir="ltr">`/ip firewall filteradd chain=input connection-state=established,related action=acceptadd chain=input connection-state=invalid action=dropadd chain=input src-address=10.10.10.0/24 action=acceptadd chain=input src-address=10.10.20.0/24 action=acceptadd chain=input action=drop`</div></div>#### **Disable Unnecessary Services**

<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative" id="bkmrk-plaintext-copy-code--17"><div class="overflow-y-auto p-4" dir="ltr">`/ip serviceset telnet disabled=yesset ftp disabled=yesset www disabled=yesset ssh disabled=yesset api disabled=yesset api-ssl disabled=yesset winbox address=10.10.10.0/24,10.10.20.0/24`</div></div>> **Note:** Only Winbox is enabled for management, and access is restricted to Home and Office VLANs.

#### **Set Strong Passwords**

Ensure the router's admin password is strong:

<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative" id="bkmrk-plaintext-copy-code--18"><div class="overflow-y-auto p-4" dir="ltr">`/user set 0 name=admin password=YourStrongPassword`</div></div>Replace `YourStrongPassword` with a strong, unique password.

#### **Additional Security Measures**

- **System Updates**: Regularly update your router's firmware to the latest stable version.
- **Backup Configuration**: Keep backups of your configuration in a secure location.
- **Logging**: Enable system logging for monitoring.

---

### **7. Final Notes**

- **Adjust Interface Names**: Replace `ether2`, `ether3`, etc., with your actual interface names if they differ.
- **WAN Interface**: Ensure your WAN interface is added to the `WAN` interface list.

<div class="dark bg-gray-950 contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative" id="bkmrk-plaintext-copy-code--19"><div class="sticky top-9 md:top-[5.75rem]">  
</div><div class="overflow-y-auto p-4" dir="ltr">`/interface listadd name=WAN/interface list memberadd interface=ether1 list=WAN`</div></div>Assuming `ether1` is your WAN interface.

- **DNS Servers**: You can replace `8.8.8.8,8.8.4.4` with your preferred DNS servers.
- **Safe Mode**: When applying configurations, use Safe Mode in Winbox or CLI to prevent lockouts.

---

**By implementing this configuration, you'll have a secure and segmented network that meets your home office needs.**

# High Availability Solutions


Load Balancing
Bonding
Bonding Examples
HA Case Studies
Multi-chassis Link Aggregation Group
VRRP
VRRP Configuration Examples


# Load Balancing

# <span class="js-about-item-abstr">Introduction</span>

<span class="js-about-item-abstr">Network load balancing is the ability to balance traffic across two or more links without using dynamic routing protocols.</span>

There are two type of balancing methods:

<div class="wiki-content" id="bkmrk-per-packet---each-pa">- per-packet - each packet of a single stream can be forwarded over different links. This method will work reliably especially on TCP and secure connections only when you are able to control both balancing endpoints.
- per-connection - all packets of the same connection (stream) is always sent over one link. This method is mandatory in setups where only one end of the balancing is under our control, for example, home router with multiple WAN connections.

</div><div class="wiki-content" id="bkmrk-method-per-connectio"><div class="table-wrap"><table class="relative-table wrapped confluenceTable" style="width: 104.405%;"><colgroup><col style="width: 22.1692%;"></col><col style="width: 40.0477%;"></col><col style="width: 21.5733%;"></col><col style="width: 16.2098%;"></col></colgroup><tbody><tr><th class="confluenceTh" colspan="2">Method</th><th class="confluenceTh">Per-connection</th><th class="confluenceTh">Per-packet</th></tr><tr><td class="confluenceTd" rowspan="3">Firewall Mangle

</td><td class="confluenceTd">Nth</td><td class="confluenceTd">**Yes**</td><td class="confluenceTd">**Yes**</td></tr><tr><td class="confluenceTd">PCC (Per Connection Classifier)</td><td class="confluenceTd">**Yes**</td><td class="confluenceTd">No</td></tr><tr><td class="confluenceTd">Other matchers</td><td class="confluenceTd">**Yes**</td><td class="confluenceTd">**Yes**</td></tr><tr><td class="confluenceTd" colspan="2">ECMP (Equal Cost Multi-Path)</td><td class="confluenceTd">**Yes**</td><td class="confluenceTd">**No**</td></tr><tr><td class="confluenceTd" colspan="2">Bonding</td><td class="confluenceTd">No</td><td class="confluenceTd">**Yes**</td></tr><tr><td class="confluenceTd" colspan="2">OSPF</td><td class="confluenceTd">**Yes**</td><td class="confluenceTd">No</td></tr><tr><td class="confluenceTd" colspan="2">BGP</td><td class="confluenceTd">**Yes**</td><td class="confluenceTd">No</td></tr></tbody></table>

</div></div><span class="js-about-item-abstr"> </span>

# Simple Failover Example

Simplest failover setup would be to use multiple gateways when one gateway is active and another one takes over when the first one fails.

To make this work, configure larger **distance** value for the secondary one, and **check-gateway** for the first one:

<div class="wiki-content" id="bkmrk-%2Fip-route-add-gatewa"><div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/ip route add gateway=192.168.1.1 distance=1 check-gateway=ping </span>/ip route add gateway=192.168.2.1 distance=2`</span></div></div></div></div>The *check-gateway* will make sure the gateway is up only when actual traffic can reach the gateway. When the ping fails the first gateway will become inactive and the second one will take over, and when the first gateway recovers it will become active and make the second gateway to work again as a backup.

<details id="bkmrk-per-connection-class"><summary>Per connection classifier</summary>

PCC matcher will allow you to divide traffic into equal streams with the ability to keep packets with specific set of options in one particular stream (you can specify this set of options from src-address, src-port, dst-address, dst-port)

## Theory

PCC takes selected fields from IP header, and with the help of a hashing algorithm converts selected fields into 32-bit value. This value then is divided by a specified *Denominator* and the remainder then is compared to a specified *Remainder*, if equal then the packet will be captured. You can choose from src-address, dst-address, src-port, dst-port from the header to use in this operation.

PCC is not a valid method, in case of Hotspot(captive portal) - due to the fact that Hotspot uses web-proxy and it uses only the default routing table, at the moment.

<div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">per-connection-classifier=</span>PerConnectionClassifier ::= [!]ValuesToHash:Denominator/Remainder  Remainder ::= 0..4294967295    (integer number)  Denominator ::= 1..4294967295    (integer number)  ValuesToHash ::= both-addresses|both-ports|dst-address-and-port|  src-address|src-port|both-addresses-and-ports|dst-address|dst-port|src-address-and-port `</span></div></div></div>## Example

This configuration will divide all connections into 3 groups based on the source address and port

<div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/ip firewall mangle add chain=prerouting action=mark-connection \</span> new-connection-mark=1st_conn per-connection-classifier=src-address-and-port:3/0/ip firewall mangle add chain=prerouting action=mark-connection \  new-connection-mark=2nd_conn per-connection-classifier=src-address-and-port:3/1/ip firewall mangle add chain=prerouting action=mark-connection \  new-connection-mark=3rd_conn per-connection-classifier=src-address-and-port:3/2`</span></div></div></div>## How PCC works

This article aims to explain in simple terms how PCC works. The definition from the official manual wiki page reads: "PCC takes selected fields from IP header, and with the help of a hashing algorithm converts selected fields into 32-bit value. This value then is divided by a specified Denominator and the remainder then is compared to a specified Remainder, if equal then packet will be captured. You can choose from src-address, dst-address, src-port, dst-port from the header to use in this operation.", with the full number of fields available being: "both-addresses|both-ports|dst-address-and-port|src-address|src-port|both-addresses-and-ports|dst-address|dst-port|src-address-and-port". If you understand that definition, there'll be nothing interesting in this article for you.

First, here are the terms necessary to understand the definition.

IP packets have a header that contains several fields, two of those fields are the IP address of the source of the packet and the IP address of the destination of the packet. TCP and UDP packets also have headers that contain the source port and the destination port.

Denominators and remainders are parts of modulus operations. A modulus operation produces the integer left over when you divide two numbers and only accept the whole number portion of the result. It is represented by a % sign. Here are some examples: 3 % 3 = 0, because 3 divides cleanly by 3. 4 % 3 = 1, because the next smallest number to 4 that cleanly divides by 3 is 3, and 4 - 3 = 1. 5 % 3 is 2, because the next smallest number to 5 that divides cleanly by 3 is 3, and 5 - 3 = 2. 6 % 3 = 0, because 6 divides cleanly by 3.

A hash is a function that is fed input, and produces output. Hashes have many interesting properties, but the only important one for the purpose of this article is that hash functions are deterministic. That means that when you feed a hash function an input that reads 'hello' and it produces the output '1', you can rely on the fact that if you feed it 'hello' a second time it will produce the output '1' again. When you feed a hash function the same input, it will always produce the same output. What exact hashing algorithm is used by PCC is not important, so for this discussion let's assume that when you feed it IP addresses and ports, it just adds up the octets of the IP addresses as decimal numbers as well as the ports, and then takes the last digit and produces it as the output. Here an example:

The hash function is fed 1.1.1.1 as the source IP address, 10000 as the source TCP port, 2.2.2.2 as the destination IP address and 80 as the destination TCP port. The output will be 1+1+1+1+10000+2+2+2+2+80 = 10092, the last digit of that is 2, so the hash output is 2. It will produce 2 every time it is fed that combination of IP addresses and ports.

At this point it's important to note that even though PCC is most often used for spreading load across circuits, PCC itself has absolutely nothing to do with routing, routing marks or spreading load. PCC is simply a way to match packets, and not directly related to the action of then marking those matched packets even if that is its main purpose.

Here are three lines often used for PCC, with their explanation:

<div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/ip firewall mangle add chain=prerouting action=mark-connection \</span> new-connection-mark=1st_conn per-connection-classifier=src-address-and-port:3/0/ip firewall mangle add chain=prerouting action=mark-connection \  new-connection-mark=2nd_conn per-connection-classifier=src-address-and-port:3/1/ip firewall mangle add chain=prerouting action=mark-connection \  new-connection-mark=3rd_conn per-connection-classifier=src-address-and-port:3/2`</span></div></div></div>Here are what the different field options mean for the purpose of packet matching, these are the fields that will be fed into the hashing algorithm (and, for the purpose of spreading load across links, decide what link a packet will be put on). Remember that a hash function will always produce the same input when it's fed the same output:

- src-address: The source address of a client will always be the same, so all traffic from a particular client will always match the same PCC matcher, and will always be put on the same link.
- dst-address: The destination address of a specific server will always be the same, so all traffic to that server (say, the Mikrotik Wiki) will always match the same PCC matcher, and will always be put on the same link.
- both-addresses: The source and destination IP pair between the same client and server will always be the same, so all traffic between one specific client and a specific server (say, your laptop and the Mikrotik Wiki) will always match the same PCC matcher, and will always be put on the same link.
- src-port: Source ports of clients are usually randomly chosen when the connection is created, so across many connections different source ports will be fed into the hash function, and different PCC matchers will match and traffic will go across different links. However, some client protocols always choose the same source port, and servers behind your router will mostly likely always use the same service port to send traffic back to their clients. A web server behind your router would send most traffic from its HTTP (80) and HTTPS (443) ports, and that traffic would always match the same PCC matcher and would be put on the same link.
- dst-port: Destination ports of clients are usually well defined service ports, all HTTP (80) traffic between your clients and servers on the Internet would always match the same PCC matcher, and would be put on the same link. However, the same clients doing HTTPS (443) traffic could match a different PCC matcher, and would go across a different link.
- both-ports: Since the client port is (usually) randomly chosen, the combination of the two ports is (usually) random and will spread load across links.
- src-address-and-port: Same caveat as src-port.
- dst-address-and-port: Same caveat as dst-port.
- both-addresses-and-ports: This is the most random way to spread traffic across links, since it has the most number of variables.

It's important to note that even though the hash function discussed in this article is greatly simplified and not what is used in real life, it nicely demonstrates another property of hash functions: two completely different inputs can produce the same output. In our example, 3 % 3 = 0, and 6 % 3 = 0; we get back 0 when we feed it a 3 as well as when we feed it a 6. The same is true for the actual function used for PCC, even though I don't know what it is we do know from the definition that it produces a 32 bit value as output. IP addresses are 32 bit, and ports are 16 bit, so assuming that we're using both-addresses-and-ports, we'd be feeding it 32+32+16+16 = 96 bits of input and would only receive 32 bits back, so it must be producing the same output for different inputs. This means that two completely unrelated connections could match the same PCC matcher, and would be put on the same line. PCC works better the more connections you put across it so that the hash function has more chances to produce different outputs.

## Configuration Example

Let's assume this configuration:

[![image.png](https://techblog.jcditservices.com/uploads/images/gallery/2024-10/scaled-1680-/1yBimage.png)](https://techblog.jcditservices.com/uploads/images/gallery/2024-10/1yBimage.png)

## IP Addresses

<div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/ip address </span>add address=10.10.4.100/24 interface=ether_ISP1 network=10.10.4.0add address=10.10.5.100/24 interface=ether_ISP2 network=10.10.5.0add address=192.168.100.1/24 interface=ether_LAN network=192.168.100.0`</span></div></div></div>The router has two upstream (ISP) interfaces with the addresses of 10.10.4.100/24 and 10.10.5.100/24. The LAN interface has IP address of 192.168.0.1/24.

  
We are adding two new Routing tables, which will be used later:

<div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/routing table</span>add disabled=no fib name=ISP1_tableadd disabled=no fib name=ISP2_table`</span></div></div></div>## Policy routing

<div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/ip firewall mangle</span>add action=accept chain=prerouting dst-address=10.10.4.0/24 in-interface=ether_LANadd action=accept chain=prerouting dst-address=10.10.5.0/24 in-interface=ether_LAN`</span></div></div></div>With policy routing it is possible to force all traffic to the specific gateway, even if traffic is destined to the host (other that gateway) from the connected networks. This way routing loop will be generated and communications with those hosts will be impossible. To avoid this situation we need to allow usage of default routing table for traffic to connected networks.

<div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">add action=mark-connection chain=input connection-state=new in-interface=ether_ISP1 new-connection-mark=ISP1</span>add action=mark-connection chain=input connection-state=new in-interface=ether_ISP2 new-connection-mark=ISP2add action=mark-connection chain=output connection-mark=no-mark connection-state=new new-connection-mark=ISP1 passthrough=yes per-connection-classifier=both-addresses:2/0add action=mark-connection chain=output connection-mark=no-mark connection-state=new new-connection-mark=ISP2 per-connection-classifier=both-addresses:2/1`</span></div></div></div>First it is necessary to manage connection initiated from outside - replies must leave via same interface (from same Public IP) request came. We will mark all new incoming connections, to remember what was the interface.

<div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">add action=mark-connection chain=prerouting connection-mark=no-mark connection-state=new dst-address-type=!local in-interface=ether_LAN new-connection-mark=ISP1 per-connection-classifier=both-addresses:2/0</span>add action=mark-connection chain=prerouting connection-mark=no-mark connection-state=new dst-address-type=!local in-interface=ether_LAN new-connection-mark=ISP2 per-connection-classifier=both-addresses:2/1`</span></div></div></div>Action mark-routing can be used only in mangle chain output and prerouting, but mangle chain prerouting is capturing all traffic that is going to the router itself. To avoid this we will use dst-address-type=!local. And with the help of the new PCC we will divide traffic into two groups based on source and destination addressees.

<div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">add action=mark-routing chain=output connection-mark=ISP1 new-routing-mark=ISP1_table</span>add action=mark-routing chain=prerouting connection-mark=ISP1 in-interface=ether_LAN new-routing-mark=ISP1_tableadd action=mark-routing chain=output connection-mark=ISP2 new-routing-mark=ISP2_tableadd action=mark-routing chain=prerouting connection-mark=ISP2 in-interface=ether_LAN new-routing-mark=ISP2_table`</span></div></div></div>Then we need to mark all packets from those connections with a proper mark. As policy routing is required only for traffic going to the Internet, do not forget to specify in-interface option.

<div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/ip route</span>add check-gateway=ping disabled=no dst-address=0.0.0.0/0 gateway=10.10.4.1 routing-table=ISP1_table suppress-hw-offload=noadd check-gateway=ping disabled=no dst-address=0.0.0.0/0 gateway=10.10.5.1 routing-table=ISP2_table suppress-hw-offload=no`</span></div></div></div>Create a route for each routing-mark

<div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">add distance=1 dst-address=0.0.0.0/0 gateway=10.10.4.1</span>add distance=2 dst-address=0.0.0.0/0 gateway=10.10.5.1`</span></div></div></div>To enable failover, it is necessary to have routes that will jump in as soon as others will become inactive on gateway failure. (and that will happen only if check-gateway option is active)

## NAT

<div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/ip firewall nat</span>add action=masquerade chain=srcnat out-interface=ether_ISP1add action=masquerade chain=srcnat out-interface=ether_ISP2`</span></div></div></div>As routing decision is already made we just need rules that will fix src-addresses for all outgoing packets. If this packet will leave via ether\_ISP1 it will be NATed to 10.10.4.100, if via ether\_ISP2 then NATed to 10.10.5.100

</details><div class="wiki-content" id="bkmrk--1"></div>

# Bonding

### <span class="mw-headline">Summary</span>

---

Bonding is a technology that allows aggregation of multiple ethernet-like interfaces into a single virtual link, thus getting higher data rates and providing failover.

Interface bonding does not create an interface with a larger link speed. Interface bonding creates a virtual interface that can load balance traffic over multiple interfaces.

CRS3xx, CRS5xx series switches, CCR2116, CCR2216 routers and 88E6393X, 88E6191X, 88E6190 switch chips support bridge hardware offloading with bonding interfaces. Only `802.3ad` and `balance-xor `bonding modes are hardware offloaded, other bonding modes will use the CPU's resources. The built-in switch chip will always use Layer2+Layer3+Layer4 for a transmit hash policy, changing the transmit hash policy manually will have no effect.

### <span class="mw-headline">Quick Setup Guide</span>

---

Let us assume that we have two Ethernet interfaces on each router (Router1 and Router2) and want to get the maximum data rate between these two routers. To make this possible, follow these steps:

1. Make sure that you do not have IP addresses on interfaces that will be enslaved for bonding interface.
2. Add bonding interface and IP address on the Router1:
    
    <div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><div class="buttonContainer_eYrJGPqrr8SQQaUJ7o5OMg==  ">  
    </div><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/interface bonding add slaves=ether1,ether2 name=bond1</span>/ip address add address=172.16.0.1/24 interface=bond1`</span></div></div></div>
3. Do the same thing on the Router2:
    
    <div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><div class="buttonContainer_eYrJGPqrr8SQQaUJ7o5OMg==  ">  
    </div><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/interface bonding add slaves=ether1,ether2 name=bond1</span>/ip address add address=172.16.0.2/24 interface=bond1`</span></div></div></div>
4. Test the link from Router1:
    
    <div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><div class="buttonContainer_eYrJGPqrr8SQQaUJ7o5OMg==  ">  
    </div><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">[admin@Router1] > ping 172.16.0.2</span>  SEQ HOST                                 SIZE TTL TIME  STATUS                       0 172.16.0.2                             56  64 0ms      1 172.16.0.2                             56  64 0ms      2 172.16.0.2                             56  64 0ms      sent=3 received=3 packet-loss=0% min-rtt=0ms avg-rtt=0ms max-rtt=0ms`</span></div></div></div>

The bonding interface needs a couple of seconds to get connectivity with its peers.

### <span class="mw-headline">Link monitoring</span>

---

It is critical that one of the available link monitoring options is enabled. In the above example, if one of the bonded links were to fail, the bonding driver will still continue to send packets over the failed link which will lead to network degradation. Bonding in RouterOS currently supports two schemes for monitoring a link state of slave devices: MII and ARP monitoring. It is not possible to use both methods at the same time due to restrictions in the bonding driver.

### <span class="mw-headline">ARP Monitoring</span>

ARP monitoring sends ARP queries and uses the response as an indication that the link is operational. The ARP replies are not validated, any received packet by the slave interface will result in the slave interface considered as active. This gives assurance that traffic is actually flowing over the links. If balance-rr and balance-xor modes are set, then the switch should be configured to evenly distribute packets across all links. Otherwise, all replies from the ARP targets will be received on the same link which could cause other links to fail. ARP monitoring is enabled by setting three properties - link-monitoring, arp-ip-targets and arp-interval. The meaning of each option is described later in this article. It is possible to specify multiple ARP targets that can be useful in High Availability setups. If only one target is set, the target itself may go down. Having additional targets increases the reliability of the ARP monitoring.

To enable ARP monitoring on Router1:

<div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code" id="bkmrk-%2Finterface-bonding-s"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><div class="buttonContainer_eYrJGPqrr8SQQaUJ7o5OMg==  ">  
</div><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/interface bonding set [find name=bond1] link-monitoring=arp arp-ip-targets=172.16.0.2</span>`</span></div></div></div>and Router2:

<div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code" id="bkmrk-%2Finterface-bonding-s-1"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><div class="buttonContainer_eYrJGPqrr8SQQaUJ7o5OMg==  ">  
</div><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/interface bonding set [find name=bond1] link-monitoring=arp arp-ip-targets=172.16.0.1</span>`</span></div></div></div>We will not change the arp-interval value in our example, RouterOS sets arp-interval to 100ms by default. Unplug one of the cables to test if the link monitoring works correctly, you might notice some ping timeouts until arp monitoring detects link failure.

<div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code" id="bkmrk-%5Badmin%40mikrotik%5D-%3E-p"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><div class="buttonContainer_eYrJGPqrr8SQQaUJ7o5OMg==  ">  
</div><span class="prismjs css-3686h1" data-code-lang="text" data-ds--code--code-block="">`<span class="">[admin@MikroTik] > ping 172.16.0.2</span>  SEQ HOST                                     SIZE TTL TIME  STATUS                                     0 172.16.0.2                                 56  64 0ms      1 172.16.0.2                                 56  64 0ms      2 172.16.0.2                                 56  64 0ms      3 172.16.0.2                                 56  64 0ms      4 172.16.0.2                                              timeout                                    5 172.16.0.2                                 56  64 0ms      6 172.16.0.2                                 56  64 0ms      sent=7 received=6 packet-loss=14% min-rtt=0ms avg-rtt=0ms max-rtt=0ms`</span></div></div></div>For ARP monitoring to work properly it is not required to have any IP address on the device, ARP monitoring will work regardless of the IP address that is set on any interface.

When ARP monitoring is used, bonding slaves will send out ARP requests without a VLAN tag, even if an IP address is set on a VLAN interface in the same subnet as the arp-ip-targets

## <span class="mw-headline">MII monitoring</span>

MII monitoring monitors only the state of the local interface. *MII Type 1* - a device driver determines whether a link is up or down. If the device driver does not support this option then the link will appear as always up. The main disadvantage is that MII monitoring can't tell if the link can actually pass packets or not, even if the link is detected as being up. MII monitoring is configured by setting the variables - link-monitoring and mii-interval.

To enable MII Type1 monitoring on Router1 and Router2:

<div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code" id="bkmrk-%2Finterface-bonding-s-2"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/interface bonding set [find name=bond1] link-monitoring=mii</span>`</span></div></div></div>We will leave mii-interval to its default value (100ms). When unplugging one of the cables, the failure will be detected almost instantly compared to ARP link monitoring.

### <span class="mw-headline">Bonding modes</span>

---

## <span class="mw-headline">802.3ad</span>

802.3ad mode is an IEEE standard also called LACP (Link Aggregation Control Protocol). It includes automatic configuration of the aggregates, so minimal configuration of the switch is needed. This standard also mandates that frames will be delivered in order and connections should not see misordering of packets. The standard also mandates that all devices in the aggregate must operate at the same speed and duplex mode.

LACP balances outgoing traffic across the active ports based on hashed protocol header information and accepts incoming traffic from any active port. The hash includes the Ethernet source and destination address and if available, the VLAN tag, and the IPv4/IPv6 source and destination address. How this is calculated depends on transmit-hash-policy parameter. The ARP link monitoring is not recommended, because the ARP replies might arrive only on one slave port due to transmit hash policy on the LACP peer device. This can result in unbalanced transmitted traffic, so MII link monitoring is the recommended option.

The layer-3-and-4 transmit hash mode is not fully compatible with LACP. More details can be found in [https://www.kernel.org/doc/Documentation/networking/bonding.txt](https://www.kernel.org/doc/Documentation/networking/bonding.txt)

### <span class="mw-headline">balance-xor</span>

This mode balances outgoing traffic across the active ports based on the hashed protocol header information and accepts incoming traffic from any active port. The mode is very similar to [LACP](https://wiki.mikrotik.com/wiki/Manual:Interface/Bonding#802.3ad) except that it is not standardized and works with **layer-3-and-4** hash policy. The mode can work together with static Link Aggregation Group (LAG) interfaces.

### <span class="mw-headline">balance-rr</span>

If this mode is set, packets are transmitted in sequential order from the first available slave to the last. The balance-rr is the only mode that will send packets across multiple interfaces that belong to the same TCP/IP connection. When utilizing multiple sending and multiple receiving links, packets are often received out of order, which results in segment retransmission, for other protocols such as UDP it is not a problem if a client software can tolerate out-of-order packets. If a switch is used to aggregate links together, then appropriate switch port configuration is required, however many switches do not support balance-rr. [Quick setup guide](https://wiki.mikrotik.com/wiki/Manual:Interface/Bonding#Quick_Setup_Guide) demonstrates the usage of the balance-rr bonding mode. As you can see, it is quite simple to set up. Balance-rr is also useful for bonding several wireless links, however, it requires equal bandwidth for all bonded links. If the bandwidth of one bonded link drops, then the total bandwidth of bond will be equal to the bandwidth of the slowest bonded link.

### <span class="mw-headline">active-backup</span>

This mode uses only one active slave to transmit packets. The additional slave only becomes active if the primary slave fails. The MAC address of the bonding interface is presented onto the active port to avoid confusing the switch. Active-backup is the best choice in high availability setups with multiple switches that are interconnected.

The ARP monitoring in this mode will not work correctly if both routers are directly connected. In such setups, MII monitoring must be used or a switch should be put between routers.

### <span class="mw-headline">broadcast</span>

When ports are configured with broadcast mode, all slave ports transmit the same packets to the destination to provide fault tolerance. This mode does not provide load balancing.

### <span class="mw-headline">balance-tlb</span>

This mode balances outgoing traffic by peer. Each link can be a different speed and duplex mode and no specific switch configuration is required as for the other modes. The downside of this mode is that only MII link monitoring is supported (ARP link monitoring is ignored when configured) and incoming traffic is not balanced. Incoming traffic will use the link that is configured as "primary".

### Configuration example

Let's assume that the router has two links - **ether1** max bandwidth is 10Mbps and **ether2** max bandwidth is 5Mbps. The first link has more bandwidth so we set it as a primary link:

<div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code" id="bkmrk-%2Finterface-bonding-a"><div class="codeContent panelContent pdl"><div class="buttonContainer_eYrJGPqrr8SQQaUJ7o5OMg==  ">  
</div><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/interface bonding add mode=balance-tlb slaves=ether1,ether2 primary=ether1</span>`</span></div></div></div>[![image.png](https://techblog.jcditservices.com/uploads/images/gallery/2024-10/scaled-1680-/Tglimage.png)](https://techblog.jcditservices.com/uploads/images/gallery/2024-10/Tglimage.png)

No additional configuration is required for the switch. The image above illustrates how balance-tlb mode works. As you can see router can communicate to all the clients connected to the switch with a total bandwidth of both links (15Mbps). But as you already know, balance-tlb is not balancing incoming traffic. In our example, clients can communicate to the router with a total bandwidth of primary link which is 10Mbps in our configuration.

## <span class="mw-headline">balance-alb</span>

The mode is basically the same as balance-tlb but incoming IPv4 traffic is also balanced. The receive load balancing is achieved by ARP negotiation. The bonding driver intercepts locally generated ARP messages on their way out and overwrites the source hardware address with the unique address of one of the slaves in the bond such that different peers use different hardware addresses. Only MII link monitoring is supported (ARP link monitoring is ignored when configured), the additional downside of this mode is that it requires device driver capability to change MAC address. The mode is not compatible with local-proxy-arp setting.

[![image.png](https://techblog.jcditservices.com/uploads/images/gallery/2024-10/scaled-1680-/2Y4image.png)](https://techblog.jcditservices.com/uploads/images/gallery/2024-10/2Y4image.png)

  
The image above illustrates how balance-alb mode works. Compared to balance-tlb mode, traffic from clients can also use the secondary link to communicate with the router.

# Bonding monitoring

---

Since RouterOS 6.48 version, it is possible to monitor the bonding interface and bonding ports. For the `802.3ad` bonding mode, more detailed monitoring options are available.

<div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code" id="bkmrk-%2Finterface-bonding-m"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/interface bonding monitor [find] </span>                      mode: 802.3ad           active-backup              active-ports: ether4            ether6                            ether5                        inactive-ports:                   ether7            lacp-system-id: CC:2D:E0:11:22:33       lacp-system-priority: 65535                 lacp-partner-system-id: B8:69:F4:44:55:66`</span></div></div></div><div class="table-wrap" id="bkmrk-property-description"><table class="wrapped relative-table confluenceTable tablesorter tablesorter-default" role="grid"><colgroup><col></col><col></col></colgroup><thead aria-label="Use column header buttons to sort"><tr class="tablesorter-headerRow" role="row"><th aria-disabled="false" class="confluenceTh tablesorter-header sortableHeader tablesorter-headerUnSorted" data-column="0" role="columnheader" scope="col"><div class="tablesorter-header-inner"><button class="headerButton">Property</button></div></th><th aria-disabled="false" class="confluenceTh tablesorter-header sortableHeader tablesorter-headerUnSorted" data-column="1" role="columnheader" scope="col"><div class="tablesorter-header-inner"><button class="headerButton">Description</button></div></th></tr></thead><tbody><tr role="row"><td class="confluenceTd">**mode** (*802.3ad | active-backup | balance-alb | balance-rr | balance-tlb | balance-xor | broadcast*)</td><td class="confluenceTd">Used bonding mode</td></tr><tr role="row"><td class="confluenceTd">**active-ports** (*interface*)</td><td class="confluenceTd">Shows the active bonding ports</td></tr><tr role="row"><td class="confluenceTd" colspan="1">**inactive-ports** (*interface*)</td><td class="confluenceTd" colspan="1">Shows the inactive bonding ports (e.g. a disabled or backup interface)</td></tr><tr role="row"><td class="confluenceTd">**lacp-system-id** (*MAC address*)</td><td class="confluenceTd">Shows the local LACP system ID</td></tr><tr role="row"><td class="confluenceTd">**lacp-system-priority** (*integer*)</td><td class="confluenceTd">Shows the local LACP priority</td></tr><tr role="row"><td class="confluenceTd">**lacp-partner-system-id** (*MAC address*)</td><td class="confluenceTd">Shows the partner LACP system ID</td></tr></tbody></table>

</div>To monitor individual bonding ports, use a `monitor-slaves` command.

<div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code" id="bkmrk-%2Finterface-bonding-m-1"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/interface bonding monitor-slaves bond1</span>Flags: A - active, P - partner  AP port=ether4 key=17 flags="A-GSCD--" partner-sys-id=D4:CA:6D:12:06:65 partner-sys-priority=65535 partner-key=9 partner-flags="A-GSCD--"  AP port=ether5 key=17 flags="A-GSCD--" partner-sys-id=D4:CA:6D:12:06:65 partner-sys-priority=65535 partner-key=9 partner-flags="A-GSCD--" `</span></div></div></div><div class="table-wrap" id="bkmrk-property-description-1"><table class="wrapped relative-table confluenceTable tablesorter tablesorter-default" role="grid"><colgroup><col></col><col></col></colgroup><thead aria-label="Use column header buttons to sort"><tr class="tablesorter-headerRow" role="row"><th aria-disabled="false" class="confluenceTh tablesorter-header sortableHeader tablesorter-headerUnSorted" data-column="0" role="columnheader" scope="col"><div class="tablesorter-header-inner"><button class="headerButton">Property</button></div></th><th aria-disabled="false" class="confluenceTh tablesorter-header sortableHeader tablesorter-headerUnSorted" data-column="1" role="columnheader" scope="col"><div class="tablesorter-header-inner"><button class="headerButton">Description</button></div></th></tr></thead><tbody><tr role="row"><td class="confluenceTd">**port** (*interface*)</td><td class="confluenceTd">Used bonding port</td></tr><tr role="row"><td class="confluenceTd">**key** (*integer*)</td><td class="confluenceTd">Shows the local LACP aggregation key. The lower 6 bits are automatically assigned based on individual port link speed and duplex. The upper 10 bits can be manually specified using the` lacp-user-key` setting (available only since RouterOS v7.3). </td></tr><tr role="row"><td class="confluenceTd">**flags** (*string*)</td><td class="confluenceTd">Shows the local LACP flags:

A - activity (link is active, otherwise passive)  
T - timeout (link is using short 1-second timeout, otherwise using 30-second timeout)  
G - aggregation (link can be aggregatable)  
S - synchronization (link is synchronized)  
C - collecting (link is able to collect incoming frames)  
D - distributing (link is able to distribute outgoing frames)  
F - defaulted (link is using defaulted partner information, indicated that no LACPDU has been received from the partner)  
E - expired (link has expired state)

</td></tr><tr role="row"><td class="confluenceTd" colspan="1">**partner-sys-id** (*MAC address*)</td><td class="confluenceTd" colspan="1">Shows the partner LACP system ID</td></tr><tr role="row"><td class="confluenceTd" colspan="1">**partner-sys-priority** (*integer*)</td><td class="confluenceTd" colspan="1">Shows the partner LACP priority</td></tr><tr role="row"><td class="confluenceTd" colspan="1">**partner-key** (*integer*)</td><td class="confluenceTd" colspan="1">Shows the partner LACP aggregation key</td></tr><tr role="row"><td class="confluenceTd" colspan="1">**partner-flags** (*string*)</td><td class="confluenceTd" colspan="1">Shows the partner LACP flags</td></tr></tbody></table>

</div>### <span class="mw-headline">Property Description</span>

---

This section describes the available bonding settings.

<div class="table-wrap" id="bkmrk-property-description-3"><table class="wrapped confluenceTable tablesorter tablesorter-default" role="grid" style="width: 108.69%;"><colgroup><col style="width: 18.236%;"></col><col style="width: 81.764%;"></col></colgroup><thead aria-label="Use column header buttons to sort"><tr class="tablesorter-headerRow" role="row"><th aria-disabled="false" class="confluenceTh tablesorter-header sortableHeader tablesorter-headerUnSorted" data-column="0" role="columnheader" scope="col"><div class="tablesorter-header-inner"><button class="headerButton">Property</button></div></th><th aria-disabled="false" class="confluenceTh tablesorter-header sortableHeader tablesorter-headerUnSorted" data-column="1" role="columnheader" scope="col"><div class="tablesorter-header-inner"><button class="headerButton">Description</button></div></th></tr></thead><tbody><tr role="row"><td class="confluenceTd">**arp** (*disabled | enabled | proxy-arp | reply-only*; Default: **enabled**)</td><td class="confluenceTd">Address Resolution Protocol for the interface. - disabled - the interface will not use ARP
- enabled - the interface will use ARP
- proxy-arp - the interface will use the ARP proxy feature
- reply-only - the interface will only reply to requests originated from matching IP address/MAC address combinations which are entered as static entries in the "/ip arp" table. No dynamic entries will be automatically stored in the "/ip arp" table. Therefore for communications to be successful, a valid static entry must already exist.

</td></tr><tr role="row"><td class="confluenceTd">**arp-interval** (*time*; Default: **00:00:00.100**)</td><td class="confluenceTd">Time in milliseconds defines how often to monitor ARP requests</td></tr><tr role="row"><td class="confluenceTd">**arp-ip-targets** (*IP address*; Default: )</td><td class="confluenceTd">IP target address which will be monitored if link-monitoring is set to arp. You can specify multiple IP addresses, separated by a comma</td></tr><tr role="row"><td class="confluenceTd">**comment** (*string*; Default: )</td><td class="confluenceTd">Short description of the interface</td></tr><tr role="row"><td class="confluenceTd">**disabled** (*yes | no*; Default: **no**)</td><td class="confluenceTd">Changes whether the bonding interface is disabled</td></tr><tr role="row"><td class="confluenceTd">**down-delay** (*time*; Default: **00:00:00**)</td><td class="confluenceTd">If a link failure has been detected, the bonding interface is disabled for a down-delay time. The value should be a multiple of mii-interval, otherwise, it will be rounded down to the nearest value. This property only has an effect when `link-monitoring` is set to `mii`.</td></tr><tr role="row"><td class="confluenceTd">**forced-mac-address** (*MAC address*; Default: **none**)</td><td class="confluenceTd">By default, the bonding interface will use the MAC address of the first selected slave interface. This property allows to configure static MAC address for the bond interface (all zeros, broadcast or multicast addresses will not apply). RouterOS will automatically change the MAC address for slave interfaces and it will be visible in `/interface ethernet` configuration export</td></tr><tr role="row"><td class="confluenceTd">**lacp-rate** (*1sec | 30secs*; Default: **30secs**)</td><td class="confluenceTd">Link Aggregation Control Protocol rate specifies how often to exchange with LACPDUs between bonding peers. Used to determine whether a link is up or other changes have occurred in the network. LACP tries to adapt to these changes providing failover.</td></tr><tr role="row"><td class="confluenceTd">**lacp-user-key** (*integer: 0..1023*; Default: 0)</td><td class="confluenceTd">Specifies the upper 10 bits of the port key. The lower 6 bits are automatically assigned based on individual port link speed and duplex. The setting is available only since RouterOS v7.3.</td></tr><tr role="row"><td class="confluenceTd">**link-monitoring** (*arp | mii | none*; Default: **mii**)</td><td class="confluenceTd">Method to use for monitoring the link (whether it is up or down) - arp - uses Address Resolution Protocol to determine whether the remote interface is reachable
- mii - uses Media Independent Interface to determine link status. Link status determination relies on the device driver.
- none - no method for link monitoring is used.

**Note:** some bonding modes require specific link monitoring to work properly.</td></tr><tr role="row"><td class="confluenceTd">**min-links** (*integer: 0..4294967295*; Default: 0)</td><td class="confluenceTd">How many active slave links needed for bonding to become active</td></tr><tr role="row"><td class="confluenceTd">**mii-interval** (*time*; Default: **00:00:00.100**)</td><td class="confluenceTd">How often to monitor the link for failures (the parameter used only if link-monitoring is mii)</td></tr><tr role="row"><td class="confluenceTd">**mlag-id** (*integer: 0..4294967295;* Default:)</td><td class="confluenceTd">Changes MLAG ID for bonding interface. The same MLAG ID should be used on both peer devices to successfully create a single MLAG. See more details on [MLAG](https://help.mikrotik.com/docs/display/ROS/Multi-chassis+Link+Aggregation+Group).</td></tr><tr role="row"><td class="confluenceTd">**mode** (*802.3ad | active-backup | balance-alb | balance-rr | balance-tlb | balance-xor | broadcast*; Default: **balance-rr**)</td><td class="confluenceTd">Specifies one of the bonding policies - 802.3ad - IEEE 802.3ad dynamic link aggregation. In this mode, the interfaces are aggregated in a group where each slave shares the same speed. It provides fault tolerance and load balancing. Slave selection for outgoing traffic is done according to the transmit-hash-policy [more&gt;](https://wiki.mikrotik.com/wiki/Manual:Interface/Bonding#802.3ad)
- active-backup - provides link backup. Only one slave can be active at a time. Another slave only becomes active, if the first one fails. [more&gt;](https://wiki.mikrotik.com/wiki/Manual:Interface/Bonding#active-backup)
- balance-alb - adaptive load balancing. The same as balance-tlb but received traffic is also balanced. The device driver should have support for changing it's MAC address. [more&gt;](https://wiki.mikrotik.com/wiki/Manual:Interface/Bonding#balance-alb)
- balance-rr - round-robin load balancing. Slaves in a bonding interface will transmit and receive data in sequential order. It provides load balancing and fault tolerance. [more&gt;](https://wiki.mikrotik.com/wiki/Manual:Interface/Bonding#balance-rr)
- balance-tlb - Outgoing traffic is distributed according to the current load on each slave. Incoming traffic is not balanced and is received by the current slave. If receiving slave fails, then another slave takes the MAC address of the failed slave. [more&gt;](https://wiki.mikrotik.com/wiki/Manual:Interface/Bonding#balance-tlb)
- balance-xor - Transmit based on the selected transmit-hash-policy. This mode provides load balancing and fault tolerance. [more&gt;](https://wiki.mikrotik.com/wiki/Manual:Interface/Bonding#balance-xor)
- broadcast - Broadcasts the same data on all interfaces at once. This provides fault tolerance but slows down traffic throughput on some slow machines. [more&gt;](https://wiki.mikrotik.com/wiki/Manual:Interface/Bonding#broadcast)

</td></tr><tr role="row"><td class="confluenceTd">**mtu** (*integer*; Default: **1500**)</td><td class="confluenceTd">Maximum Transmit Unit in bytes. Must be smaller or equal to the smallest L2MTU value of a bonding slave. L2MTU of a bonding interface is determined by the lowest L2MTU value among its slave interfaces</td></tr><tr role="row"><td class="confluenceTd">**name** (*string*; Default: )</td><td class="confluenceTd">Name of the bonding interface</td></tr><tr role="row"><td class="confluenceTd">**primary** (*string*; Default: **none**)</td><td class="confluenceTd">Controls the primary interface between active slave ports, works only for active-backup, balance-tlb and balance-alb modes. For active-backup mode, it controls which running interface is supposed to send and receive the traffic. For balance-tlb mode, it controls which running interface is supposed to receive all the traffic, but for balance-alb mode, it controls which interface is supposed to receive the unbalanced traffic (the non-IPv4 traffic). When none of the interfaces are selected as primary, device will automatically select the interface that is configured as the first one.</td></tr><tr role="row"><td class="confluenceTd">**slaves** (*string*; Default: **none**)</td><td class="confluenceTd">At least two ethernet-like interfaces separated by a comma, which will be used for bonding</td></tr><tr role="row"><td class="confluenceTd">**up-delay** (*time*; Default: **00:00:00**)</td><td class="confluenceTd">If a link has been brought up, the bonding interface is disabled for up-delay time and after this time it is enabled. The value should be a multiple of mii-interval, otherwise, it will be rounded down to the nearest value. This property only has an effect when `link-monitoring` is set to `mii`.</td></tr><tr role="row"><td class="confluenceTd">**transmit-hash-policy** (*layer-2 | layer-2-and-3 | layer-3-and-4*; Default: **layer-2**)</td><td class="confluenceTd">Selects the transmit hash policy to use for slave selection in balance-xor and 802.3ad modes - layer-2 - Uses XOR of hardware MAC addresses to generate the hash. This algorithm will place all traffic to a particular network peer on the same slave. This algorithm is 802.3ad compliant.
- layer-2-and-3 - This policy uses a combination of layer2 and layer3 protocol information to generate the hash. Uses XOR of hardware MAC addresses and IP addresses to generate the hash. This algorithm will place all traffic to a particular network peer on the same slave. For non-IP traffic, the formula is the same as for the layer2 transmit hash policy. This policy is intended to provide a more balanced distribution of traffic than layer2 alone, especially in environments where a layer3 gateway device is required to reach most destinations. This algorithm is 802.3ad compliant.
- layer-3-and-4 - This policy uses upper layer protocol information, when available, to generate the hash. This allows for traffic to a particular network peer to span multiple slaves, although a single connection will not span multiple slaves. For fragmented TCP or UDP packets and all other IP protocol traffic, the source and destination port information is omitted. For non-IP traffic, the formula is the same as for the layer2 transmit hash policy. This algorithm is not fully 802.3ad compliant.

</td></tr></tbody></table>

</div>

# Bonding Examples

### <span class="mw-headline">Bonding EoIP tunnels over two wireless links</span>

This is an example of aggregating multiple network interfaces into a single pipe. In particular, it is shown how to aggregate multiple virtual (EoIP) interfaces to get maximum throughput (MT) with emphasis on availability.

### <span class="mw-headline">Network Diagram</span>

Two routers R1 and R2 are interconnected via wireless links. Wireless interfaces on both sides have assigned IP addresses.

[![image.png](https://techblog.jcditservices.com/uploads/images/gallery/2024-10/scaled-1680-/Hk5image.png)](https://techblog.jcditservices.com/uploads/images/gallery/2024-10/Hk5image.png)

### <span class="mw-headline">Configuration</span>

Bonding could be used only on OSI layer 2 (Ethernet level) connections. Thus we need to create EoIP interfaces on each of the wireless links. This is done as follows:

on router R1:

<div class="wiki-content" id="bkmrk-%2Finterface-eoip-add-"><div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/interface eoip add remote-address=10.0.1.1/24 tunnel-id=1 </span>/interface eoip add remote-address=10.2.2.1/24 tunnel-id=2`</span></div></div></div></div>and on router R2:

<div class="wiki-content" id="bkmrk-%2Finterface-eoip-add--1"><div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/interface eoip add remote-address=10.0.1.2/24 tunnel-id=1 </span>/interface eoip add remote-address=10.2.2.2/24 tunnel-id=2`</span></div></div></div></div>The second step is to add a bonding interface and specify EoIP interfaces as slaves:

R1:

<div class="wiki-content" id="bkmrk-%2Finterface-bonding-a"><div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/interface bonding add slaves=eoip-tunnel1,eoip-tunnel2 mode=balance-rr</span>`</span></div></div></div></div>R2:

<div class="wiki-content" id="bkmrk-%2Finterface-bonding-a-1"><div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/interface bonding add slaves=eoip-tunnel1,eoip-tunnel2 mode=balance-rr</span>`</span></div></div></div></div>The last step is to add IP addresses to the bonding interfaces:

R1:

<div class="wiki-content" id="bkmrk-%2Fip-address-add-addr"><div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/ip address add address 192.168.0.1/24 interface=bonding1</span>`</span></div></div></div></div>R2:

<div class="wiki-content" id="bkmrk-%2Fip-address-add-addr-1"><div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/ip address add address 192.168.0.2/24 interface=bonding1</span>`</span></div></div></div></div>### <span class="mw-headline">Test the configuration</span>

Now two routers are able to reach each other using addresses from the 192.168.0.0/24 network. To verify bonding interface functionality, do the following:

R1:

<div class="wiki-content" id="bkmrk-%2Finterface-monitor-t"><div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/interface monitor-traffic eoip-tunnel1,eoip-tunnel2</span>`</span></div></div></div></div>R2:

<div class="wiki-content" id="bkmrk-%2Ftool-bandwidth-test"><div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/tool bandwidth-test 192.168.0.1 direction=transmit</span>`</span></div></div></div></div>You should see that traffic is distributed equally across both EoIP interfaces:

<div class="wiki-content" id="bkmrk-%2Fint-monitor-traffic"><div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-3686h1" data-code-lang="text" data-ds--code--code-block="">`<span class="">/int monitor-traffic eoip-tunnel1,eoip-tunnel2              </span>    received-packets-per-second: 685      685                                         received-bits-per-second: 8.0Mbps  8.0Mbps                                      sent-packets-per-second: 21       20                                              sent-bits-per-second: 11.9kbps 11.0kbps                                 received-packets-per-second: 898      899                                         received-bits-per-second: 10.6Mbps 10.6Mbps                                     sent-packets-per-second: 20       21                                              sent-bits-per-second: 11.0kbps 11.9kbps                                 received-packets-per-second: 975      975                                         received-bits-per-second: 11.5Mbps 11.5Mbps                                     sent-packets-per-second: 22       22                                              sent-bits-per-second: 12.4kbps 12.3kbps                                 received-packets-per-second: 980      980                                         received-bits-per-second: 11.6Mbps 11.6Mbps                                     sent-packets-per-second: 21       21                                              sent-bits-per-second: 11.9kbps 11.8kbps                                 received-packets-per-second: 977      977                                         received-bits-per-second: 11.6Mbps 11.5Mbps                                     sent-packets-per-second: 21       21                                              sent-bits-per-second: 11.9kbps 11.8kbps                             -- [Q quit|D dump|C-z pause]`</span></div></div></div></div>### <span class="mw-headline">Link Monitoring</span>

It is easy to notice that with the configuration above as soon as any individual link fails, the bonding interface throughput collapses. That's because no link monitoring is performed, consequently, the bonding driver is unaware of problems with the underlying links. Enabling link monitoring is a must in most bonding configurations. To enable ARP link monitoring, do the following:

R1:

<div class="wiki-content" id="bkmrk-%2Finterface-bonding-s"><div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/interface bonding set bonding1 link-monitoring=arp arp-ip-targets=192.168.0.2</span>`</span></div></div></div></div>R2:

<div class="wiki-content" id="bkmrk-%2Finterface-bonding-s-1"><div class="code panel pdl conf-macro output-block" data-hasbody="true" data-macro-name="code"><div class="codeContent panelContent pdl"><div class="codeBlockContainer_yyk2gsoAwjaamghp6yoO-Q=="><span class="prismjs css-nc0a95" data-code-lang="text" data-ds--code--code-block="">`<span class="">/interface bonding set bonding1 link-monitoring=arp arp-ip-targets=192.168.0.1</span>`</span></div></div></div></div>