Imagine this, you have more than two networks separated by Virtual Lans protocols (IEEE 802.1q) or VLANs, carried to you by an intelligent/manageable switch on one troncal line 10/100/1000 MB HD/FD (naturally the best is 1000 MB FD).

Imagine this, you have more than two networks separated by Virtual Lans protocols (IEEE 802.1q) or VLANs, carried to you by an intelligent/manageable switch on one troncal line 10/100/1000 MB HD/FD (naturally the best is 1000 MB FD).

−

You have to share internet to a really BIG numbers of hosts, and maintain a good performance. The first choice is to separate the networks into a equal numbers of ports and maybe a more numbers of firewalls machines. This is not really cost effective, but works.

+

This page introduce how to create High Performance Firewall / Nat with iptables and VLANs and iproute2. Then you can share internet to a really BIG numbers of hosts, and maintain a good performance.

−

−

The second one is what I did. The history of how this begin is related to a some emergency/burn/crash/out of a group of Cisco PIXs. I won't go too deeply into that.

−

−

===VLAN support===

−

−

The first thing we have to do is give the kernel the capacity to work with Jumbo Frames. This is done by adding the 8021q module to the kernel

−

# modprobe 8021q

−

and/or put in modules in /etc/rc.conf; alternatively using systemd modules are managed in /etc/modules-load.d/

−

Next we have to create the virtuals NICs with this command ''vconfig''. Let's suppose we have vlans 20,30,40 and 50 working in our core network.

+

==VLAN support==

−

{{note|vconfig deprecated, use iproute2 instead}}

−

# vconfig add ethX 20

−

# vconfig add ethX 30

−

...

−

# vconfig add ethX 50

−

Where ''ethX'' is the trunk NIC

−

Now, if we want to see the interfaces just put '''ifconfig -a''' and we will get a list.

−

So .... next just set the private address as you want. For example (using eth1 like a troncal)

+

First, create sub-network as in page [[VLAN]].

−

# ifconfig eth1.20 192.168.0.1 netmask 255.255.248.0

−

# ifconfig eth1.30 192.168.8.1 netmask 255.255.248.0

−

...

−

etc.

−

I will not explain the number of host neither the mask....

−

I do a kind of daemon with this, a vlan.conf file in /etc and a vland in /etc/rc.d... I can share this if you want?

−

====The round robin NAT====

+

===The round robin NAT===

Let's suppose we have a one ip: 200.aaa.bbb.6 and our gateway is 200.aaa.bbb.1. we can safely put these parameters by default in our configuration. It will not get participation at all in our firewall.

Let's suppose we have a one ip: 200.aaa.bbb.6 and our gateway is 200.aaa.bbb.1. we can safely put these parameters by default in our configuration. It will not get participation at all in our firewall.

Line 57:

Line 32:

It's important that every real router knows every group and publishes its via BGP (or similar) to the neighbours.

It's important that every real router knows every group and publishes its via BGP (or similar) to the neighbours.

−

====tips====

+

===tips===

To accelerate some ports you can put this in the top of FORWARD chain

To accelerate some ports you can put this in the top of FORWARD chain

Line 80:

Line 55:

If you can, before they reach our machine.

If you can, before they reach our machine.

−

===The High Performance===

+

==The High Performance==

We get to the real important part of this howto.

We get to the real important part of this howto.

Line 108:

Line 83:

The next part will need some comprehension about buckets and conntracks and hashsize (the way how iptables manage the nat connections).

The next part will need some comprehension about buckets and conntracks and hashsize (the way how iptables manage the nat connections).

−

