 Tom here for more systems and we're going to talk about gateway groups and load balancing and PF sense Now the first question I want to get out of the way because this question comes up quite a bit And it's most commonly asked is if you have more than one service provider for your network connection Can't you load balance your way to mega connection the cumulative rate of all those connections combined? And that's not exactly how that works I have a video linked down below about SD WAN where I kind of explain yes You can bond them together, but when you bond them together you only get the connection speed That's available to a single host in a single. Let's say TCP stream It doesn't automatically bond all the connections together to give you the cumulative rate now We are going to talk about load balancing because when you have many hosts and it's often why this is done It will balance the connections across multiple connections, but it does not automatically just give you let's say when you're doing a download Or a speed test the rate depending on how many streams that speed test is actually testing or those connections allow So something for example requires a single TCP stream. It's only going to go as fast through a single provider That's where that SD WAN comes in because bonding different providers together. Well, that's something that can be done It's just a little bit more complicated than just setting up a load balance But today we're going to focus on the load balance the gateway groups how to set them up And I did another video on policy routing. We're going to be covering how you set the Policy routing to make that work. It's very similar to policy routing But we're actually in a policy route not just off of a gateway But off of the group that we build for either the load balance or the failover And yes, you can have many of them or multiple men there now before we get started in this video Let's think of sponsor first Are you an individual or company looking for support on a network engineering storage or virtualization project? Is your company or internal IT team looking for someone to proactively monitor your system security Or offer strategic guidance to keep your IT systems operating smoothly? Not only would we love to help consulting your project We also offer fully managed or co-managed IT service plans for businesses in need of IT administration Or IT teams in need of additional support With our expert install team We can also assist you with all of your structure cabling and Wi-Fi planning projects If any of this piques your interest, fill out our hire us form at laurancesystems.com So we can start crafting a solution that works for you If you're not interested in hiring us But you're looking for other ways you want to support this channel There's affiliate links down below to get you deals and discounts on products and services We talk about on this channel and now back to our content Let's do a quick overview of how this lab is set up This is a basic Ubuntu system I have set up at 192.168.40.151 that is behind the PF sense It has the option of going out WAN2 or WAN And these are the addresses set to WAN2 and the other WAN Then it goes to our simulated internet Which then lands on 172.169.152 I'm using a tool called IPerf3 So we can create a connection from here And figure out which way it's going to route Or we're going to actually balance the routes between them And then land over to this IP address Now by doing this and switching and we'll simulate a failover You'll see how the switching occurs And how the bandwidth management works for there Because we're going to do it first with a single stream And then we're going to start splitting the streams To get an idea of how that load balance part works All right, so we're over in our PF sense We can see 192.168.3.217 here And 192.168.4.5 Those are the two different WANs that are set up We go to system and routing We can see that the WAN DHCP Which is just the regular WAN is set to the default gateway So if we do a quick test with a default gateway set And we're just going to switch over here And just do an IPerf test So now we're sending some traffic At about 200 megs a second And you can see that traffic going over WAN Not WAN2 WAN2 is only in the kilobits This one's going about 26 megabits here So you can see it matches the amount that's going out of the land If we go over here, system routing And we were to switch it to be WAN2 gateway Hit apply Jump back over here Do this up arrow We're just going to run that same test again And now we see the traffic going out WAN2 Pretty simple to get these connections Going out either one of them and switch your default gateway Let's go ahead though and go back over to routing And build a balance group So we're going to call this one balance Tier one Tier one When you want them balanced, you choose them both to be the same tier This will create a balance group between these two different interfaces Or if you had more interfaces, the same rules apply And then as far as member down packet loss or high latency These are some options you can choose the one you want to remove that member from the list So it will work also as a failover even with them at the same tier It's just going to split the connections between these two services So we'll leave it the trigger level We'll go ahead and do packet loss or high latency Because I usually want them to drop out once there's too much packet loss on one of these You can also adjust these latency and packet thresholds I have another video linked about how to do gateway monitoring on PF Since where I dive more into detail now We'll call this our balance connection Save apply Now you're probably thinking that should do the trick And then we should have balance But actually there's another step you need to do So this did set up the balance But what it didn't do was automatically create a rule for it So right now it's still going to go out whatever the default gateway is So we're going to go over here to firewall rules Then we're going to go to LAN We're going to edit this rule Now this is the same as my policy routing video that I was discussing The other day I'll link that one down below But we're going to go down here and we want to choose The balanced option for the gateway So the gateway balanced hit save and apply So now we can look at this rule This is the allow all rule balance Now you can choose each individual network you have Or different rules based on policy routing that you want balance Maybe you don't want everything balanced Maybe you want certain things balanced You could have different rules based on different sources Different networks So that is the policy works the same way For creating it and applying it then to a load balance group So let's go ahead and run the test again So go to the screen here Kick off this Iperf test again We can see the same speed Because as I said it's not going to give you more speed But what you're going to notice is it's only sending it out when This is the single stream problem Because by default Iperf only sends a single stream So if we take the stream though And we're going to change it And we'll use the option dash capital P And we'll break it out just into two streams And now it's going to load balance Because with two streams Now we've got two of them running simultaneously Half goes here and half goes here So the cumulative of WAN and WAN2 Equals the total for LAN now Because now we created that balanced connection Between these two devices But as I said if there's a single stream There's nothing it can do It can't break that single stream to put it across two Because that's not how TCPIP connections work All right the next thing we're going to do Is fail this connection And the way I'm going to fail it is Just disable it inside my lab You'll actually see this go offline packet loss And we're going to run the connection again Just to show you how that works It was still able to find the connection But of course it's only going to go out Because it can't go out WAN2 as it's down It's only going to go out the one WAN So the load balance works perfectly fine for this It will split them It will easily fail over when one of these goes down So let's go ahead and bring this one back up And create a different group So we're going to system, routing, gateway groups And we'll just say how they fail over group And we want the first WAN to be tier one Well let's make this one tier two And that one tier one There we go We want it to default to this Same thing remember down hit save And this is going to be our fail over one I guess we could probably give it the description Of fail over group Hit save Apply And then we go back over here to firewall Rules, LAN And we can create another rule Or we can edit this one And change this one from balanced to fail over group Hit save So now this instead of splitting Is going to be in a fail over mode So right now it's going to default to This one here you can see a little globe To tell me that the 4.1 is the default gateway So if we go over here run a test It's on WAN right now going out WAN2 Now we're going to go ahead and drop WAN2 Put it offline Offline packet loss Which broke this connection So we're just going to cancel it I'm going to terminate it because When you drop it it's going to drop that connection Server busy try again later It's going to take a second to Drop all those connections that we just broke Because it's thinking there's another test still coming in All right we can start the connection again here And if we go over here Now it's going out WAN1 That's all you have to do pretty simple Now for the rules You can create as I said different rules inside of here So we did this one for fail over Maybe you want a rule where you have Single hosts that you want So certain sources Maybe a single host or alias You want like these ones to work And say for example if the source Is the IP address of the system we're doing We want this one To be part of that load balance group So we're going to go ahead and change the gateway to Balanced on this one Then other devices will be all on the fail over So anything over here is going to be balanced Anything on this one is going to be fail over You can see how you can kind of build your rules out On an as needed basis for those It's really that simple for setting the fail over groups And gateway groups You do want to make sure one thing Because this is my favorite way I learned To break PF Sense setting up this demo This one set up for balance This one set up for fail over And I'm going to kind of call this a bug Because we can go here to our gateway groups And if we want we can delete a gateway group If you delete a gateway group that is assigned Instead of getting an error You'll manage to lock yourself out of the PF Sense You can go to the command line And restore that last change you made That locked you out of the PF Sense This cause is kind of an interesting condition I didn't see if there's a bug report on this yet But if not maybe I'll follow one Because it should warn you That these groups are in use Also of note if you set them here To something other than automatic Such as the fail over group And hit save and apply And then delete one of those gateway groups That are applied there It will also lock you out of your PF Sense A couple quick things I learned during the demo Now a couple advanced topics I want to cover here One of them is problems with load balancing And this is all in the PF Sense documentation And the sticky connection feature Is intended to fix this potential problem And that's that a expected site May require a host Let's say your phone is wanting to connect To some site or a client behind your PF Sense Your computer is trying to connect to a site And it expects not only the first connection But subsequent connections to all come From the same IP address And in the case of having two different ISPs With two different public IP addresses If you balance the subsequent connections So they come differently You could run into a little bit of problem And this is where they have the sticky connections for that So let's show you where the sticky connections are We go to system advanced Miscellaneous and just check the box Use sticky connections No need to reboot your firewall if you do this Change anything really You just click save But this sticky connections may solve If you're having problems with this This could actually cause a lot of drama That you may not even know about When you set up a load balance Because you don't necessarily know what doesn't work By having those connections come from two different sources Until you have a lot of clients on a network So that option is there if you need it And this is called unequal cost load balancing PF Sense software can achieve unequal cost load balancing By setting the appropriate weights on the gateways Discuss under advanced gateway settings By setting a weight on a gateway It will be used more often in a gateway group And weights can be set from 1 to 30 allowing And this is where you're going to set your splits To split up the loads Note this is a distribution of strictly balancing Number of connections It does not take in to consideration The interface throughput or existing load into account So we're going to split the connections Based on the quantity of them Not the bandwidth that they're using So let's go ahead and look at that real quick Now to do the unequal cost load balancing These are where those settings are We're going to edit the gateway And we're just going to set this one at a weight of two So this one has a weight of two We're going to hit save We're going to look at the other one We're going to leave it at a weight of one So that's the default So we've got those both set now Make sure we apply the changes Now this applies equally to both of these It doesn't really matter though Unless you're using the balance Because they're both set to tier one So then it will take that into account So we're going to go and make sure We're using that particular rule And we are Here's our default gateway rule It's set to the balance Both of these gateways are active So we go here And now we're going to see How the connection loads between them So we'll just split this to IPERF-P100 for a hundred connections And it will now distribute those connections Based on that weight So because this one has a higher weight This one's going to get most of the connection So we've got 18 going here And we've got about eight going here To build the cumulative of our LAN Now if we wanted to adjust that balance Differently Go over here Back to our routing Go here And set this to a weight of three Save Apply Back to here And let's see how it distributes it now Run that connection test again And it brought this one down to about six And that means this one goes up to about 20 To get that connection going across there Kind of gives you an idea of how you can adjust those And tune those based on your requirements If those are requirements Generally you just load balance them And let it spread the connections out across there And it generally works fine So hopefully this leaves you with a clearer understanding Of how PF Sense works in terms of load balancing Do take the time to read through their documentation I always recommend it That's the source material I have for my videos here In case anyone was wondering They add in lots of testing in labs To learn what you can break That's always the fun thing and why I have a lab Leave your comments and thoughts down below Or head over to my forums for a more in-depth discussion Thanks And thank you for making it all the way to the end of this video If you've enjoyed the content, please give us a thumbs up If you would like to see more content from this channel Hit the subscribe button and the bell icon If you'd like to hire a short project Head over to lauranceystems.com And click the hires button right at the top To help this channel out in other ways There's a join button here for YouTube And a Patreon page where your support is greatly appreciated For deals, discounts, and offers Check out our affiliate links In the description of all of our videos Including a link to our shirt store Where we have a wide variety of shirts that we sell And designs come out well randomly So check back frequently And finally, our forums Forums.LauranceSystems.com Is where you can have a more in-depth discussion About this video and other tech topics Covered on this channel Thanks again for watching And look forward to hearing from you