AKZN Notes

Archives for My Lazy and Forgetful Mind

Configure Two ISP on Mikrotik using VLAN with Openwrt

Last Modified on

Why ?

  1. I want to load balance on Openwrt Openclash
  2. OPENWRT on STB has only one RJ45 port
  3. Mikrotik has multiple port, so we can use vlan to route two ISP into Openwrt

Mikrotik Setting


Based on my current configuration, I use Ether1 as WAN2 and Ether2 as WAN1

  1. Make sure we already setting ip> addresses, route, and nat masquerade on Ether1[wan2] and Ether2[wan1]. In this case i create DHCP client for both of them

    • ether2

      ip dhcp-client add-default-route=yes

    • ether1

      ip dhcp-client add-default-route=no

    • Make route failover to WAN2 because we set add-default-route=no to wan 2

      ip route dst-address=0.0.0.0/0 gateway=[ip router WAN2] Check-gateway=ping distance=2

  2. Add vlan on interface, on some article ,vlan naming convention use ip third subnet as name, In this case, I use 192.168.[88].1 so vlan id is 88

    /interface vlan
    add name=vlan-88  interface=ether2  vlan-id=88
  3. Create address using vlan interface created above

    ip addresses :192.168.88.1/24 interface=vlan-88

  4. Configure MIkrotik DHCP server for vlan

    ip dhcp-server interface : vlan-88

  5. Create route to WAN2 and add routing mark to be used wiht IP pool from VLAN
    this step is to make openwrt can use internet from wan2

    /ip route
    add dst-address=0.0.0.0/0 gateway=ip-gateway-isp-2 distance=2 check-gateway=ping routing-mark=wan2 ;
  6. make route rule to route VLAN address list to ISP2
    /ip route rule
    add action=lookup disabled=no src-address=192.168.88.0/24 dst-address=0.0.0.0/0 table=wan2 ; <- the outgoing via wan2 always.

OpenWRT Setting


DHCP Server

default dhcp server setting on lan or bridge interface should works, on this case I set bridge-lan interface using ip 10.5.51.1/24

VLAN DHCP CLient

CLI version source Openwrt DOCs

Add Virtual Device

notes below are using LUCI.

  1. Network > interfaces > devices > add new
    device type choose vlan (802.1q)
  2. base device use eth0 (or any physical eth on device)
  3. Vlan id 88 (as per this notes)
  4. device name eth0.88 (or any of your choices)

Add Virtual Interface

  1. Network > interfaces > interfaces > add new
  2. Name VLAN88 (or any of your choices)
  3. Protocol DHCP Static
  4. Device : eth0.88

Save and restart openwrt device.

More setting to be configured

opewrt

to make client to be able to ping wan MIKROTIK we need to add route
linux

ip route add <destination_ip> via <gateway_ip> dev <interface_name>

busybox

route add -net <destination_network> netmask <netmask> gw <gateway_ip>

above is not persistent,

To make the route persistent (survive reboots) on OpenWRT, you can add the route configuration to the network configuration files. For example, for a static route, edit the /etc/config/network file:

config route
    option interface '<interface_name>'
    option target '<destination_ip>'
    option gateway '<gateway_ip>'
    option netmask '<netmask>'

Replace <interface_name>, <destination_ip>, <gateway_ip>, and <netmask> with your specific values. After editing the file, save and apply the changes:

/etc/init.d/network restart

This ensures that the route configuration persists across reboots.


Common Problem

  • cant ping if using unmanaged switch, this is because unmanaged switch usually only has 1500 MTU, and VLAN add 4 more byte to 1504 making random error.

Leave a Reply

Your email address will not be published.