บทความสำหรับ: ผู้ที่มีความรู้เกี่ยวกับระบบเครือข่ายในระดับเบื้องต้นถึงปานกลาง (v1.1)
โดย วิทวัส โฉมประเสริฐ, ศุภสิทธิ์ ศิริพานิชกร, เจตน์สันติ์ ยาวิลาศ
คำถาม
ต้องการทำ LoadBalance รวมเน็ตจำนวน 2 เส้น โดยเซ็ตโมเด็มเป็นแบบบริดจ์ทั้งหมด แล้วให้ MikroTik รุ่น RB750GL เป็นสั่งการเชื่อมต่อ PPPOE ต้องทำอย่างไร?
คำตอบ
สืบเนื่องมาจากคู่มือ -> 2.1 ติดตั้ง LoadBalance RB750GL แบบ 4 PPPOE to 1LAN มีหลายท่านต้องการให้ปรับ code มาเป็นแบบ 2 WAN + 1 LAN + HotSpot ดังนั้นทีมงานได้จัดทำ Script สำหรับความต้องการดังนี้นะครับ
Port1 - WAN1 (PPPoE1)
Port2 - WAN2 (PPPoE2)
Port3 - NONE (ไม่ใช้งาน)
Port4 - Loadbalance WAN1,WAN2 + Hotspot (จะไม่รวมเน็ตทั้ง 2 เส้น แต่จะเป็น link backup โดยเวลา link ไหนมีปัญหาก็จะสลับไปอีก link ที่ใช้งานได้ให้อัตโนมัติ)
port5 - Loadbalance WAN1,WAN2 (รวมเน็ตทั้ง 2 เส้น)
- การเซต Loadbalance เข้า port1,2 ออก port5
- ดาวน์โหลด Winbox แล้วเสียบสาย LAN ขา Ether5 ของ MikroTik
เข้าโปรแกรม Winbox แล้วคลิกเลือก mac address MikroTik ที่ broadcast เจอ แล้วกด Connect - จะมี mac address ของขา LAN Mikrotik ที่เราเชื่อมต่ออยู่ ขึ้นมา กด Connect เพื่อเชื่อมต่อ
- Winbox กำลังเชื่อมต่อเข้าไปยัง Mikrotik
- ปกติแล้ว MikroTik แทบทุกรุ่นจะมี config default ให้ แต่เราจะไม่ใช่ครับ กด Remove Configuration ได้เลย
- RB750GL จะทำการ Remove config default ออก แล้วจะ reboot ตัวเอง ถ้าเกิด message เด้งขึ้นมา ก็ไม่ต้องตกใจน่ะครับ
- สร้าง Connection PPPOE ผ่านเมนู PPP
- ที่เมนู PPP กดปุ่ม + เพื่อสร้าง PPPOE โดยเลือก PPPOE Client
- สร้าง pppoe-out1 (3BB-7b)
- สร้าง pppoe-out2 (TRUE-7b)
- เนื่องด้วยถ้าทำในรูปแบบ Interface นั้นจะต้อง Capture หน้าจอเยอะมาก ผมจึงขอเปลี่ยนไปใช้วิธี code ผ่าน Terminal น่ะครับ
เข้าเมนู New Terminal > Terminal
Script : 2 WAN(PPPoE) to 1 LAN- โค้ด: เลือกทั้งหมด
#|/ip address
/ip address add address=192.168.0.1/24 network=192.168.0.0 broadcast=192.168.0.255 interface=ether5 comment="default configuration"
#|/ip firewall mangle
/ip firewall mangle add chain=input in-interface=pppoe-out1 action=mark-connection new-connection-mark=ether1_conn
/ip firewall mangle add chain=input in-interface=pppoe-out2 action=mark-connection new-connection-mark=ether2_conn
/ip firewall mangle add chain=output connection-mark=ether1_conn action=mark-routing new-routing-mark=to_ether1
/ip firewall mangle add chain=output connection-mark=ether2_conn action=mark-routing new-routing-mark=to_ether2
/ip firewall mangle add chain=prerouting dst-address-type=!local in-interface=ether5 per-connection-classifier=both-addresses-and-ports:2/0 action=mark-connection new-connection-mark=ether1_conn passthrough=yes
/ip firewall mangle add chain=prerouting dst-address-type=!local in-interface=ether5 per-connection-classifier=both-addresses-and-ports:2/1 action=mark-connection new-connection-mark=ether2_conn passthrough=yes
/ip firewall mangle add chain=prerouting connection-mark=ether1_conn in-interface=ether5 action=mark-routing new-routing-mark=to_ether1
/ip firewall mangle add chain=prerouting connection-mark=ether2_conn in-interface=ether5 action=mark-routing new-routing-mark=to_ether2
#|/ip route
/ip route add dst-address=0.0.0.0/0 gateway=pppoe-out1 routing-mark=to_ether1 check-gateway=ping
/ip route add dst-address=0.0.0.0/0 gateway=pppoe-out2 routing-mark=to_ether2 check-gateway=ping
/ip route add dst-address=0.0.0.0/0 gateway=pppoe-out1 distance=1 check-gateway=ping
/ip route add dst-address=0.0.0.0/0 gateway=pppoe-out2 distance=2 check-gateway=ping
#|/ip firewall nat
/ip firewall nat add chain=srcnat out-interface=pppoe-out1 action=masquerade
/ip firewall nat add chain=srcnat out-interface=pppoe-out2 action=masquerade
#| DHCP server is on switch, with address pool 192.168.0.100-192.168.0.200
/ip pool add name=default-dhcp ranges=192.168.0.100-192.168.0.200
/ip dhcp-server add name=default address-pool=default-dhcp interface=ether5 disabled=no
/ip dhcp-server network add address=192.168.0.0/24 gateway=192.168.0.1 dns-server=192.168.0.1 comment="default configuration"
#| DNS
/ip dns set allow-remote-requests=yes
/ip dns static add name=router address=192.168.0.1
#| Now Configure DNS server so users can resolve hostnames,
#| Ex.cache-size=5000KiB
#| DNS Google = 8.8.8.8,8.8.4.4
#| DNS 3BB = 110.164.252.222,110.164.252.223
/ip dns set allow-remote-requests=yes cache-max-ttl=1w cache-size=5000K max-udp-packet-size=512 servers=8.8.8.8,8.8.4.4
- หลัง ผมแนะนำให้คัดลอกโค้ดเก็บไว้เป็น Word เพราะถ้าต้องการเปลี่ยน IP หรือเปลี่ยนค่าอื่นๆ เราสามารถใช้ฟังก์ชั่นค้นหาและแทนที่ ได้เลย
- คลิกขวา ที่แถบ command บน terminal แล้ว Paste
- รูปแสดงตัวอย่างการป้อนโค้ด
- หลังจากป้อนโค้ดเสร็จแล้วควรสั่ง Reboot ครั้งหนึ่ง ด้วยคำสั่งบน terminal ดังนี้ system reboot
- หลัง Mikrotik reboot เสร็จ ก็ connect เชื่อมต่อใหม่อีกครั้ง (เข้าPort1=WAN1,Port2=WAN2 ออกPort5=Loadbalance)
- การตั้งค่า LAN-HOTSPOT1 SETUP ( port4=Hotspot)
- เข้าเมนู IP > Hotspot
- แท็ป Server ทำการคลิก Hotspot Setup
แล้วเลือก HotSpot Interface: ether4
**ปกติแล้ว MikroTik จะดึงค่า DNS มาให้อัตโนมัติครับ (ตัวอย่างเป็น DNS ของ 3BB)
การตั้งค่า LoadBalance ให้ Hotspot - เข้าเมนู IP > Firewall
แท็ป Mangle Rule
คลิกสร้าง mangle ที่ปุ่ม " + " > (ให้ออก WAN1 ได้)
แท็ป General
Chain : prerouting
Src.Address : IP ของ hotspot (ตัวอย่าง 10.5.50.1)
In.Interface : Interface ของ hotspot (ตัวอย่างใช้ ether4)
แท็ป Advanced
Per Connection Classifier : both addresses and ports 2/0
(หมายเหตุ. ในตัวอย่างมีอยู่ 2 WAN จะใช้ 2/0 และ 2/1)
แท็ป Extra
Address Type เลือกเป็น local ติ๊กถูกที่ Invert
Hotsport เลือกเป็น auth
แท็ป Action
Action : mark connection
New Connection Mark : เลือก connection ของ wan1( ตัวอย่างใช้ ether1_conn) - คลิกสร้าง mangle ที่ปุ่ม " + " > (ให้ออก WAN2 ได้)
แท็ป General
Chain : prerouting
Src.Address : IP ของ hotspot (ตัวอย่าง 10.5.50.1)
In.Interface : Interface ของ hotspot (ตัวอย่างใช้ ether4)
แท็ป Advanced
Per Connection Classifier : both addresses and ports 2/1
(หมายเหตุ. ในตัวอย่างมีอยู่ 2 WAN จะใช้ 2/0 และ 2/1)
แท็ป Extra
Address Type เลือกเป็น local ติ๊กถูกที่ Invert
Hotsport เลือกเป็น auth
แท็ป Action
Action : mark connection
New Connection Mark : เลือก connection ของ wan2( ตัวอย่างใช้ ether2_conn)
แสดง mangle ที่สร้างเพิ่มขึ้นมาให้ Hotspot
หมายเหตุ: สามารถประยุกต์ใช้กับ 3-5 WAN to 1 LAN(Hotspot) ได้เลย
ตัวอย่าง 4 WAN จะใช้ Per Connection Classifier (4/0,4/1,4/2,4/3) แล้วก็เลือก connection (etherX_conn) เรียงลำดับกันไปให้ครบ
- เข้าเมนู IP > Hotspot
เพิ่มเติม สำหรับการสร้างหลายๆ Hotspot
สำหรับ admin ท่านใดต้องการใช้แต่ละ Link เกิดประโยชน์สูงสุด ไม่อยากให้เป็นแค่ link backup ก็สามารถสร้างแยกเป็น 1 Hotspot ต่อเน็ต 1 Link ได้
ซึ่งการสร้างหลายๆ hotspot ก็ยังคงสามารถใช้ user,pass ของ profiles และ dhcp เดียวกันได้อยู่
สามารถเลือก Address Pool(dhcp) และ Profile(user,pass) ของ Hotspot ตัวเดียวกัน ใช้งานพร้อมๆกันได้