Welcome to Sysnet Board คู่มือ การใช้งานอุปกรณ์ Network. Please log in or sign up.
สมาชิกทั้งหมด
17,591
กระทู้ทั้งหมด
10,018
หัวข้อทั้งหมด
4,705

  • Script Loadbalance 2 Wan แบบ PPPoE Client, DHCP Client และ Static IP
    เริ่มโดย yod
    Read 36,710 times
0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้
yod

 

 

Script Loadbalance 2 Wan แบบ PPPoE Client, DHCP Client และ Static IP


มีสมาชิกสอบถามกันเข้ามาพอสมควร ขอรวมในกระทู้เดียวกันเลยนะครับ

หัวข้อนี้สำหรับผู้ที่ Config อุปกรณ์ Mikrotik มาบ้างแล้ว จะไม่ขอลงรายละเอียดทุกๆขั้นตอน ลงเฉพาะขั้นตอนหลักๆเท่านั้นครับ

IP Address ฝั่งขา Lan ของเครื่องที่ทดสอบจะเป็น IP 192.168.2.1 นะครับ ถ้าต้องการเปลี่ยนให้ตรงกับตัวอย่าง ดูที่หัวข้อนี้ครับ การแก้ไข IP Address ของอุปกรณ์ Mikrotik RouterBoard https://www.sysnetcenter.com/board/index.php/topic,1398.0/


แบบที่ 1

