Use more than one IP

Ok, we run a small WISP and we have 1 8mb conection with 30 ip public adresses and 4 adsl4 mb conections, we balance across the five conections and everything is very fast and working ok but as the number of customers gets larger we are having the problem that they can’t download from megaupload or rapidshare because they receive the message that their ip is already downloading. This is because we are going out only from 5 ips one from each conection and don’t know how can we use the other 29 from the 8mb conection.

Is there a way to use the 30 ips from the 8mb conection?

Thanks in advance for your help.

Are you doing NAT then? You should probably start assigning each customer their own public IP; either statically, via PPPoE, or via DHCP, and let the customer router or CPE do the NAT.

Thanks for your reply, yes we are doing NAT, we can’t assign public IP adresses to the customers because we don’t have enough (we have 180 customers and only 30 ips) and also we are using 5 wans and the public ip adresses are only on 1.

Best regards,

Take a look at the PCC wiki. That example shows how to use PCC for load balancing, but you can just stop after marking the connection and instead of assigning a routing mark use the connection mark derived from PCC to src-nat. The both-addresses or even just the src-address qualifiers would work well.

Your upstream should be willing to give you as many IPs as you can justify, in this case you should be able to get a full /24.

But anyway, there might be a way to get NAT to use more than one IP in a round robin fashion, otherwise, depending on how your customers are connected, you could do something like create 30 vlans or 30 bridges and group the customers into those with each vlan or bridge having its own public IP and NAT rule. Just an idea, and there may or may not be better ways to do it (besides giving the customers their own IPs). Its hard to say without knowing more about how everything is set up; but maybe this will give you a creative nudge to help you come up with something (and there would still be the potential for problems with those download sites).

Thanks a lot that sounds like something that could work, so should I add the 30 IP Adresses in IP/Adress and then src-address to point those adresses?

The basic idea would be something like this, shown for just three IPs, they are all balanced between and one of them is used for fallback:

# assign the addresses used for NAT to the WAN interface so that the router responds to ARP requests from the upstream
/ip address
add address=1.1.1.2/25 interface=WAN
add address=1.1.1.3/25 interface=WAN
add address=1.1.1.4/25 interface=WAN

# now mark connections with PCC to decide what to NAT to. Src-nat is very late in the packet flow, so below this is done in the postrouting mangle chain after it's been decided that the packet will go out to the WAN. Only packets going through the router are balanced for NAT, router generated packets are always NAT'd to the same IP. Adjust passthrough if you have later rules.
/ip firewall mangle
add chain=postrouting out-interface=WAN src-address-type=!local per-connection-classifier=both-addresses:3/0 action=mark-connection new-connection-mark=NAT_to_dot2 passthrough=no
add chain=postrouting out-interface=WAN src-address-type=!local per-connection-classifier=both-addresses:3/1 action=mark-connection new-connection-mark=NAT_to_dot3 passthrough=no
add chain=postrouting out-interface=WAN src-address-type=!local per-connection-classifier=both-addresses:3/2 action=mark-connection new-connection-mark=NAT_to_dot4 passthrough=no

# now NAT, fallback to .2, which is also used for router generated packets
/ip firewall nat
add chain=srcnat connection-mark=NAT_to_dot2 out-interface=WAN action=src-nat to-address=1.1.1.2
add chain=srcnat connection-mark=NAT_to_dot3 out-interface=WAN action=src-nat to-address=1.1.1.3
add chain=srcnat connection-mark=NAT_to_dot4 out-interface=WAN action=src-nat to-address=1.1.1.4
add chain=srcnat out-interface=WAN action=src-nat to-address=1.1.1.2

That should work and easily extend. If you need to have a client always NAT to the same IP just use the src-address classifier.

Thanks fot the example, it’s very helpful. I currently use pcc and can change it easily but after the pcc I have packet marks for the queue tree, this is going to make them stop working?