There is a very good document about this at [http://www.wallfire.org/misc/netfilter_conntrack_perf.txt here]. Read it!!!!

+

There is a very good document about this at [https://github.com/jeffmurphy/NetPass/blob/master/doc/netfilter_conntrack_perf.txt here]. Read it!!!!

Some thing are change since IPtables is know as Netfiler.

Some thing are change since IPtables is know as Netfiler.

Line 118:

Line 93:

The ''''nf_conntrack hashsize=1048576'''' increase the numbers of the hashsize (increase the kernel memory designated to NAT connections) (need reboot or '''reload module''' :-) see with ''dmesg | grep conntrack'')

The ''''nf_conntrack hashsize=1048576'''' increase the numbers of the hashsize (increase the kernel memory designated to NAT connections) (need reboot or '''reload module''' :-) see with ''dmesg | grep conntrack'')

−

And the next is put some similar to the ''/etc/sysctrl.conf'' file

+

And the next is put some similar to the {{ic|/etc/sysctl.d/99-sysctl.conf}}: file

...

...

net.netfilter.nf_conntrack_max = 1048576

net.netfilter.nf_conntrack_max = 1048576

...

...

−

And do the ''sysctl -p'' command

+

And do the ''sysctl --system'' command

In my case is the same number, that means that I have 1 connection for bucket!!!! I do not need more!!!! by default NetFilter put rate of 1:8. I.E. 8 conections per bucket!! (I think, not remember well)..

In my case is the same number, that means that I have 1 connection for bucket!!!! I do not need more!!!! by default NetFilter put rate of 1:8. I.E. 8 conections per bucket!! (I think, not remember well)..

Line 130:

Line 105:

And put this in a snmpd agent to get and graph it in a MRTG/cacti server ..... uuuuuuu homework

And put this in a snmpd agent to get and graph it in a MRTG/cacti server ..... uuuuuuu homework

−

===The iproute2===

+

==The iproute2==

We have 3 big access to Internet!!! This is because we manage 3 class C groups of IPs (some restrictions of BGP) in this firewall. So, we have 3 incoming traffics that we can manage, but only one outgoing!!! Our default gateway.

We have 3 big access to Internet!!! This is because we manage 3 class C groups of IPs (some restrictions of BGP) in this firewall. So, we have 3 incoming traffics that we can manage, but only one outgoing!!! Our default gateway.

Imagine this, you have more than two networks separated by Virtual Lans protocols (IEEE 802.1q) or VLANs, carried to you by an intelligent/manageable switch on one troncal line 10/100/1000 MB HD/FD (naturally the best is 1000 MB FD).

This page introduce how to create High Performance Firewall / Nat with iptables and VLANs and iproute2. Then you can share internet to a really BIG numbers of hosts, and maintain a good performance.

Contents

VLAN support

The round robin NAT

Let's suppose we have a one ip: 200.aaa.bbb.6 and our gateway is 200.aaa.bbb.1. we can safely put these parameters by default in our configuration. It will not get participation at all in our firewall.

I say I have 3 groups of 10 IPs each to play...... we'll define the NEXT in our firewall script:

The High Performance

In our run to get a really big number of hosts running through our machine we miss some things

We forget that is just one NICs to potentially more than 8000 Mac Addresses. The card shared memory is not prepare for this!!!!!

By default iptables is not prepared to make this number of connections simultaneously !!!!!!

So...

To the first issue...
I get some error messages in the logs relative to this, I'm really sorry, I lost these logs and do not remember what they said. But the answer is this, increase the threshold memory to the neighbours.
Type this and read:

and make sysctl -p to increase to the double!!! (no reboot needed) with this I get no errors!!!!!

The next part will need some comprehension about buckets and conntracks and hashsize (the way how iptables manage the nat connections).
There is a very good document about this at here. Read it!!!!
Some thing are change since IPtables is know as Netfiler.

The last ones is just to avoid some problems that we have with ftp connections (I thing this is not necessary anymore).
The 'nf_conntrack hashsize=1048576' increase the numbers of the hashsize (increase the kernel memory designated to NAT connections) (need reboot or reload module :-) see with dmesg | grep conntrack)

And the next is put some similar to the /etc/sysctl.d/99-sysctl.conf: file

...
net.netfilter.nf_conntrack_max = 1048576
...

And do the sysctl --system command

In my case is the same number, that means that I have 1 connection for bucket!!!! I do not need more!!!! by default NetFilter put rate of 1:8. I.E. 8 conections per bucket!! (I think, not remember well)..

In our case we get about 600.000 simultaneous connections in 2 1Giga NICs cards, You can see this with the next command

# cat /proc/sys/net/netfilter/nf_conntrack_count

And put this in a snmpd agent to get and graph it in a MRTG/cacti server ..... uuuuuuu homework

The iproute2

We have 3 big access to Internet!!! This is because we manage 3 class C groups of IPs (some restrictions of BGP) in this firewall. So, we have 3 incoming traffics that we can manage, but only one outgoing!!! Our default gateway.
This can easily fill our outgoing quote, so we have to spare it.

It's recommended but not necessary put the local interfaces to each table. If you do not put the next few lines you will get not answer of ping in the local network, but you will be able to pass trough.