[EP.35] How to Configure Wireguard Client to Site VPN (RouterOS v7)

Krittin Srithong
techblogclub
Published in
3 min readMay 18, 2022

--

Scenario

ข้อกำหนด

  1. จะต้องเป็น MikroTik RouterOS 7 ขึ้นไป (ใน LAB นี้ใช้ RouterOS 7.2.3 Stable)
  2. ฝั่ง Main Router จะต้องได้รับ Public IP จาก ผู้ให้บริการ เท่านั้น เพราะ ฝั่งเครื่อง Client จะต้อง Remote เข้ามาผ่าน Dynamic DNS ของ Main Router

วิธีการ Config WireGuard

  1. เปิดใช้งาน Dynamic DNS ของ RouterOS
  • ไปที่ IP > Cloud
  • ติ๊ก DDNS Enabled
  • กด Apply และ OK

2. สร้าง WireGuard Interface และกำหนดค่า IP Address ให้กับ Interface ของ WireGuard

2.1) สร้าง WireGuard Interface

  • ไปที่เมนู WireGuard แท็ป WireGuard
  • กด +
  • กด OK เลย
หลังจากกดปุ่ม OK จะสังเกตุได้ว่า WireGuard จะสร้าง Private Key และ Public Key ขึ้นมาให้เราอัตโนมัติ

2.2) กำหนดค่า IP Address ให้กับ Interface ของ WireGuard

  • ไปที่เมนู IP > Addresses
  • กด +
  • Address: 172.16.0.1/24 (คือการสร้างขา Local Address นั้นเอง โดยการกำหนดค่า IP Address ท่านสามารถเลือกใช้ Private IP Address ได้ตามใจชอบเลย)
  • Network: 172.16.0.0
  • Interface: wireguard1
  • กด OK

3. ดาวน์โหลด & ติดตั้งโปรแกรม WireGuard (สำหรับในบทความนี้จะสอนการเชื่อมต่อของ Windows เท่านั่น)

  • WireGuard For Windows: https://www.wireguard.com/install/
  • สำหรับ iOS และ Android: ดาวน์โหลดได้โปรแกรมได้จาก Apple Store และ Google Play Store ซึ่งวิธีการ Config นั่น ทำคล้ายกับ Windows เลยครับ ลองไปทำกันดูครับ

4. เพิ่ม Tunnel ฝั่ง Client สำหรับเชื่อมต่อไปยัง Server (Main Router)

  • เปิดโปรแกรม WireGuard
  • กด Add empty tunnel… หรือ Ctrl+N
  • จะได้หน้าตาลักษณะนี้
  • ให้คลิกขวาและ Copy Public Key เอาไว้ และอย่าพึ่งปิดหน้าต่าง
  • เมื่อคลิกขวาและ Copy Public Key เสร็จ ให้กลับมาที่ตัว Winbox
  • ไปที่เมนู WireGuard > แท็ป Peers
  • กด +
  • Interface: เลือกเป็น wireguard1
  • Public Key: ให้ Paste Public Key ที่ได้ไปก๊อปมา
  • Allowed Address: 172.16.0.2/32 (IP สำหรับ Remote เข้ามานั่นเอง)
  • กด Apply และ OK
  • ไปที่เมนู Wireguard > แท็ป WireGuard
  • ดับเบิ้ลคลิก “wireguard1" และ คัดลอง Public Key ของ “wireguard1” มา
  • กลับมาที่หน้าโปรแกรม Wireguard อีกครั้ง ที่ท่านได้เปิดค้างเอาไว้
  • ต่อมาเราจะมาเขียนค่า Setting ของ Tunnel กัน
  • Name: wg0 (ตั้งชื่อ)

ส่วน [Interface]

  • PrivateKey = ระบบสร้างมาให้อัตโนมัติอยู่แล้ว ไม่ต้องไปแก้ไขอะไร
  • Address = 172.16.0.2/32 (IP Remote ต้องตรงกับใน Peers ด้วย)
  • DNS = 1.1.1.1, 1.0.0.1 (DNS Server ใช้เจ้าไหนก็ได้)

ส่วน [Peer]

  • PublicKey = วาง Public Key ของ “wireguard1” ที่ได้ไป คักลอกมา
  • AllowedIPs = 0.0.0.0/0 คือให้เครื่องฝั่ง Client ที่ Remote มา สามารถ Route ไปยังทุกวงของ Main Router ได้
  • Endpoint = กรอก xXx.sn.mynetname.net:13231 (Dynamic DNS ของฝั่ง Main Router)
  • PersistentKeepalive = 10 (เช็ค Connection ทุกๆ 10 วิ)
  • กด Save

5. ทำ NAT

  • ไปที่ IP > Firewall > แท็ป NAT
  • กด +
  • Chain: srcnat
  • Action: masquerade
  • กด OK

6. ทดสอบเชื่อมต่อ Wireguard VPN

  • กด Activate

--

--

Krittin Srithong
techblogclub

Hi, I’m Krittin. I am studying in bachelor of Computer Enginnering. I have MikroTik Certificates as following MTCNA, MTCSE, MTCUME. (medium.com/techblogclub)