<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: htin linn</title>
    <description>The latest articles on DEV Community by htin linn (@htinlinn).</description>
    <link>https://dev.to/htinlinn</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4068580%2F7fb252a3-9cfd-45f1-9c0b-449a7f824359.png</url>
      <title>DEV Community: htin linn</title>
      <link>https://dev.to/htinlinn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/htinlinn"/>
    <language>en</language>
    <item>
      <title>How to Configure PCC Load Balancing and Failover on MikroTik RouterOS</title>
      <dc:creator>htin linn</dc:creator>
      <pubDate>Sat, 08 Aug 2026 10:18:37 +0000</pubDate>
      <link>https://dev.to/htinlinn/how-to-configure-pcc-load-balancing-and-failover-on-mikrotik-routeros-5gmg</link>
      <guid>https://dev.to/htinlinn/how-to-configure-pcc-load-balancing-and-failover-on-mikrotik-routeros-5gmg</guid>
      <description>&lt;p&gt;published: true&lt;/p&gt;

&lt;h2&gt;
  
  
  tags: mikrotik, networking, sysadmin, routeros
&lt;/h2&gt;

&lt;p&gt;Managing multiple Internet Service Provider (ISP) connections is essential for high-availability enterprise networks. Relying on a single WAN connection creates a point of failure, whereas combining dual ISPs ensures both traffic distribution and network redundancy.&lt;/p&gt;

&lt;p&gt;In this guide, we will set up &lt;strong&gt;Per Connection Classifier (PCC) Load Balancing&lt;/strong&gt; alongside automated &lt;strong&gt;Failover&lt;/strong&gt; on MikroTik RouterOS using two active WAN links.&lt;/p&gt;




&lt;h2&gt;
  
  
  Prerequisites &amp;amp; WAN Setup
&lt;/h2&gt;

