Mikrotik Ubuntu L2TPv3 one server six mikrotik

From wiki karavi
Revision as of 19:44, 21 June 2026 by Karavi (talk | contribs) (Created page with "== L2TPv3 Tunnel: One Linux Server to Multiple MikroTik Routers == === Overview === This guide explains how to connect one Linux server to six MikroTik routers using static L2TPv3 tunnels via <code>ql2tpd</code>. {| class="wikitable" ! # !! MikroTik IP !! Server Tunnel IP !! Client Tunnel IP !! tid !! ptid !! sid !! psid |- | 0 (existing) || 78.157.42.222 || 10.0.0.1/30 || 10.0.0.2/30 || 100 || 200 || 1000 || 2000 |- | 1 || 85.57.4.221 || 10.0.1.1/30 || 10.0.1.2/30 ||...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

L2TPv3 Tunnel: One Linux Server to Multiple MikroTik Routers

Overview

This guide explains how to connect one Linux server to six MikroTik routers using static L2TPv3 tunnels via ql2tpd.

# MikroTik IP Server Tunnel IP Client Tunnel IP tid ptid sid psid
0 (existing) 78.157.42.222 10.0.0.1/30 10.0.0.2/30 100 200 1000 2000
1 85.57.4.221 10.0.1.1/30 10.0.1.2/30 101 201 1001 2001
2 85.57.4.222 10.0.2.1/30 10.0.2.2/30 102 202 1002 2002
3 85.57.4.223 10.0.3.1/30 10.0.3.2/30 103 203 1003 2003
4 85.57.4.224 10.0.4.1/30 10.0.4.2/30 104 204 1004 2004
5 85.57.4.225 10.0.5.1/30 10.0.5.2/30 105 205 1005 2005

---

Linux Server Setup (157.90.26.4)

1. Update ql2tpd configuration

cat > /etc/ql2tpd/ql2tpd.toml << 'EOF'
[tunnel.t1]
  version = "l2tpv3"
  encap = "ip"
  local = "157.90.26.4:0"
  peer = "78.157.42.222:0"
  tid = 100
  ptid = 200
  [tunnel.t1.session.s1]
    pseudowire = "eth"
    sid = 1000
    psid = 2000
    interface_name = "l2tpeth0"

[tunnel.t2]
  version = "l2tpv3"
  encap = "ip"
  local = "157.90.26.4:0"
  peer = "85.57.4.221:0"
  tid = 101
  ptid = 201
  [tunnel.t2.session.s1]
    pseudowire = "eth"
    sid = 1001
    psid = 2001
    interface_name = "l2tpeth1"

[tunnel.t3]
  version = "l2tpv3"
  encap = "ip"
  local = "157.90.26.4:0"
  peer = "85.57.4.222:0"
  tid = 102
  ptid = 202
  [tunnel.t3.session.s1]
    pseudowire = "eth"
    sid = 1002
    psid = 2002
    interface_name = "l2tpeth2"

[tunnel.t4]
  version = "l2tpv3"
  encap = "ip"
  local = "157.90.26.4:0"
  peer = "85.57.4.223:0"
  tid = 103
  ptid = 203
  [tunnel.t4.session.s1]
    pseudowire = "eth"
    sid = 1003
    psid = 2003
    interface_name = "l2tpeth3"

[tunnel.t5]
  version = "l2tpv3"
  encap = "ip"
  local = "157.90.26.4:0"
  peer = "85.57.4.224:0"
  tid = 104
  ptid = 204
  [tunnel.t5.session.s1]
    pseudowire = "eth"
    sid = 1004
    psid = 2004
    interface_name = "l2tpeth4"

[tunnel.t6]
  version = "l2tpv3"
  encap = "ip"
  local = "157.90.26.4:0"
  peer = "85.57.4.225:0"
  tid = 105
  ptid = 205
  [tunnel.t6.session.s1]
    pseudowire = "eth"
    sid = 1005
    psid = 2005
    interface_name = "l2tpeth5"
EOF

2. Restart service

systemctl restart ql2tpd
sleep 2

3. Assign tunnel IPs

ip addr add 10.0.1.1/30 dev l2tpeth1 && ip link set l2tpeth1 up
ip addr add 10.0.2.1/30 dev l2tpeth2 && ip link set l2tpeth2 up
ip addr add 10.0.3.1/30 dev l2tpeth3 && ip link set l2tpeth3 up
ip addr add 10.0.4.1/30 dev l2tpeth4 && ip link set l2tpeth4 up
ip addr add 10.0.5.1/30 dev l2tpeth5 && ip link set l2tpeth5 up

4. Persist IPs after reboot

cat > /etc/networkd-dispatcher/routable.d/l2tp-ip.sh << 'EOF'
#!/bin/bash
sleep 3
ip addr add 10.0.0.1/30 dev l2tpeth0 2>/dev/null && ip link set l2tpeth0 up 2>/dev/null
ip addr add 10.0.1.1/30 dev l2tpeth1 2>/dev/null && ip link set l2tpeth1 up 2>/dev/null
ip addr add 10.0.2.1/30 dev l2tpeth2 2>/dev/null && ip link set l2tpeth2 up 2>/dev/null
ip addr add 10.0.3.1/30 dev l2tpeth3 2>/dev/null && ip link set l2tpeth3 up 2>/dev/null
ip addr add 10.0.4.1/30 dev l2tpeth4 2>/dev/null && ip link set l2tpeth4 up 2>/dev/null
ip addr add 10.0.5.1/30 dev l2tpeth5 2>/dev/null && ip link set l2tpeth5 up 2>/dev/null
EOF
chmod +x /etc/networkd-dispatcher/routable.d/l2tp-ip.sh

---

MikroTik 1 — 85.57.4.221

/interface l2tp-ether add name=l2tpv3 connect-to=157.90.26.4 local-address=85.57.4.221 local-tunnel-id=201 remote-tunnel-id=101 local-session-id=2001 remote-session-id=1001 l2tp-proto-version=l2tpv3-ip unmanaged-mode=yes disabled=no
/ip address add address=10.0.1.2/30 interface=l2tpv3

---

MikroTik 2 — 85.57.4.222

/interface l2tp-ether add name=l2tpv3 connect-to=157.90.26.4 local-address=85.57.4.222 local-tunnel-id=202 remote-tunnel-id=102 local-session-id=2002 remote-session-id=1002 l2tp-proto-version=l2tpv3-ip unmanaged-mode=yes disabled=no
/ip address add address=10.0.2.2/30 interface=l2tpv3

---

MikroTik 3 — 85.57.4.223

/interface l2tp-ether add name=l2tpv3 connect-to=157.90.26.4 local-address=85.57.4.223 local-tunnel-id=203 remote-tunnel-id=103 local-session-id=2003 remote-session-id=1003 l2tp-proto-version=l2tpv3-ip unmanaged-mode=yes disabled=no
/ip address add address=10.0.3.2/30 interface=l2tpv3

---

MikroTik 4 — 85.57.4.224

/interface l2tp-ether add name=l2tpv3 connect-to=157.90.26.4 local-address=85.57.4.224 local-tunnel-id=204 remote-tunnel-id=104 local-session-id=2004 remote-session-id=1004 l2tp-proto-version=l2tpv3-ip unmanaged-mode=yes disabled=no
/ip address add address=10.0.4.2/30 interface=l2tpv3

---

MikroTik 5 — 85.57.4.225

/interface l2tp-ether add name=l2tpv3 connect-to=157.90.26.4 local-address=85.57.4.225 local-tunnel-id=205 remote-tunnel-id=105 local-session-id=2005 remote-session-id=1005 l2tp-proto-version=l2tpv3-ip unmanaged-mode=yes disabled=no
/ip address add address=10.0.5.2/30 interface=l2tpv3

---

Verification

From Linux server:

ping 10.0.1.2 -c 2
ping 10.0.2.2 -c 2
ping 10.0.3.2 -c 2
ping 10.0.4.2 -c 2
ping 10.0.5.2 -c 2

From each MikroTik:

/ping 10.0.X.1 count=4

---

Troubleshooting

Symptom Cause Fix
Interface not created ql2tpd not restarted systemctl restart ql2tpd
Link stays DOWN MikroTik sending control messages Verify unmanaged-mode=yes
No packets arriving Firewall blocking proto 115 Allow IP protocol 115 on both sides
IP lost after reboot persistence script not updated Re-run step 4
Wrong tunnel match Duplicate tid/ptid/sid/psid Verify IDs are unique per tunnel

---

Notes

  • Each tunnel must have unique tid, ptid, sid, and psid values.
  • Each MikroTik's local-tunnel-id must match the server's ptid for that tunnel, and vice versa.
  • All tunnels share the same Linux server public IP (157.90.26.4) — this is supported since each tunnel is differentiated by its tunnel ID.
  • No encryption is applied by default. For production use, consider wrapping tunnels with IPsec.

---

References