Depends on your current setup. The above doesn’t set packet marks so it wouldn’t affect those. It sets passthrough to no, but only in the postrouting chain, so unless you’re already using the postrouting chain for something else it won’t interfere. However, if you are already using PCC to make routing decisions it might interfere because you’re constantly changing the mark on the connection, which could make them unstable. I don’t think it would be advisable to mix the two. That would apply to any balancing scheme, the problem isn’t using PCC twice, the problem is marking connections twice.
You can use PCC straight in the NAT rules, though. Don’t use mangle at all to mark for NAT, just src-nat directly from the PCC decision:

# assign the addresses used for NAT to the WAN interface so that the router responds to ARP requests from the upstream
/ip address
add address=1.1.1.2/25 interface=WAN
add address=1.1.1.3/25 interface=WAN
add address=1.1.1.4/25 interface=WAN

# now NAT, fallback to .2, which is also used for router generated packets
/ip firewall nat
add chain=srcnat out-interface=WAN src-address-type=!local per-connection-classifier=both-addresses:3/0 action=src-nat to-address=1.1.1.2
add chain=srcnat out-interface=WAN src-address-type=!local per-connection-classifier=both-addresses:3/1 action=src-nat to-address=1.1.1.3
add chain=srcnat out-interface=WAN src-address-type=!local per-connection-classifier=both-addresses:3/2 action=src-nat to-address=1.1.1.4
add chain=srcnat out-interface=WAN action=src-nat to-address=1.1.1.2

I’ve never tried that but don’t see why it wouldn’t work.

Ok I did a quick test using the example. I tried with five ip adresses something like this:

/ip firewall mangle
add chain=postrouting out-interface=x10 src-address-type=!local per-connection-classifier=both-addresses:5/0 action=mark-connection new-connection-mark=fibra1 passthrough=yes
add chain=postrouting out-interface=x10 src-address-type=!local per-connection-classifier=both-addresses:5/1 action=mark-connection new-connection-mark=fibra2 passthrough=yes
add chain=postrouting out-interface=x10 src-address-type=!local per-connection-classifier=both-addresses:5/2 action=mark-connection new-connection-mark=fibra3 passthrough=yes
add chain=postrouting out-interface=x10 src-address-type=!local per-connection-classifier=both-addresses:5/3 action=mark-connection new-connection-mark=fibra4 passthrough=yes
add chain=postrouting out-interface=x10 src-address-type=!local per-connection-classifier=both-addresses:5/4 action=mark-connection new-connection-mark=fibra5 passthrough=yes

/ip firewall nat
add chain=srcnat connection-mark=fibra1 out-interface=x10 action=src-nat to-address=189.xx.xx.34
add chain=srcnat connection-mark=fibra2 out-interface=x10 action=src-nat to-address=189.xx.xx.35
add chain=srcnat connection-mark=fibra3 out-interface=x10 action=src-nat to-address=189.xx.xx.36
add chain=srcnat connection-mark=fibra4 out-interface=x10 action=src-nat to-address=189.xx.xx.37
add chain=srcnat connection-mark=fibra5 out-interface=x10 action=src-nat to-address=189.xx.xx.39
add chain=srcnat out-interface=x10 action=src-nat to-address=189.xx.xx.35

I had a route that included all de adresses i had decalred from the public ip pool I have in ip/adress and all the traffic left throuh it using just the preferred adress (189.xx.xx.35) if I disabled that route the traffic stopped.

Also I dont know why but in firewall/nat the connection mark fibra4 y fibra 5 didn’t passed dat even though that the mangle rules that marcked that conections reported the expected data.

So the first trial was a desaster. Back to the sketch board.

This is what we use now for loadbalancing and traffic shapping:

/ip firewall mangle

add action=mark-connection chain=input comment="Marcar Entrantes" \
    connection-state=new disabled=no in-interface=ether7 new-connection-mark=\
    adsl1_conn passthrough=yes