Wan 1: Internet แบบ PPPoE Client (ตัวอย่างจะเป็น Internet แบบ ADSL ทำการ Config ADSL Modem เป็น Bridge Mode)
Wan 2: Internet แบบ DHCP Client (ตัวอย่างจะเป็น Internet แบบ Cable ทำการ Config Cable Modem เป็น Bridge Mode https://www.sysnetcenter.com/board/index.php?topic=3000.0)



Wan1 PPPoE Client




Wan2 DHCP Client ถ้า Cable Modem ทำการ Set เป็น Bridge แล้ว จะได้ IP จริงจากผู้ให้บริการ Internet




1. ถ้าเป็นเครื่องที่ทางร้าน Config ให้ ให้ลบ Port ether2 จากสมาชิกใน Bridge1 ได้เลยครับ




2. Copy Script จากด้านล่าง จะแบ่งเป็น 2 ส่วน คือไม่มีระบบ Hotspot กับ มีระบบ Hotspot

2.1. ไม่มีระบบ Hotspot

เปลี่ยน หมายเลข IP ตรง src-address ตามวง Network ของ Mikrotik ครับ


/ip firewall mangle

add action=accept chain=prerouting disabled=no in-interface=pppoe-out1
add action=accept chain=prerouting disabled=no in-interface=ether2

add action=mark-connection chain=prerouting disabled=no dst-address-type=!local new-connection-mark=wan1_conn passthrough=yes per-connection-classifier=both-addresses-and-ports:2/0 src-address=192.168.2.0/24
add action=mark-connection chain=prerouting disabled=no dst-address-type=!local new-connection-mark=wan2_conn passthrough=yes per-connection-classifier=both-addresses-and-ports:2/1 src-address=192.168.2.0/24

add action=mark-routing chain=prerouting connection-mark=wan1_conn disabled=no new-routing-mark=to_wan1 passthrough=yes src-address=192.168.2.0/24
add action=mark-routing chain=prerouting connection-mark=wan2_conn disabled=no new-routing-mark=to_wan2 passthrough=yes src-address=192.168.2.0/24

/ip firewall nat
add action=masquerade chain=srcnat disabled=no out-interface=pppoe-out1 src-address=192.168.2.0/24
add action=masquerade chain=srcnat disabled=no out-interface=ether2 src-address=192.168.2.0/24

/ip route
add check-gateway=ping disabled=no distance=1 dst-address=0.0.0.0/0 gateway=pppoe-out1 routing-mark=to_wan1 scope=30 target-scope=10
add check-gateway=ping disabled=no distance=1 dst-address=0.0.0.0/0 gateway=ether2 routing-mark=to_wan2 scope=30 target-scope=10
add check-gateway=ping disabled=no distance=1 dst-address=0.0.0.0/0 gateway=pppoe-out1 scope=30 target-scope=10
add check-gateway=ping disabled=no distance=1 dst-address=0.0.0.0/0 gateway=ether2 scope=30 target-scope=10



2.2 มีระบบ Hotspot

เปลี่ยน หมายเลข IP ตรง src-address ตามวง Network ของ Mikrotik ครับ
เวลาทดสอบ ต้อง Enable Hotspot Server ด้วยนะครับ

/ip firewall mangle

add action=accept chain=prerouting disabled=no in-interface=pppoe-out1
add action=accept chain=prerouting disabled=no in-interface=ether2

add action=mark-connection chain=prerouting disabled=no dst-address-type=!local hotspot=auth new-connection-mark=wan1_conn passthrough=yes per-connection-classifier=both-addresses-and-ports:2/0 src-address=192.168.2.0/24
add action=mark-connection chain=prerouting disabled=no dst-address-type=!local hotspot=auth new-connection-mark=wan2_conn passthrough=yes per-connection-classifier=both-addresses-and-ports:2/1 src-address=192.168.2.0/24

add action=mark-routing chain=prerouting connection-mark=wan1_conn disabled=no new-routing-mark=to_wan1 passthrough=yes src-address=192.168.2.0/24
add action=mark-routing chain=prerouting connection-mark=wan2_conn disabled=no new-routing-mark=to_wan2 passthrough=yes src-address=192.168.2.0/24

/ip firewall nat
add action=masquerade chain=srcnat disabled=no out-interface=pppoe-out1 src-address=192.168.2.0/24
add action=masquerade chain=srcnat disabled=no out-interface=ether2 src-address=192.168.2.0/24

/ip route
add check-gateway=ping disabled=no distance=1 dst-address=0.0.0.0/0 gateway=pppoe-out1 routing-mark=to_wan1 scope=30 target-scope=10
add check-gateway=ping disabled=no distance=1 dst-address=0.0.0.0/0 gateway=ether2 routing-mark=to_wan2 scope=30 target-scope=10

add check-gateway=ping disabled=no distance=1 dst-address=0.0.0.0/0 gateway=pppoe-out1 scope=30 target-scope=10
add check-gateway=ping disabled=no distance=1 dst-address=0.0.0.0/0 gateway=ether2 scope=30 target-scope=10



3. เมื่อ Run Script จากข้อ 2 จะได้ตามรูป




4. Test Speed ด้วย Web speedtest






แบบที่ 2




Wan 1: Static IP 192.168.0.2 (ether1)
Wan 2: Static IP 192.168.1.2 (ether2)

1. กำหนด IP Address ให้กับ ether1 เป็น 192.168.0.2 และ ether2 เป็น 192.168.1.2 ตามรูปครับ




2. กำหนด DNS ใส่ DNS ของ Google เข้าไป 8.8.8.8




3. Run Script

3.1 ไม่มีระบบ Hotspot
เปลี่ยน หมายเลข IP ตรง src-address ตามวง Network ของ Mikrotik

/ip firewall mangle
add chain=input in-interface=ether1 action=mark-connection new-connection-mark=WAN1_conn
add chain=input in-interface=ether2 action=mark-connection new-connection-mark=WAN2_conn

add chain=output connection-mark=WAN1_conn action=mark-routing new-routing-mark=to_WAN1
add chain=output connection-mark=WAN2_conn action=mark-routing new-routing-mark=to_WAN2

add chain=prerouting dst-address=192.168.0.0/24 action=accept in-interface=bridge1
add chain=prerouting dst-address=192.168.1.0/24 action=accept in-interface=bridge1

add chain=prerouting dst-address-type=!local in-interface=bridge1 per-connection-classifier=both-addresses-and-ports:2/0 action=mark-connection new-connection-mark=WAN1_conn passthrough=yes
add chain=prerouting dst-address-type=!local in-interface=bridge1 per-connection-classifier=both-addresses-and-ports:2/1 action=mark-connection new-connection-mark=WAN2_conn passthrough=yes

add chain=prerouting connection-mark=WAN1_conn in-interface=bridge1 action=mark-routing new-routing-mark=to_WAN1
add chain=prerouting connection-mark=WAN2_conn in-interface=bridge1 action=mark-routing new-routing-mark=to_WAN2

/ip route
add dst-address=0.0.0.0/0 gateway=192.168.0.1 routing-mark=to_WAN1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=192.168.1.1 routing-mark=to_WAN2 check-gateway=ping

add dst-address=0.0.0.0/0 gateway=192.168.0.1 distance=1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=192.168.1.1 distance=2 check-gateway=ping



3.2 มีระบบ Hotspot
เปลี่ยน หมายเลข IP ตรง src-address ตามวง Network ของ Mikrotik

/ip firewall mangle
add chain=input in-interface=ether1 action=mark-connection new-connection-mark=WAN1_conn
add chain=input in-interface=ether2 action=mark-connection new-connection-mark=WAN2_conn

add chain=output connection-mark=WAN1_conn action=mark-routing new-routing-mark=to_WAN1
add chain=output connection-mark=WAN2_conn action=mark-routing new-routing-mark=to_WAN2

add chain=prerouting dst-address=192.168.0.0/24 action=accept in-interface=bridge1
add chain=prerouting dst-address=192.168.1.0/24 action=accept in-interface=bridge1

add chain=prerouting dst-address-type=!local hotspot=auth in-interface=bridge1 per-connection-classifier=both-addresses-and-ports:2/0 action=mark-connection new-connection-mark=WAN1_conn passthrough=yes
add chain=prerouting dst-address-type=!local hotspot=auth in-interface=bridge1 per-connection-classifier=both-addresses-and-ports:2/1 action=mark-connection new-connection-mark=WAN2_conn passthrough=yes

add chain=prerouting connection-mark=WAN1_conn in-interface=bridge1 action=mark-routing new-routing-mark=to_WAN1
add chain=prerouting connection-mark=WAN2_conn in-interface=bridge1 action=mark-routing new-routing-mark=to_WAN2

/ip route
add dst-address=0.0.0.0/0 gateway=192.168.0.1 routing-mark=to_WAN1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=192.168.1.1 routing-mark=to_WAN2 check-gateway=ping

add dst-address=0.0.0.0/0 gateway=192.168.0.1 distance=1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=192.168.1.1 distance=2 check-gateway=ping



จะได้ Firewall - Mangle ตามรูป




4. ลองทดสอบ Test Speed จะต้องวิ่งทั้ง 2 เส้น






เรียบร้อยครับ ติดปัญหาอะไร โพสไว้ในหัวข้อนี้นะครับ  ;D ;D

ถ้าต้องการเป็น PPPoe 2 เส้นเลยนี่ใช้ Script นี้เลยได้ไหมครับ

ขอบคุณครับ

ต้องแก้ Script นิดหน่อยน่ะครับ




มีคำถามครับ

ตอนนี้ผมให้ Mikrotik เป็นตัวต่อ Internet 2 เส้น ซึ่งเน็ตก็ใช้ได้ทั้ง 2 เส้นล่ะครับ

แต่ว่ารวมเน็ตแล้วไม่ทราบว่า Script ไปผิดตรงไหนรึเปล่ามันออกเน็ตเส้นเดียวตลอดเลยครับ

อันนี้เป็นหน้า General กับ Dial Out ของ WAN 1,2  (ตอนนี้ผมเอาติ้กถูกหน้า Use Peer DNS กับ Add Default Route ออกหมดแล้ว)





จะเห็นว่าผม Disable WAN 2 เอาไว้เพราะถ้า Enable เน็ตมันจะไปออก WAN 2 อย่างเดียวซึ่งความเร็วช้ากว่า WAN1

WAN 1 : Down 15mb Up 1 mb
WAN 2 : Down 4mb Up 1mb (Fix IP)

ด้านล่างนี้เป็น Export Script ที่ใช้ครับ (ขออนุญาติเอา User กับ Pass ออก)

อ้างถึง/interface ethernet
set [ find default-name=ether1 ] comment="LAN Interface" name=LAN
set [ find default-name=ether2 ] comment="WAN Interface ISP1" name=WAN1
set [ find default-name=ether3 ] comment="WAN Interface ISP2" name=WAN2
set [ find default-name=ether4 ] comment="WAN Interface ISP3" name=WAN3
set [ find default-name=ether5 ] comment="WAN Interface ISP4" name=WAN4

/interface pppoe-client
add add-default-route=yes comment="WAN1 pppoe-out1 on ether2" disabled=no interface=WAN1 max-mru=1480 max-mtu=1480 name=pppoe-out1 password=XXXXXXX use-peer-dns=yes user=XXXXXXX@trueisp

add add-default-route=yes comment="WAN2 pppoe-out2 on ether3" interface=WAN2 max-mru=1480 max-mtu=1480 name=pppoe-out2 password=XXXXXXX use-peer-dns=yes user=XXXXXXX@truefxip

/ip neighbor discovery
set LAN comment="LAN Interface"
set WAN1 comment="WAN Interface ISP1"
set WAN2 comment="WAN Interface ISP2"
set WAN3 comment="WAN Interface ISP3"
set WAN4 comment="WAN Interface ISP4"
set pppoe-out1 comment="WAN1 pppoe-out1 on ether2"
set pppoe-out2 comment="WAN2 pppoe-out2 on ether3"

/ip dhcp-server
add disabled=no interface=LAN lease-time=3d name=dhcp1

/port
set 0 name=serial0

/ppp profile
set [ find name=default ] name=default
set [ find name=default-encryption ] name=default-encryption

/ip address
add address=192.168.0.6/24 interface=LAN network=192.168.0.0

/ip dhcp-server network
add address=192.168.0.0/24 dns-server=8.8.8.8,8.8.4.4 gateway=192.168.0.6 netmask=24 ntp-server=129.6.15.29,118.175.67.83

/ip dns
set servers=8.8.8.8,8.8.4.4

/ip firewall mangle
add action=mark-connection chain=prerouting connection-mark=no-mark in-interface=pppoe-out1 new-connection-mark=WAN1_conn

add action=mark-connection chain=prerouting connection-mark=no-mark in-interface=pppoe-out2 new-connection-mark=WAN2_conn

add action=mark-routing chain=output connection-mark=WAN1_conn new-routing-mark=to_WAN1

add action=mark-routing chain=output connection-mark=WAN2_conn new-routing-mark=to_WAN2

add chain=prerouting dst-address=192.168.0.0/24

add action=mark-connection chain=prerouting connection-mark=no-mark dst-address-type=!local new-connection-mark=WAN1_conn per-connection-classifier=both-addresses:2/0 src-address=192.168.0.0/24

add action=mark-connection chain=prerouting connection-mark=no-mark dst-address-type=!local new-connection-mark=WAN2_conn per-connection-classifier=both-addresses:2/1 src-address=192.168.0.0/24

add action=mark-routing chain=prerouting connection-mark=WAN1_conn new-routing-mark=to_WAN1 src-address=192.168.0.0/24

add action=mark-routing chain=prerouting connection-mark=WAN2_conn new-routing-mark=to_WAN2 src-address=192.168.0.0/24

/ip firewall nat
add action=masquerade chain=srcnat out-interface=pppoe-out1 src-address=192.168.0.0/24
add action=masquerade chain=srcnat out-interface=pppoe-out2 src-address=192.168.0.0/24

/ip route
add check-gateway=ping distance=1 gateway=pppoe-out1 routing-mark=to_WAN1
add check-gateway=ping distance=1 gateway=pppoe-out2 routing-mark=to_WAN2
add check-gateway=ping distance=1 gateway=pppoe-out1
add check-gateway=ping distance=2 gateway=pppoe-out2

/ip service
set telnet disabled=yes
set ftp disabled=yes
set www port=81
set ssh disabled=yes
set api disabled=yes

/system clock
set time-zone-autodetect=no time-zone-name=Asia/Bangkok

/system routerboard settings
set protected-routerboot=disabled

/tool romon port
add disabled=no   
รบกวนช่วยดูหน่อยนะครับ  :)

