YOU ARE DOWNLOADING DOCUMENT

Please tick the box to continue:

Transcript
Page 1: คู่มือ ADSL DHCP + Multiwan Loadbalance บน CentOS 5 up

Multiwan Loadbalance

ON

CentOS 5 up

เลือกการ์ดแลนที่เราต้องการใช้งานเป็น Mutiwan LoadBalance

ในตัวอย่าง จาก Server ของผม

eth0 ------| รับเน็ตมาจาก ADSL Router WAN 1 = 192.168.1.100 : Gateway = 192.168.1.1

||------- > Multiwan Loadbalance

eth1 ------| รับเน็ตมาจาก ADSL Router WAN 2 = 192.168.2.100 : Gateway = 192.168.2.1

eth2 ----- Chillispot : TUN0 : IP Gateway = 10.0.0.1

eth3 ----- DHCP Server : IP Gateway = 192.168.100.1

~~~~~~~~~~~~~~~~~~~~~~~~~~~

ใน Multiwan ช่วงนี้ ผมขอใช้เป็น DHCP Gateway จากตัว router ก่อน

เพราะผมอาศับพักอยู่ในหอแบบ น.ศ ทั่วไป จึงไม่สามารถท่ีท าเป็น PPPoE ให้เป็นตัวอย่างได้

เพราะ router เป็นของหอ เจ้าของหอพักเค้าคงไม่ให้ท า

ผมจึงใช้ คอมอีกเครื่องหน่ึงมารับเน็ต แล้วปล่อยไอพีเป็น 192.168.2.1 ให้แทน ..เพื่อที่จะท า Multiwan

จะพยายามหา Router จากเพื่อนๆ ที่รับเน็ตรายเดือนมาโดยตรง มาท า PPPoE ให้อีกครับ

Page 2: คู่มือ ADSL DHCP + Multiwan Loadbalance บน CentOS 5 up

# cd /tmp/temp/

# yum -y install perl-Crypt-SSLeay

จากน้ันท าการ Download ทั้ง 3 ไฟล์ มาเก็บไว้ใน /tmp/temp

http://www.mediafire.com/?jt9cht99ju5ypa3

http://www.mediafire.com/?ogsry32fb74cvje

http://www.mediafire.com/?4d6wfxg47ea6snt

# rpm -Uvh cc-firewall-4.2-50.i386.rpm

Preparing... ########################################### [100%]

1:cc-firewall ########################################### [100%]

# rpm -Uvh cc-syswatch-4.2-10.i386.rpm

Preparing... ########################################### [100%]

1:cc-syswatch ########################################### [100%]

# rpm -Uvh firewall-1.3.5-1.i386.rpm

Preparing... #################################### [100%]

1:firewall ##################################### [100%]

# cd /sbin/

# ln -sf iptables iptables-bin

# ls -l iptables-bin lrwxrwxrwx 1 root root 8 Jun 20 18:40 iptables-bin -> iptables

# cd /etc/iproute2/

# ln -sf rt_dsfield rt_dsfield.rt_config

# ln -sf rt_protos rt_protos.rt_config

# ln -sf rt_realms rt_realms.rt_config

# ln -sf rt_scopes rt_scopes.rt_config

# ln -sf rt_tables rt_tables.rt_config

Page 3: คู่มือ ADSL DHCP + Multiwan Loadbalance บน CentOS 5 up

# ls -l

# nano +12 /etc/firewall แก้เป็น

# Firewall mode

#-------------- # Possible configurations:

# gateway trustedgateway standalone trustedstandalone dmz

MODE="gateway"

# nano +18 /etc/firewall เดิม

# Interface roles

#----------------

EXTIF="eth0"

LANIF=""

DMZIF="" WIFIF=""

HOTIF=""

แก้เป็น eth0 = WAN1 และ eth1 = WAN2 ส่วน eth2 = LAN

EXTIF="eth0 eth1"

LANIF="eth2" DMZIF=""

WIFIF=""

HOTIF=""

Page 4: คู่มือ ADSL DHCP + Multiwan Loadbalance บน CentOS 5 up

# nano +27 /etc/firewall เดิม

# Bandwidth management (QoS)

#---------------------------

BANDWIDTH_QOS="on"

BANDWIDTH_UPSTREAM=1000000 BANDWIDTH_DOWNSTREAM=1000000

แก้เป็น

# Bandwidth management (QoS)

#---------------------------

BANDWIDTH_QOS="off"

BANDWIDTH_UPSTREAM=1000000 BANDWIDTH_DOWNSTREAM=1000000

# nano +38 /etc/firewall เดิม

# Multipath

#----------

MULTIPATH="off"

MULTIPATH_WEIGHTS=""

แก้เป็น

# Multipath

#----------

MULTIPATH="on"

MULTIPATH_WEIGHTS="eth1|1 eth0|1" <-- ส ำหรับ LoadBalance เส้น-ต่อ-เส้น

Page 5: คู่มือ ADSL DHCP + Multiwan Loadbalance บน CentOS 5 up

# nano +44 /etc/firewall เดิม

# Squid configuration

#--------------------

SQUID_TRANSPARENT="off"

