# Using two Internet connections



## bbzz (Apr 29, 2011)

I have a cable (2 Mbps) and an adsl (4 Mbps) connection to two different providers. To utilize both, I have to decide an Internet IP range that will be reached via one or the other and set it manually in routing table. Is there another way to maximize use of both connections dynamically?


----------



## gkontos (Apr 29, 2011)

Since you can not use any dynamic routing protocol like BGP your best bet is policy based static routing.


----------



## SirDice (Apr 29, 2011)

Have a look at lagg(4).

Handbook: 31.6 Link Aggregation and Failover


----------



## AngryWolf (Apr 29, 2011)

I think you can use ipfw and natd to achieve multi-homing, eg. with a probability of 2/6 to forward packets to the cable connection, and with a probability of 4/6 to forward packets to the adsl connection. No expert there and haven't tried it yet, but maybe see section "5.1 Simulating multipath" on this page:

http://info.iet.unipi.it/~luigi/ip_dummynet/original.html


----------



## bbzz (Apr 29, 2011)

Thanks all,
I don't see how link aggregation helps since it's dual-homing connection that has two external IP addresses. 
BGP, well, out of question obviously. 
What I was thinking of was ability for dynamic routing out of slower link only if the faster link is full. In other words if I'm downloading something and adsl link is saturated, switch any other upload request to cable link. When adsl link is free again, send new requests to it. Important thing is not to load-share per packet (each different packet to same destination over different links).
Right now I have to mess with static routing every time I need a change.


----------



## aragon (Apr 29, 2011)

No one played with PF's load balancing features?  It works very well.  I'm not sure if this documentation still works on FreeBSD:

http://www.openbsd.org/faq/pf/pools.html


----------



## gkontos (Apr 30, 2011)

aragon said:
			
		

> No one played with PF's load balancing features?  It works very well.  I'm not sure if this documentation still works on FreeBSD:
> 
> http://www.openbsd.org/faq/pf/pools.html



I don't see why not. In fact it could be the best scenario here.


----------



## bbzz (Apr 30, 2011)

Unfortunately that doesn't work well for this scenario since you either end up with static hash mappings or round-robin (basically equal load balancing which won't work well with 2 Mbps and 4 Mbps connections).


----------



## aragon (Apr 30, 2011)

bbzz said:
			
		

> Unfortunately that doesn't work well for this scenario since you either end up with static hash mappings or round-robin (basically equal load balancing which won't work well with 2 Mbps and 4 Mbps connections).


Haven't tried this, but you can try add the 4 Mbps connection into the pool twice, with the hope of it being round-robinned twice as frequently as the 2 Mbps connection.


----------



## frankpeng (Mar 31, 2012)

aragon said:
			
		

> No one played with PF's load balancing features?  It works very well.  I'm not sure if this documentation still works on FreeBSD:
> 
> http://www.openbsd.org/faq/pf/pools.html



Not working in FreeBSD.


----------



## frankpeng (Apr 1, 2012)

```
#
# Macros
#
INT_IF = "em0"
EXT_IF = "bge0"
EXT_IF2 = "bge1"

table <private_nets> persist { 127/8, 172.16/12, 192.168/16, 169.254/16 }

#
# Options and default policy
#
set block-policy drop
set state-policy if-bound

#
# Packet normalization
#
scrub in                          all
scrub out on $EXT_IF all random-id
scrub        on $EXT_IF all reassemble tcp

#
# NAT/redirects
#

# NAT
nat on $EXT_IF from <private_nets> to any -> ($EXT_IF)
nat on $EXT_IF2 from <private_nets> to any -> ($EXT_IF2)

#
# Filter rules
#
pass all
#pass in from 192.168.100.0/24 to any rtable 0
#pass in from 192.168.150.0/24 to any rtable 1
```
This one works in FreeBSD, but it won't failover. If the first link is down the whole connextion is down. I have to start /etc/rc.d/ppp, /etc/rc.d/netif, /etc/rc.d/routing, /etc/rc.d/pf and /etc/rc.d/named.

The main problem is the DNS server. When the first WAN is down, you cannot access its DNS. But freebsd FreeBSD is still using the old DNS server.


----------



## overmind (Apr 21, 2012)

*Use OpenDNS DNS's*

Or set up a DNS server on a machine in a datacenter.


----------



## bbzz (Apr 22, 2012)

The problem with *pf* load balancing features is (as far as I remember when I originally asked this question), is that it simply uses static hash or round robin, etc for your outgoing connections. What is needed is something like Performance Edge Routing (in Cisco world), which could, among other things, check _download_ saturation and accordingly send requests upstream. In other words, one connection could be nearly saturated on upload, but not on downstream.

Is there a solution like this?


----------