&lt;p&gt;For this demonstration, we assume two ISP connections connected to a MikroTik router:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ISP 1 (Primary / Dedicated):&lt;/strong&gt; Ethernet port &lt;code&gt;ether1_ISP1&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ISP 2 (Secondary / Backup):&lt;/strong&gt; Ethernet port &lt;code&gt;ether2_ISP2&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Local Network (LAN):&lt;/strong&gt; Ethernet port &lt;code&gt;bridge_LAN&lt;/code&gt; (&lt;code&gt;192.168.88.0/24&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Step 1: Interface IP Address Assignment
&lt;/h2&gt;

&lt;p&gt;Assign static IP addresses provided by your ISPs and configure your local gateway IP:&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
routeros
/ip address
add address=192.168.88.1/24 interface=bridge_LAN network=192.168.88.0
add address=1.1.1.2/30 interface=ether1_ISP1 network=1.1.1.0
add address=2.2.2.2/30 interface=ether2_ISP2 network=2.2.2.0
Step 2: Configure Firewall NAT Rules
Configure Network Address Translation (NAT) masquerading for both WAN interfaces to grant internet access to internal clients:
/ip firewall nat
add chain=srcnat out-interface=ether1_ISP1 action=masquerade
add chain=srcnat out-interface=ether2_ISP2 action=masquerade
Step 3: Configure Mangle Rules for PCC Marking
We use Per Connection Classifier (PCC) to split traffic evenly across both ISP links based on source/destination address pairs.
1. Accept Connections to Internal Subnets
Prevent local network traffic from being load-balanced:
/ip firewall mangle
add chain=prerouting dst-address=192.168.88.0/24 action=accept in-interface=bridge_LAN
2. Mark Incoming Connections from ISPs
Ensure responses to inbound traffic leave through the exact same interface they entered:
/ip firewall mangle
add chain=prerouting in-interface=ether1_ISP1 connection-state=new action=mark-connection new-connection-mark=ISP1_conn passthrough=yes
add chain=prerouting in-interface=ether2_ISP2 connection-state=new action=mark-connection new-connection-mark=ISP2_conn passthrough=yes
3. Apply PCC Rules to LAN Traffic
Distribute outgoing connections equally between both links:
/ip firewall mangle
add chain=prerouting in-interface=bridge_LAN connection-state=new per-connection-classifier=both-addresses-and-ports:2/0 action=mark-connection new-connection-mark=ISP1_conn passthrough=yes
add chain=prerouting in-interface=bridge_LAN connection-state=new per-connection-classifier=both-addresses-and-ports:2/1 action=mark-connection new-connection-mark=ISP2_conn passthrough=yes
4. Assign Routing Marks
​Translate connection marks into routing decisions:
/ip firewall mangle
add chain=prerouting in-interface=bridge_LAN connection-mark=ISP1_conn action=mark-routing new-routing-mark=to_ISP1 passthrough=no
add chain=prerouting in-interface=bridge_LAN connection-mark=ISP2_conn action=mark-routing new-routing-mark=to_ISP2 passthrough=no
Step 4: Configure Static Routes and Dynamic Failover
​Configure default routes using check-gateway monitoring (ping) to automatically reroute traffic if an ISP connection fails.
# Routes for marked traffic
/ip route
add dst-address=0.0.0.0/0 gateway=1.1.1.1 distance=1 routing-table=to_ISP1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=2.2.2.1 distance=1 routing-table=to_ISP2 check-gateway=ping

# Fallback default routes for unmarked router traffic
add dst-address=0.0.0.0/0 gateway=1.1.1.1 distance=1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=2.2.2.1 distance=2 check-gateway=ping
Step 5: Verification &amp;amp; Testing
​1. Check Firewall Connections
​Navigate to IP &amp;gt; Firewall &amp;gt; Connections in WinBox or execute:
/ip firewall connection print
Verify that active connections display connection-mark=ISP1_conn and connection-mark=ISP2_conn evenly.
Unplug the network cable for ether1_ISP1. The router should detect link failure via the check-gateway=ping health check and automatically shift all active network flows through ether2_ISP2 within seconds.Conclusion
Combining PCC load balancing with check-gateway ping monitoring in RouterOS maximizes WAN utilization while building automatic network redundancy. This dynamic routing strategy ensures optimal network stability for bandwidth-intensive environments.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>mikrotik</category>
      <category>networking</category>
      <category>sysadmin</category>
      <category>routeros</category>
    </item>
    <item>
      <title>WireGuard Site-to-Site VPN on Linux</title>
      <dc:creator>htin linn</dc:creator>
      <pubDate>Sat, 08 Aug 2026 09:43:19 +0000</pubDate>
      <link>https://dev.to/htinlinn/wireguard-site-to-site-vpn-on-linux-1p03</link>
      <guid>https://dev.to/htinlinn/wireguard-site-to-site-vpn-on-linux-1p03</guid>
      <description>&lt;p&gt;Connecting separate office locations or data centers securely over the public internet is a critical task for network engineers and system administrators. Traditional VPN solutions like IPsec or OpenVPN can be complex to configure and resource-heavy. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;WireGuard&lt;/strong&gt; provides an extremely fast, modern, and lean alternative that utilizes state-of-the-art cryptography. In this tutorial, we will walk through configuring a production-ready &lt;strong&gt;Site-to-Site WireGuard VPN&lt;/strong&gt; connecting two Linux gateways.&lt;/p&gt;




&lt;h2&gt;
  
  
  Network Topology Overview
&lt;/h2&gt;

&lt;p&gt;Before diving into configuration, let's define our environment topology:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Site A (Headquarters):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Public IP:&lt;/strong&gt; &lt;code&gt;203.0.113.10&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Internal Subnet:&lt;/strong&gt; &lt;code&gt;192.168.10.0/24&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;WireGuard Gateway Interface:&lt;/strong&gt; &lt;code&gt;wg0&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;WireGuard IP:&lt;/strong&gt; &lt;code&gt;10.0.0.1/30&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Site B (Branch Office):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Public IP:&lt;/strong&gt; &lt;code&gt;198.51.100.20&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Internal Subnet:&lt;/strong&gt; &lt;code&gt;192.168.20.0/24&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;WireGuard Gateway Interface:&lt;/strong&gt; &lt;code&gt;wg0&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;WireGuard IP:&lt;/strong&gt; &lt;code&gt;10.0.0.2/30&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Step 1: Installing WireGuard on Both Gateways
&lt;/h2&gt;

&lt;p&gt;First, install WireGuard and necessary networking utilities on both Linux gateways (Debian/Ubuntu-based example):&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
bash
sudo apt update
sudo apt install -y wireguard iptables


(For RedHat/CentOS/Rocky Linux systems, use sudo dnf install -y wireguard-tools iptables).
Step 2: Enable IP Forwarding
For a Site-to-Site VPN, the Linux gateways must forward packets between internal subnets and the WireGuard interface.
On both Site A and Site B gateways, enable IP forwarding permanently:
echo "net.ipv4.ip_forward = 1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
Step 3: Key Generation
WireGuard uses public/private key pairs for peer authentication.
On Site A Gateway:
cd /etc/wireguard
umask 077
wg genkey | tee privatekey | wg pubkey &amp;gt; publickey
On Site B Gateway:
cd /etc/wireguard
umask 077
wg genkey | tee privatekey | wg pubkey &amp;gt; publickey
Note: Keep private keys strictly confidential and readable only by root.
Step 4: Configuring Site A Gateway (/etc/wireguard/wg0.conf)
Create the configuration file on Site A:

sudo nano /etc/wireguard/wg0.conf
Add the following content (replace keys with your actual generated keys):

[Interface]
Address = 10.0.0.1/30
ListenPort = 51820
PrivateKey = &amp;lt;SITE_A_PRIVATE_KEY&amp;gt;

# PostUp and PostDown rules for NAT routing across internal interface (eth0)
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE

[Peer]
# Site B Details
PublicKey = &amp;lt;SITE_B_PUBLIC_KEY&amp;gt;
Endpoint = 198.51.100.20:51820
# Allow WireGuard tunnel IP and Site B internal subnet
AllowedIPs = 10.0.0.2/32, 192.168.20.0/24
PersistentKeepalive = 25
Step 5: Configuring Site B Gateway (/etc/wireguard/wg0.conf)
Create the configuration file on Site B:
sudo nano /etc/wireguard/wg0.conf
Add the following content:
[Interface]
Address = 10.0.0.2/30
ListenPort = 51820
PrivateKey = &amp;lt;SITE_B_PRIVATE_KEY&amp;gt;

PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE

[Peer]
# Site A Details
PublicKey = &amp;lt;SITE_A_PUBLIC_KEY&amp;gt;
Endpoint = 203.0.113.10:51820
# Allow WireGuard tunnel IP and Site A internal subnet
AllowedIPs = 10.0.0.1/32, 192.168.10.0/24
PersistentKeepalive = 25

Step 6: Starting and Enabling the WireGuard Tunnel
Start the interface and enable auto-start on boot for both gateways:
sudo systemctl enable --now wg-quick@wg0
Step 7: Verifying Tunnel and Route Connectivity
1. Check WireGuard Status
Execute the following command on either gateway to verify the active peer handshake:
sudo wg show

2. Test Ping Across Tunnels
From Site A Gateway, ping Site B's internal IP:
ping -c 4 10.0.0.2
ping -c 4 192.168.20.1
From a workstation inside Site A (192.168.10.50), ping a machine in Site B (192.168.20.50) to confirm cross-subnet routing.
Step 8: Adding Static Routes on Local Routers (Optional)
If your Linux gateways are separate from your core LAN routers, remember to add a static route on your primary LAN router:
Site A LAN Router: Destination 192.168.20.0/24 via Next Hop 192.168.10.X (Site A Linux Gateway).
Site B LAN Router: Destination 192.168.10.0/24 via Next Hop 192.168.20.X (Site B Linux Gateway).
Conclusion
WireGuard provides high-performance encrypted transport with minimal overhead compared to legacy VPN protocols. By enabling IP forwarding, setting precise AllowedIPs routing policies, and configuring iptables post-up actions, you can establish a secure and efficient site-to-site communication channel across remote sites.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>linux</category>
      <category>vpn</category>
      <category>networking</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