add action=mark-connection chain=input comment="" connection-state=new \
    disabled=no in-interface=ether8 new-connection-mark=adsl2_conn \
    passthrough=yes
add action=mark-connection chain=input comment="" connection-state=new \
    disabled=no in-interface=ether9 new-connection-mark=adsl3_conn \
    passthrough=yes
add action=mark-connection chain=input comment="" connection-state=new \
    disabled=no in-interface=x10 new-connection-mark=fibra_conn passthrough=\
    yes
add action=accept chain=output comment=\
    "Prevenir que las conexiones salientes sean marcadas y ruteadas por PCC" \
    disabled=no dst-address-list=clients
add action=accept chain=output comment="" disabled=no dst-address=\
    172.165.20.0/24
add action=accept chain=output comment="" disabled=no dst-address=\
    172.165.10.0/24
add action=accept chain=output comment="" disabled=no dst-address=\
    172.165.15.0/24
add action=accept chain=output comment="" disabled=no dst-address=\
    172.165.16.0/24
add action=accept chain=output comment="" disabled=no dst-address=\
    172.165.17.0/24
add action=accept chain=output comment="" disabled=no dst-address=\
    172.165.18.0/24
add action=accept chain=output comment="Prevenir que las conexiones choquen co\
    n las marcas PCC y sean asignadas a otra salida" connection-state=new \
    disabled=no dst-address=192.168.20.0/24
add action=accept chain=output comment="" connection-state=new disabled=no \
    dst-address=192.168.254.0/24
add action=accept chain=output comment="" connection-state=new disabled=no \
    dst-address=192.168.30.0/24
add action=accept chain=output comment="" connection-state=new disabled=no \
    dst-address=189.xx.xx.32/27
add action=mark-routing chain=output comment="" connection-mark=fibra_conn \
    disabled=no new-routing-mark=to_fibra passthrough=yes
add action=mark-routing chain=output comment="" connection-mark=adsl1_conn \
    disabled=no new-routing-mark=to_adsl1 passthrough=yes
add action=mark-routing chain=output comment="" connection-mark=adsl2_conn \
    disabled=no new-routing-mark=to_adsl2 passthrough=yes
add action=mark-routing chain=output comment="" connection-mark=adsl3_conn \
    disabled=no new-routing-mark=to_adsl3 passthrough=yes
add action=accept chain=prerouting comment="Reglas de Aceptacion-Prevenir cone\
    xiones locales que sean marcadas y enviadas a las salidas de ineternet don\
    de serian rechazadas porque las direcciones no coinciden" disabled=no \
    dst-address=192.168.20.0/24 src-address-list=clients
add action=accept chain=prerouting comment="" disabled=no dst-address=\
    192.168.254.0/24 src-address-list=clients
add action=accept chain=prerouting comment="" disabled=no dst-address=\
    192.168.30.0/24 src-address-list=clients
add action=accept chain=prerouting comment="" disabled=no dst-address=\
    189.xx.xx.xx/27 src-address-list=clients
add action=accept chain=prerouting comment="" disabled=no dst-address-list=\
    clients src-address-list=clients
add action=mark-connection chain=prerouting comment="Marcar las conexiones de \
    las direcciones de los clientes con el balanceo PCC para asignarles las re\
    glas de ruteo" connection-state=new disabled=no dst-address-type=!local \
    new-connection-mark=fibra_conn passthrough=yes per-connection-classifier=\
    both-addresses:5/0 src-address-list=clients
add action=mark-connection chain=prerouting comment="" connection-state=new \
    disabled=no dst-address-type=!local new-connection-mark=fibra_conn \
    passthrough=yes per-connection-classifier=both-addresses:5/1 \
    src-address-list=clients
add action=mark-connection chain=prerouting comment="" connection-state=new \
    disabled=no dst-address-type=!local new-connection-mark=adsl1_conn \
    passthrough=yes per-connection-classifier=both-addresses:5/2 \
    src-address-list=clients