SQUID_FILTER_PORT=""

*~ในขั้นตอนน้ีเฉพาะท่านท่ีได้ติดตั้ง squid proxy แบบ transparent ผ่านแล้ว

แก้เป็น

# Squid configuration

#--------------------

SQUID_TRANSPARENT="on"

SQUID_FILTER_PORT=""

Page 6: คู่มือ ADSL DHCP + Multiwan Loadbalance บน CentOS 5 up

# nano +85 /etc/firewall

เดิม

# NOTE: If editing these by hand, do not add spaces between fields.

RULES="\

webservice||0x10000001|6||1875| \

"

# vim: ts=4 syntax=sh

ในขั้นตอนน้ีเป็นการ Incomming เปิด port ให้ remote จากข้างนอกเข้ามา หรือ ทาง WAN นั้นเอง

แก้เป็น

# NOTE: If editing these by hand, do not add spaces between fields.

RULES="\

HTTP||0x10000001|6|192.168.1.100|80| \ <-เป็นการระบุไอพีเฉพาะท่ีจะ remote เข้ามาทาง eth0

HTTP||0x10000001|6|192.168.2.100|80| \ <-เป็นการระบุไอพีเฉพาะท่ีจะ remote เข้ามาทาง eth1

HTTPS||0x10000001|6|192.168.1.100|443| \

HTTPS||0x10000001|6|192.168.2.100|443| \

SSH||0x10000001|6||22| \ <-เป็นการไม่ระบุไอพีท่ีจะ remote เข้า ระบบจะเข้าใจว่าเอาท้ัง 2 ไอพี auto

Webmin||0x10000001|6||10000| \

"

# vim: ts=4 syntax=sh

Page 7: คู่มือ ADSL DHCP + Multiwan Loadbalance บน CentOS 5 up

# nano +8 /etc/syswatch

เดิม

# Connection type

# - values: dhcp, static, or pppoe

conntype=pppoe

แก้เป็น

# Connection type

# - values: dhcp, static, or pppoe

conntype= static

# nano +14 /etc/syswatch

แก้เป็น

# Server type

# - values: gateway, onlan

servtype=gateway

# nano +49 /etc/syswatch

เดิม

firewall="/etc/rc.d/init.d/firewall restart >/dev/null"

ในขั้นตอนน้ีถ้าไม่แก้ เวลาระบบ restart ทุกครั้ง ไฟล์จะว่างเปล่าตลอด จะท าให้ iptable ของ firewall

ต้อง add ใหม่ทุกครั้ง ( ซึ่งไม่ดีแน่ )

แก้เป็น

firewall="/etc/rc.d/init.d/firewall restart"

Page 8: คู่มือ ADSL DHCP + Multiwan Loadbalance บน CentOS 5 up

# nano +57 /etc/syswatch

เดิม

# Ping servers

# - The syswatch daemon by default will just ping the next hop on the Internet

# and another device. You can override this with a comma separated list of

# 2 servers.

ping_servers=203.146.237.222,203.144.144.163

ขั้นตอนน้ีให้แก้เป็น IP Gateway ของ ADSL Router ของแต่ละท่าน

แก้เป็น

ping_servers=192.168.1.1,192.168.2.1

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ขั้นตอนต่อไป เป็นการขั้นการ config ไฟล์ resolv.conf และ chilli.conf และ rc.local

# nano /etc/resolv.conf

เดิม

nameserver 192.168.1.1

search localhost

แก้เป็น Gateway ของแต่ละ WAN คือ

WAN1 = 192.168.1.1 และ WAN2 = 192.168.2.1

แก้เป็น

nameserver 192.168.1.1

nameserver 192.168.2.1

Page 9: คู่มือ ADSL DHCP + Multiwan Loadbalance บน CentOS 5 up

# nano +59 /etc/chilli.conf

เดิม

# TAG: dns1

# Primary DNS server.

# Will be suggested to the client.

# If omitted the system default will be used.

# Normally you do not need to uncomment this tag.

dns1 192.168.1.100

# TAG: dns2

# Secondary DNS server.

# Will be suggested to the client.

# If omitted the system default will be used.

# Normally you do not need to uncomment this tag.

dns2 192.168.1.1

ท าการใส่เคร่ืองหมาย # เพื่อให้ระบบมองเป็น comment

เพราะในส่วนน้ีระบบจะให้ Chillispot ไประบบ DNS จากไฟล์ /etc/resolv.conf เอง

แก้เป็น

# TAG: dns1

# Primary DNS server.

# Will be suggested to the client.

# If omitted the system default will be used.

# Normally you do not need to uncomment this tag.

#dns1 192.168.1.254

# TAG: dns2

# Secondary DNS server.

# Will be suggested to the client.

# If omitted the system default will be used.

# Normally you do not need to uncomment this tag.

#dns2 192.168.1.1

Page 10: คู่มือ ADSL DHCP + Multiwan Loadbalance บน CentOS 5 up

ขั้นตอนต่อไปนี้ เป็นขั้นตอนที่ IPTABLES จะต้องน ามาใส่ในไฟล์นี้เท่านั้น เพราะต าแหน่งไฟล์เปลี่ยนไปแล้ว