ของผม มี Internet แบบ ADSL 2 ตัว
Cable 1 ตัว
ถ้าต้องการจะรวมเน็ต 3 เส้น ต้อง แก้ที่สวนไหน บ้างหรอ ครับ ???

กรณีที่วางสคริปนี้แล้ว  

/ip firewall mangle
add chain=input in-interface=ether1 action=mark-connection new-connection-mark=WAN1_conn
add chain=input in-interface=ether2 action=mark-connection new-connection-mark=WAN2_conn

add chain=output connection-mark=WAN1_conn action=mark-routing new-routing-mark=to_WAN1
add chain=output connection-mark=WAN2_conn action=mark-routing new-routing-mark=to_WAN2

add chain=prerouting dst-address=192.168.0.0/24 action=accept in-interface=bridge1
add chain=prerouting dst-address=192.168.1.0/24 action=accept in-interface=bridge1

add chain=prerouting dst-address-type=!local hotspot=auth in-interface=bridge1 per-connection-classifier=both-addresses-and-ports:2/0 action=mark-connection new-connection-mark=WAN1_conn passthrough=yes
add chain=prerouting dst-address-type=!local hotspot=auth in-interface=bridge1 per-connection-classifier=both-addresses-and-ports:2/1 action=mark-connection new-connection-mark=WAN2_conn passthrough=yes

add chain=prerouting connection-mark=WAN1_conn in-interface=bridge1 action=mark-routing new-routing-mark=to_WAN1
add chain=prerouting connection-mark=WAN2_conn in-interface=bridge1 action=mark-routing new-routing-mark=to_WAN2

/ip route
add dst-address=0.0.0.0/0 gateway=192.168.0.1 routing-mark=to_WAN1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=192.168.1.1 routing-mark=to_WAN2 check-gateway=ping

add dst-address=0.0.0.0/0 gateway=192.168.0.1 distance=1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=192.168.1.1 distance=2 check-gateway=ping


ต้องกำหนด NAT เพิ่ม เพื่อให้ออกเนตที่  ether3 (192.168.88.1) ด้วยหรือไม่ครับ


ผมใช้ script นี้ครับแต่ถ้าเน็ตไม่เท่ากันต้องแก้ไขตรงไหนครับ  และตอนนี้มีปัญหาเข้าบางเว็บช้ามากครับ