add action=mark-connection chain=prerouting comment="" connection-state=new \
    disabled=no dst-address-type=!local new-connection-mark=adsl2_conn \
    passthrough=yes per-connection-classifier=both-addresses:5/3 \
    src-address-list=clients
add action=mark-connection chain=prerouting comment="" connection-state=new \
    disabled=no dst-address-type=!local new-connection-mark=adsl3_conn \
    passthrough=yes per-connection-classifier=both-addresses:5/4 \
    src-address-list=clients
add action=mark-routing chain=prerouting comment="" connection-mark=\
    adsl1_conn disabled=no new-routing-mark=to_adsl1 passthrough=yes \
    src-address-list=clients
add action=mark-routing chain=prerouting comment="" connection-mark=\
    adsl2_conn disabled=no new-routing-mark=to_adsl2 passthrough=yes \
    src-address-list=clients
add action=mark-routing chain=prerouting comment="" connection-mark=\
    adsl3_conn disabled=no new-routing-mark=to_adsl3 passthrough=yes \
    src-address-list=clients
add action=mark-routing chain=prerouting comment="" connection-mark=\
    fibra_conn disabled=no new-routing-mark=to_fibra passthrough=yes \
    src-address-list=clients
add action=mark-packet chain=prerouting comment="H.323 - Voice over IP" \
    disabled=no layer7-protocol=h323 new-packet-mark=h323_voiceoverip_in \
    passthrough=no
add action=mark-packet chain=postrouting comment="" disabled=no \
    layer7-protocol=h323 new-packet-mark=h323_voiceoverip_out passthrough=no
add action=mark-packet chain=prerouting comment=\
    "SIP - Session Initiation Protocol - Internet telephony " disabled=no \
    layer7-protocol=sip new-packet-mark=sip_in passthrough=no
add action=mark-packet chain=postrouting comment="" disabled=no \
    layer7-protocol=sip new-packet-mark=sip_out passthrough=no
add action=mark-packet chain=prerouting comment=\
    "Skype to Skype - UDP voice call " disabled=no layer7-protocol=\
    skypetoskype new-packet-mark=skype2skype_in passthrough=no
add action=mark-packet chain=postrouting comment="" disabled=no \
    layer7-protocol=skypetoskype new-packet-mark=skype2skype_out passthrough=\
    no
add action=mark-packet chain=prerouting comment=\
    "Skype to phone - UDP voice call " disabled=no layer7-protocol=skypeout \
    new-packet-mark=skypeout_in passthrough=yes
add action=mark-connection chain=postrouting comment="" disabled=no \
    new-connection-mark=NAT_to_fibra1 out-interface=x10 passthrough=yes \
    per-connection-classifier=both-addresses:5/0 src-address-type=!local
add action=mark-connection chain=postrouting comment="" disabled=no \
    new-connection-mark=NAT_to_fibra2 out-interface=x10 passthrough=yes \
    per-connection-classifier=both-addresses:5/1 src-address-type=!local
add action=mark-connection chain=postrouting comment="" disabled=no \
    new-connection-mark=NAT_to_fibra3 out-interface=x10 passthrough=yes \
    per-connection-classifier=both-addresses:5/2 src-address-type=!local
add action=mark-connection chain=postrouting comment="" disabled=no \
    new-connection-mark=NAT_to_fibra4 out-interface=x10 passthrough=yes \
    per-connection-classifier=both-addresses:5/3 src-address-type=!local
add action=mark-connection chain=postrouting comment="" disabled=no \
    new-connection-mark=NAT_to_fibra5 out-interface=x10 passthrough=yes \
    per-connection-classifier=both-addresses:5/4 src-address-type=!local
add action=mark-packet chain=postrouting comment="" disabled=no \
    layer7-protocol=skypeout new-packet-mark=skypeout_out passthrough=no
add action=mark-packet chain=prerouting comment=QoS disabled=no \
    new-packet-mark=icmp passthrough=no protocol=icmp
