Dual-WAN for simple round-robin load equalization

From DD-WRT Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 01:02, 17 October 2006 (edit)
1161046096 (Talk | contribs)

← Previous diff
Revision as of 14:21, 17 October 2006 (edit) (undo)
AycheKay (Talk | contribs)
(Deleted Ukranian Spam, Sick!)
Next diff →
Line 167: Line 167:
[[Category:English documentation]] [[Category:English documentation]]
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
-<div style="display:none"> 
-[l_sp_9] 
-[http://top20man.in.ua/tankless.htm Tankless] 
-[http://top20man.in.ua/heater-water.htm Heater Water] 
-[http://top20man.in.ua/heater-tankless-water.htm Heater Tankless Water] 
-[http://top20man.in.ua/heater-hot-water.htm Heater Hot Water] 
-[http://top20man.in.ua/heater-hot-tankless-water.htm Heater Hot Tankless Water] 
-[http://top20man.in.ua/electric-heater-tankless-water.htm Electric Heater Tankless Water] 
-[http://top20man.in.ua/electric-heater-water.htm Electric Heater Water] 
-[http://top20man.in.ua/heater-solar-water.htm Heater Solar Water] 
-[http://top20man.in.ua/gas-heater-water.htm Gas Heater Water] 
-[http://top20man.in.ua/gas-heater-hot-water.htm Gas Heater Hot Water] 
-[http://top20man.in.ua/bosch-heater-tankless-water.htm Bosch Heater Tankless Water] 
-[http://top20man.in.ua/heater-rheem-water.htm Heater Rheem Water] 
-[http://top20man.in.ua/electric-heater-hot-water.htm Electric Heater Hot Water] 
-[http://top20man.in.ua/bed-heater-water.htm Bed Heater Water] 
-[http://top20man.in.ua/heater-rinnai-tankless-water.htm Heater Rinnai Tankless Water] 
-[http://top20man.in.ua/gas-heater-tankless-water.htm Gas Heater Tankless Water] 
-[http://top20man.in.ua/demand-heater-water.htm Demand Heater Water] 
-[http://top20man.in.ua/heater-richmond-water.htm Heater Richmond Water] 
-[http://top20man.in.ua/heater-services-water.htm Heater Services Water] 
-[http://top20man.in.ua/heater-state-water.htm Heater State Water] 
-[http://top20man.in.ua/heater-rinnai-water.htm Heater Rinnai Water]  
-[http://top20man.in.ua/bosch-heater-water.htm Bosch Heater Water]  
-[http://top20man.in.ua/ao-heater-smith-water.htm Ao Heater Smith Water]  
-[http://top20man.in.ua/heater-water-whirlpool.htm Heater Water Whirlpool] 
-[http://top20man.in.ua/bradford-heater-water-white.htm Bradford Heater Water White] 
-[http://top20man.in.ua/heater-repair-water.htm Heater Repair Water] 
-[http://top20man.in.ua/electric-heater-hot-tankless-water.htm Electric Heater Hot Tankless Water] 
-[http://top20man.in.ua/gas-heater-hot-tankless-water.htm Gas Heater Hot Tankless Water] 
-[http://top20man.in.ua/dealer-heater-water.htm Dealer Heater Water] 
-[http://top20man.in.ua/40-electric-gal-heater-water.htm 40 Electric Gal Heater Water] 
-[http://top20man.in.ua/heater-hot-instant-water.htm Heater Hot Instant Water] 
-[http://top20man.in.ua/american-heater-water.htm American Heater Water] 
-[http://top20man.in.ua/heater-o-smith-water.htm Heater O Smith Water] 
-[http://top20man.in.ua/ge-heater-water.htm Ge Heater Water] 
-[http://top20man.in.ua/heater-hot-solar-water.htm Heater Hot Solar Water] 
-[http://top20man.in.ua/demand-heater-hot-water.htm Demand Heater Hot Water] 
-[http://top20man.in.ua/heater-rv-water.htm Heater Rv Water] 
-[http://top20man.in.ua/heater-paloma-tankless-water.htm Heater Paloma Tankless Water] 
-[http://top20man.in.ua/heater-instant-water.htm Heater Instant Water] 
-[http://top20man.in.ua/heater-paloma-water.htm Heater Paloma Water] 
-[http://top20man.in.ua/heater-propane-water.htm Heater Propane Water] 
-[http://top20man.in.ua/atwood-heater-water.htm Atwood Heater Water] 
-[http://top20man.in.ua/heater-noritz-water.htm Heater Noritz Water] 
-[http://top20man.in.ua/heater-hot-rheem-water.htm Heater Hot Rheem Water] 
-[http://top20man.in.ua/commercial-heater-water.htm Commercial Heater Water] 
-[http://top20man.in.ua/heater-rheem-tankless-water.htm Heater Rheem Tankless Water] 
-[http://top20man.in.ua/heater-noritz-tankless-water.htm Heater Noritz Tankless Water] 
-[http://top20man.in.ua/heater-marathon-water.htm Heater Marathon Water] 
-[http://top20man.in.ua/gas-heater-natural-water.htm Gas Heater Natural Water] 
-[http://top20man.in.ua/heater-review-tankless-water.htm Heater Review Tankless Water] 
-[http://top20man.in.ua/heater-polaris-water.htm Heater Polaris Water] 
-[http://top20man.in.ua/heater-installation-water.htm Heater Installation Water] 
-[http://top20man.in.ua/heater-indirect-water.htm Heater Indirect Water] 
-[http://top20man.in.ua/heater-hot-price-water.htm Heater Hot Price Water] 
-[http://top20man.in.ua/heater-reliance-water.htm Heater Reliance Water] 
-[http://top20man.in.ua/heat-heater-pump-water.htm Heat Heater Pump Water] 
-[http://top20man.in.ua/demand-electric-heater-water.htm Demand Electric Heater Water] 
-[http://top20man.in.ua/heater-part-water.htm Heater Part Water] 
-[http://top20man.in.ua/heater-hot-rinnai-water.htm Heater Hot Rinnai Water] 
-[http://top20man.in.ua/a-o-heater-smith-water.htm A O Heater Smith Water] 
-[http://top20man.in.ua/heater-tankless-titan-water.htm Heater Tankless Titan Water] 
-[http://top20man.in.ua/heater-lochinvar-water.htm Heater Lochinvar Water] 
-[http://top20man.in.ua/heater-suburban-water.htm Heater Suburban Water] 
-[http://top20man.in.ua/heater-problem-water.htm Heater Problem Water] 
-[http://top20man.in.ua/heater-hot-rv-water.htm Heater Hot Rv Water] 
-[http://top20man.in.ua/gas-heater-natural-tankless-water.htm Gas Heater Natural Tankless Water] 
-[http://top20man.in.ua/heater-renco-tankless-water.htm Heater Renco Tankless Water] 
-[http://top20man.in.ua/heater-takagi-tankless-water.htm Heater Takagi Tankless Water] 
-[http://top20man.in.ua/heater-hot-repair-water.htm Heater Hot Repair Water] 
-[http://top20man.in.ua/heater-hot-rinnai-tankless-water.htm Heater Hot Rinnai Tankless Water] 
-[http://top20man.in.ua/heater-timer-water.htm Heater Timer Water] 
-[http://top20man.in.ua/heater-hot-water-whirlpool.htm Heater Hot Water Whirlpool] 
-[http://top20man.in.ua/heater-point-use-water.htm Heater Point Use Water] 
-[http://top20man.in.ua/bosch-electric-heater-tankless-water.htm Bosch Electric Heater Tankless Water] 
-[http://top20man.in.ua/heater-titan-water.htm Heater Titan Water] 
-[http://top20man.in.ua/electric-heater-powerstar-tankless-water.htm Electric Heater Powerstar Tankless Water] 
-[http://top20man.in.ua/bradford-heater-hot-water-white.htm Bradford Heater Hot Water White] 
-[http://top20man.in.ua/heater-select-state-water.htm Heater Select State Water] 
-[http://top20man.in.ua/heater-ruud-water.htm Heater Ruud Water] 
-[http://top20man.in.ua/heater-sears-water.htm Heater Sears Water] 
-[http://top20man.in.ua/heater-takagi-water.htm Heater Takagi Water] 
-[http://top20man.in.ua/ariston-heater-water.htm Ariston Heater Water] 
-[http://top20man.in.ua/bosch-heater-hot-tankless-water.htm Bosch Heater Hot Tankless Water] 
-[http://top20man.in.ua/heater-instantaneous-water.htm Heater Instantaneous Water] 
-[http://top20man.in.ua/heater-price-water.htm Heater Price Water] 
-[http://top20man.in.ua/heater-power-vent-water.htm Heater Power Vent Water] 
-[http://top20man.in.ua/heater-install-water.htm Heater Install Water] 
-[http://top20man.in.ua/bosch-gas-heater-tankless-water.htm Bosch Gas Heater Tankless Water] 
-[http://top20man.in.ua/heater-portable-water.htm Heater Portable Water] 
-[http://top20man.in.ua/heater-home-mobile-water.htm Heater Home Mobile Water] 
-[http://top20man.in.ua/build-heater-solar-water.htm Build Heater Solar Water] 
-[http://top20man.in.ua/fired-heater-water-wood.htm Fired Heater Water Wood] 
-[http://top20man.in.ua/drain-heater-water.htm Drain Heater Water] 
-[http://top20man.in.ua/heater-renai-tankless-water.htm Heater Renai Tankless Water] 
-[http://top20man.in.ua/heater-hot-problem-water.htm Heater Hot Problem Water] 
-[http://top20man.in.ua/heater-propane-tankless-water.htm Heater Propane Tankless Water] 
-[http://top20man.in.ua/baseboard-heater-hot-water.htm Baseboard Heater Hot Water] 
-[http://top20man.in.ua/heater-maintenance-water.htm Heater Maintenance Water] 
-[http://top20man.in.ua/heater-review-water.htm Heater Review Water] 
-[http://top20man.in.ua/gas-heater-rheem-water.htm Gas Heater Rheem Water] 
-[http://top20man.in.ua/bosch-heater-hot-water.htm Bosch Heater Hot Water] 
-</div> 

Revision as of 14:21, 17 October 2006

(copied from forum-posting by user aldoir Dual-WAN forum posting

You'll need to create a new VLAN, called vlan2.

Enter in the web interface, Settings/VLANs. Set Port 4 to a new VLAN.

Enter in the console, and do the following commands

commands to set VLANs

nvram set vlan0ports="1 2 3 5*"
nvram set vlan2ports="4 5"
nvram set vlan2hwname=et0
nvram commit

Here are the scripts I used to startup the interface. You need to call them in rc_firewall

wan2.firewall

//edit - dont like this bit, it doesnt seem to be for DHCP connection and looks like its for a static IP connection

#!/bin/sh
WAN2_IFNAME=vlan2
WAN2_IPADDR=10.0.0.2
WAN2_GATEWAY=10.0.0.1
WAN2_NETMASK=255.0.0.0
if [ "$(nvram get wan2_ipaddr)" != "$WAN2_IPADDR" ]; then
        nvram set wan2_ifname=$WAN2_IFNAME   
   nvram set wan2_ipaddr=$WAN2_IPADDR
   nvram set wan2_gateway=$WAN2_GATEWAY
   nvram set wan2_netmask=$WAN2_NETMASK
   nvram commit
fi
ifconfig $(nvram get wan2_ifname) up $(nvram get wan2_ipaddr) netmask $(nvram get wan2_netmask)

routes.firewall

#!/bin/sh
ip rule flush
ip rule add lookup main prio 32766
ip rule add lookup default prio 32767
ip rule add from $(nvram get wan_ipaddr) table 100 prio 100
ip rule add fwmark 0x100 table 100 prio 101
ip rule add from $(nvram get wan2_ipaddr) table 200 prio 200
ip rule add fwmark 0x200 table 200 prio 201
ip route flush table 100
ip route flush table 200
for TABLE in 100 200
do
   ip route | grep link | while read ROUTE
   do
      ip route add table $TABLE to $ROUTE
   done
done
ip route add table 100 default via $(nvram get wan_gateway)
ip route add table 200 default via $(nvram get wan2_gateway)

firewall.firewall

#!/bin/sh
#DD-WRT firewall rules
#BEGIN
#apply simple forward rules
for RULE in $(nvram get forward_spec)
do
   FROM=`echo $RULE | cut -d '>' -f 1`
   TO=`echo $RULE | cut -d '>' -f 2`
   STATE=`echo $FROM | cut -d ':' -f 2`
   PROTO=`echo $FROM | cut -d ':' -f 3`
   SPORT=`echo $FROM | cut -d ':' -f 4`
   DEST=`echo $TO | cut -d ':' -f 1`
   DPORT=`echo $TO | cut -d ':' -f 2`
   if [ "$STATE" = "on" ]; then
      if [ "$PROTO" = "both" ]; then
         #udp
         #iptables -A FORWARD -d $(nvram get wan2_ipaddr) -p udp --dport $SPORT -j ACCEPT
         iptables -A PREROUTING -t nat -p udp -d $(nvram get wan2_ipaddr) --dport $SPORT -j DNAT --to $DEST:$DPORT
         #tcp
         #iptables -A FORWARD -d $(nvram get wan2_ipaddr) -p tcp --dport $SPORT -j ACCEPT
         iptables -A PREROUTING -t nat -p tcp -d $(nvram get wan2_ipaddr) --dport $SPORT -j DNAT --to $DEST:$DPORT
      else
         #iptables -A FORWARD -d $(nvram get wan2_ipaddr) -p $PROTO --dport $SPORT -j ACCEPT
         iptables -A PREROUTING -t nat -p $PROTO -d $(nvram get wan2_ipaddr) --dport $SPORT -j DNAT --to $DEST:$DPORT
      fi
   fi
done
#apply range forward rules
for RULE in $(nvram get forward_port)
do
   FROM=`echo $RULE | cut -d '>' -f 1`
   TO=`echo $RULE | cut -d '>' -f 2`
   STATE=`echo $FROM | cut -d ':' -f 2`
   PROTO=`echo $FROM | cut -d ':' -f 3`
   SPORT=`echo $FROM | cut -d ':' -f 4`
   EPORT=`echo $FROM | cut -d ':' -f 5`

   if [ "$STATE" = "on" ]; then
      if [ "$PROTO" = "both" ]; then
         #udp
         #iptables -A FORWARD -d $(nvram get wan2_ipaddr) -p udp --dport $SPORT:$EPORT -j ACCEPT
         iptables -A PREROUTING -t nat -p udp -d $(nvram get wan2_ipaddr) --dport $SPORT:$EPORT -j DNAT --to $TO
         #tcp
         #iptables -A FORWARD -d $(nvram get wan2_ipaddr) -p tcp --dport $SPORT:$EPORT -j ACCEPT
         iptables -A PREROUTING -t nat -p tcp -d $(nvram get wan2_ipaddr) --dport $SPORT:$EPORT -j DNAT --to $TO
      else
         #iptables -A FORWARD -d $(nvram get wan2_ipaddr) -p $PROTO --dport $SPORT:$EPORT -j ACCEPT
         iptables -A PREROUTING -t nat -p $PROTO -d $(nvram get wan2_ipaddr) --dport $SPORT:$EPORT -j DNAT --to $TO
      fi
   fi
done
iptables -A PREROUTING -t nat -p icmp -d $(nvram get wan2_ipaddr) -j DNAT --to $(nvram get lan_ipaddr)
if [ $(nvram get remote_management) -eq 1 ]; then
      iptables -A PREROUTING -t nat -p tcp -d $(nvram get wan2_ipaddr) \
            --dport $(nvram get http_wanport) -j DNAT --to $(nvram get lan_ipaddr):$(nvram get http_lanport)
fi
if [ $(nvram get dmz_enable) -eq 1 ]; then
      DMZ_IP=$(nvram get lan_ipaddr | sed -r 's/[0-9]+$//')$(nvram get dmz_ipaddr)
      iptables -A PREROUTING -t nat -d $(nvram get wan2_ipaddr) -j DNAT --to $DMZ_IP
fi
iptables -A PREROUTING -t nat --dest $(nvram get wan2_ipaddr) -j TRIGGER --trigger-type dnat
iptables -A FORWARD -i $(nvram get wan2_ifname) -o $(nvram get lan_ifname) -j TRIGGER --trigger-type in
iptables -A PREROUTING -t mangle -i $(nvram get wan2_ifname) -j IMQ --todev 0
iptables -A PREROUTING -t mangle -i $(nvram get wan2_ifname) -j SVQOS_IN
iptables -A POSTROUTING -t mangle -o $(nvram get wan2_ifname) -j SVQOS_OUT
#DD-WRT END
#Save the gateway in the connection mark for new incoming connections
iptables -t mangle -A PREROUTING -i $(nvram get wan_ifname) -m conntrack --ctstate NEW -j CONNMARK --set-mark 0x100
iptables -t mangle -A PREROUTING -i $(nvram get wan2_ifname) -m conntrack --ctstate NEW -j CONNMARK --set-mark 0x200
# Save the gateway in the connection mark for new outgoing connections
iptables -t mangle -A POSTROUTING -o $(nvram get wan_ifname) -m conntrack --ctstate NEW -j CONNMARK --set-mark 0x100
iptables -t mangle -A POSTROUTING -o $(nvram get wan2_ifname) -m conntrack --ctstate NEW -j CONNMARK --set-mark 0x200
# Use the correct gateway for reply packets from the LAN
iptables -t mangle -A PREROUTING -i $(nvram get lan_ifname) -m conntrack --ctstate ESTABLISHED,RELATED -j CONNMARK  --restore-mark
# Use the correct gateway for reply packets from local connections
iptables -t mangle -A OUTPUT -m conntrack --ctstate ESTABLISHED,RELATED -j CONNMARK --restore-mark
#mask known packets to its source address
iptables -A POSTROUTING -t nat -m mark --mark 0x100 -j SNAT --to-source $(nvram get wan_ipaddr)
iptables -A POSTROUTING -t nat -m mark --mark 0x200 -j SNAT --to-source $(nvram get wan2_ipaddr)
#permit access to wan2
iptables -A POSTROUTING -t nat -j MASQUERADE -o $(nvram get wan2_ifname)
#restore-mark is done in PREROUTING. If restored again, will loose the outgoing marks
iptables -t mangle -D SVQOS_OUT -j CONNMARK --restore-mark 2> /dev/null
#iptables -t mangle -A PREROUTING -i $(nvram get lan_ifname) -m multiport -p tcp --dport 22,25,80,110,119,143,443,993,3389 -j MARK --set-mark 0x100
#use WAN1 for common navigation, WAN2 for P2P traffic and others
#iptables -t mangle -I PREROUTING -i $(nvram get lan_ifname) -s 192.168.1.100 -j MARK --set-mark 0x200
#iptables -t mangle -I PREROUTING -i $(nvram get lan_ifname) -s 192.168.1.100 -j LOG --log-prefix 'P2P: '
RP_PATH=/proc/sys/net/ipv4/conf
for IFACE in `ls $RP_PATH`; do
   echo 0 > $RP_PATH/$IFACE/rp_filter
done

Once everything works, you should use the command ' ip route equalize' (search with Google for the syntax) to balance the load, or do a -j MARK --set-mark 0xN00 via iptables to redirect your traffig to WAN1 (0x100) or WAN2 (0x200)

If you need further assistance, post in forums or PM -me

The firewall scripts does not yet implement the full DD-WRT firewall, only the basic port/range forwarding.

This is script works for both outgoing AND incoming connections (most scripts only treats outgoing), so you should be able to accept connections in both links simultaneous (eg. web in one and FTP in another).