Firewall ของ CentOS ตอนนี้จะเป็นเหมือนของ ClearOS แทน

เพราะ CentOS กับ ClearOS ก็อันเดียวกัน ..คลอดออกมาท้องเดียวกัน แต่ ClearOS ถูกออกแบบให้ใช้

firewall ส าหรับ Multiwan ตั้งแต่ตอนติดตั้ง และถูกออกแบบ WEB UI แทน

# nano /etc/rc.d/rc.firewall.local

เดิม ( ไม่มีอะไร มีแต่ comment ให้น า service tables มาใส่ )

# Custom firewall rules.

# This file is executed by the firewall on stop/start/restart.

เราก็ไปน าส่วนของ IPTABLES อันเก่า จากไฟล์ /etc/firewall.iptables มาใส่แทน เฉพาะส่วนที่ต้องใช้งาน

ใส่เป็น

#Enable NAT on output device

$IPTABLES -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE

## Squid Proxy Allow transparent proxy

$IPTABLES -A INPUT -p tcp -m tcp --dport 3128 --syn -j ACCEPT

#

# Squid Proxy Allow transparent proxy for Tun0

$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp --dport 3128 --syn -j DROP

$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 10.0.0.0/24 --dport 80 -j RETURN

$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 10.0.0.0/16 --dport 80 -j RETURN

$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 10.0.0.0/8 --dport 80 -j RETURN

$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 127.0.0.0/8 --dport 80 -j RETURN

$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128

แก้เป็น eth ตามการ์ดเลย #Enable NAT on output device

$IPTABLES -t nat -A POSTROUTING -o eth0 -j MASQUERADE <-- ก็ไม่มีไรมาก แก้แค่ 2 ไฟล์น้ีเท่าน้ัน

เพราะ WAN มี 2 ตัว จึงต้องมี nat 2 ตัว

$IPTABLES -t nat -A POSTROUTING -o eth1 -j MASQUERADE จาก $EXTIF มาเป็น eth แทน

## Squid Proxy Allow transparent proxy

$IPTABLES -A INPUT -p tcp -m tcp --dport 3128 --syn -j ACCEPT

## Squid Proxy Allow transparent proxy for Tun0 -> eth2

$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp --dport 3128 --syn -j DROP

$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 10.0.0.0/24 --dport 80 -j RETURN

$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 10.0.0.0/16 --dport 80 -j RETURN

$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 10.0.0.0/8 --dport 80 -j RETURN

$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 127.0.0.0/8 --dport 80 -j RETURN

$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128

Page 11: คู่มือ ADSL DHCP + Multiwan Loadbalance บน CentOS 5 up

# nano /etc/rc.local

เดิม

sh /etc/firewall.iptables

แก้เป็นการส่ัง start firewall ส าหรับการ Multiwan อย่างเดียว ( อันเดิมปล่อยทิ้งไว้เลย )

แก้เป็น

sh /etc/firewall

ต่อไปเป็นการ Restart Service ระบบ ท่ีได้ท าการแก้ไขให้เร่ิมต้นใหม่หมด

# shutdown -r now

คร้ังเดียวจบไม่เสียเวลา ตาม reset service

หมายเหตุ

ในข้ันตอนการน า IPTABLES มาใส่ หรือ เพิ่มเติม คร้ังต่อไป

ให้น าไปใส่ใน path /etc/rc.d/rc.firewall.local ทุกคร้ัง

แล้วสั่ง Restart service firewall ใหม่ทุกคร้ังท่ีเปลี่ยนแปลง

# /etc/init.d/firewall restart

*ในข้ันตอนการท าเป็น PPPoE ก็ท าเหมือนกันทุกอย่าง เปล่ียนแค่ช่วง /etc/firewall

ที่ใช้ eth0 eth1 มาเป็น ppp0 ppp1 แทน

และไประบุ DNS ในไฟล์ /etc/resolv.conf อีกที

Page 12: คู่มือ ADSL DHCP + Multiwan Loadbalance บน CentOS 5 up

Multiwan Loadbalance + บน CentOS

ช่วง tcpdump ดูไฟล์ ห้ามมีเครื่องใช้งานร่วมทาง WAN1 ,WAN2 เด็ดขาด

เพราะระบบ จะไป dump ไฟล์ ที่ว่ิงร่วมเส้นเดียวกัน ให้มีแต่ server ของท่านเครื่องเดียวเพื่อทดสอบก่อน

# tcpdump -i eth0

# tcpdump -i eth1

หรือ ตัวสอบแบบชัดเจนที่สุด

ให้ท่านลองถอดสาย WAN เส้นใดเส้นหนึ่ง ออก

แล้วลองใฟ้เครื่องเล่นเน็ตตามปกติดู ช่วงแรกๆ เน็ตจะ delay นิดหน่ึง

ท่านก็เปล่ียน URL ไปเป็น www.google.com หรือเว็บอ่ืนๆดู

รับรองเห็นได้ชัดว่า Multiwan ท างานแทนกัน เส้นใดเส้นหนึ่ง


Related Documents