add action=mark-packet chain=prerouting comment="" disabled=no dst-port=443 \
    new-packet-mark=ssl passthrough=no protocol=tcp
add action=mark-packet chain=prerouting comment="" disabled=no \
    new-packet-mark=p2p p2p=all-p2p passthrough=no
add action=mark-packet chain=prerouting comment="" disabled=no \
    new-packet-mark=udp-100 packet-size=0-100 passthrough=no protocol=udp
add action=mark-packet chain=prerouting comment="" disabled=no \
    new-packet-mark=upd-500 packet-size=100-500 passthrough=no protocol=udp
add action=mark-packet chain=prerouting comment="" disabled=no \
    new-packet-mark=upd-other passthrough=no protocol=udp
add action=mark-packet chain=prerouting comment="" disabled=no dst-port=1863 \
    new-packet-mark=msn-messenger passthrough=no protocol=tcp
add action=mark-packet chain=prerouting comment="" disabled=no dst-port=110 \
    new-packet-mark=pop3 passthrough=no protocol=tcp
add action=mark-packet chain=prerouting comment="" disabled=no dst-port=25 \
    new-packet-mark=smtp passthrough=no protocol=tcp
add action=mark-packet chain=prerouting comment="" disabled=no dst-port=143 \
    new-packet-mark=imap passthrough=no protocol=tcp
add action=mark-packet chain=prerouting comment="" disabled=no \
    new-packet-mark=gre passthrough=no protocol=gre
add action=mark-packet chain=prerouting comment="" disabled=no \
    new-packet-mark=ipsec-esp passthrough=no protocol=ipsec-esp
add action=mark-packet chain=prerouting comment="" disabled=no \
    new-packet-mark=ipsec-ah passthrough=no protocol=ipsec-ah
add action=mark-packet chain=prerouting comment="" disabled=no \
    new-packet-mark=ipencap passthrough=no protocol=ipencap
add action=mark-packet chain=prerouting comment="" disabled=no \
    new-packet-mark=ipip passthrough=no protocol=ipip
add action=mark-packet chain=prerouting comment="" disabled=no \
    new-packet-mark=Youtube passthrough=no src-address-list=Youtube
add action=mark-packet chain=prerouting comment="" disabled=no dst-port=80 \
    new-packet-mark=http passthrough=no protocol=tcp
add action=mark-packet chain=prerouting comment="" connection-bytes=1-512000 \
    disabled=no new-packet-mark=0bytes passthrough=yes
add action=mark-packet chain=prerouting comment="" connection-bytes=\
    512000-1000000 disabled=no new-packet-mark=1Mbyte passthrough=yes
add action=mark-packet chain=prerouting comment="" connection-bytes=\
    1000000-3000000 disabled=no new-packet-mark=3Mbyte passthrough=yes
add action=mark-packet chain=prerouting comment="" connection-bytes=\
    3000000-6000000 disabled=no new-packet-mark=6Mbyte passthrough=yes
add action=mark-packet chain=prerouting comment="" connection-bytes=\
    6000000-30000000 disabled=no new-packet-mark=30Mbyte passthrough=yes
add action=mark-packet chain=prerouting comment="" connection-bytes=\
    30000000-60000000 disabled=no new-packet-mark=60Mbytes passthrough=yes
add action=mark-packet chain=prerouting comment="" connection-bytes=\
    60000000-0 disabled=no new-packet-mark=Infinite passthrough=yes
add action=mark-connection chain=prerouting comment="" disabled=yes \
    new-connection-mark=other-tcp passthrough=no protocol=tcp
add action=mark-connection chain=prerouting comment="" disabled=yes dst-port=\
    1024-65535 new-connection-mark=skype passthrough=no protocol=udp \
    src-port=36725
add action=mark-connection chain=prerouting comment="" connection-state=new \
    disabled=yes new-connection-mark=other-udp passthrough=no protocol=udp