firehol-iptables

title: firehol-iptables(5)

summary: include custom iptables commands

text:
# firehol-iptables(5)

## NAME
firehol-iptables - include custom iptables commands

## SYNOPSIS
iptables argument...

ip6tables argument...

## DESCRIPTION
The iptables and ip6tables helper commands pass all of their arguments to the real iptables(8) or ip6tables(8) at the appropriate point during run-time.

Note

When used in an interface or router, the result will not have a direct relationship to the enclosing definition as the parameters passed are only those you supply.

You should not use /sbin/iptables or /sbin/ip6tables directly in a FireHOL configuration as they will run before FireHOL activates its firewall. This means that the commands are applied to the previously running firewall, not the new firewall, and will be lost when the new firewall is activated.

The iptables and ip6tables helpers are provided to allow you to hook in commands safely.

When using the -t option to specify a table, ensure this is the first option to iptables, otherwise "fast activation" will fail with an error message such as:

```
iptables-restore: The -t option cannot be used in iptables-restore
```

## EXAMPLES
Fix LXC DHCP on same host:

```
iptables -t mangle -A POSTROUTING -p udp --dport 68 -j CHECKSUM --checksum-fill
```

## SEE ALSO
•

firehol(1) - FireHOL program

•

firehol.conf(5) - FireHOL configuration

•

iptables(8) (http://ipset.netfilter.org/iptables.man.html) - administration tool for IPv4 firewalls

•

ip6tables(8) (http://ipset.netfilter.org/ip6tables.man.html) - administration tool for IPv6 firewalls

•

FireHOL Website (http://firehol.org/)

•

FireHOL Online PDF Manual (http://firehol.org/firehol-manual.pdf)

•

FireHOL Online Documentation (http://firehol.org/documentation/)

## AUTHORS
FireHOL Team.


firehol-iptrap

package: firehol

title: firehol-iptrap(5)

text:
# firehol-iptrap(5)

## NAME
firehol-iptrap - dynamically put IP addresses in an ipset

## SYNOPSIS
{ iptrap | iptrap4 | iptrap6 } ipset type seconds [ timeout | counters ] [ method method ] [rule-params] [ except [rule-params] ]...

{ ipuntrap | ipuntrap4 | ipuntrap6 } ipset type [ timeout | counters ] [ method method ] [rule-params] [ except [rule-params] ]...

## DESCRIPTION
iptrap adds the IP addresses of the matching packets to ipset.

ipuntrap deletes the IP addresses of the matching packets from ipset.

Both helpers do not affect the flow of traffic. They do not ACCEPT, REJECT, DROP packets or affect the firewall in any way.

ipset is the name of the ipset to use.

type selects which of the IP addresses of the matching packets will be used (added or removed from the ipset). type can be src, dst, src,dst, dst,src, etc. If type is a pair, then the ipset must be an ipset of pairs too.

seconds is required by iptrap and gives the duration in seconds of the lifetime of each IP address that is added to ipset. Every matching packet will refresh this duration for the IP address in the ipset. The Linux kernel will automatically remove the IP from the ipset when this time expires. The user may monitor the remaining time for each IP, by running ipset list NAME (where NAME is the ipset parameter given in the iptrap command).

The seconds value default will not set any seconds. The ipset default will be used.

A seconds of 0 (zero), writes to the ipset permanently (this is a feature of the ipset command, not the ipset FireHOL helper).

The keywords timeout and counters are mutually exclusive. timeout is the default and means that each IP address every time is matched its timeout will be refreshed, while counters means that its packets and bytes counters will be refreshed. Unfortunately the kernel either re-add the IP in the ipset with the new timeout - but its counters will be lost, or just the counters will be updated, but the timeout will not be refreshed.

method is defines the storage method of the underlying ipset. It accepts all the types the ipset commands accepts.

method and type should match. For example if method is hash:ip then method should be either src or dst. If method is hash:ip,ip then method should be either src,dst or dst,src. If method is hash:ip,port,ip method should be src,src,dst or src,dst,dst or dst,src,src or dst,dst,src. For more information check the manual page of the ipset command.

The rule-params define a set of rule parameters to restrict the traffic that is matched to this helper. See firehol-params(5) for more details.

except rule-params are used to exclude traffic, i.e. traffic that normally is matched by the first set of rule-params, will be excluded if matched by the second.

iptrap and ipuntrap are hooked on PREROUTING so it is only useful for incoming traffic.

iptrap and ipuntrap cannot setup both IPv4 and IPv6 traps with one call. The reason is that the ipset can either be IPv4 or IPv6.

Both helpers will create the ipset specified, if that ipset is not already created by other statements. When the ipset is created by the iptrap helper, the ipset will not be reset (emptied) when the firewall is restarted.

The ipset options used when these helpers create ipsets can be controlled with the variable IPTRAP_DEFAULT_IPSET_OPTIONS.

## EXAMPLES

```
 # Example: mini-IDS
 # add to the ipset `trap` for an hour (3600 seconds) all IPs from all packets
 # coming from eth0 and going to tcp/3306 (mysql).
 iptrap4 src trap 3600 inface eth0 proto tcp dport 3306 log "TRAPPED HTTP"
 # block them
 blacklist4 full inface eth0 log "BLOCKED" src ipset:trap except src ipset:whitelist
 # Example: ipuntrap
 ipuntrap4 src trap inface eth0 src ipset:trap proto tcp dport 80 log "UNTRAPPED HTTP"
 # Example: a knock
 # The user will be able to knock at tcp/12345
 iptrap4 src knock1 30 inface eth0 proto tcp dport 12345 log "KNOCK STEP 1"
 # in 30 seconds knock at tcp/23456
 iptrap4 src knock2 60 inface eth0 proto tcp dport 23456 src ipset:knock1 log "KNOCK STEP 2"
 # in 60 seconds knock at tcp/34566
 iptrap4 src knock3 90 inface eth0 proto tcp dport 34567 src ipset:knock2 log "KNOCK STEP 3"
 #
 # and in 90 seconds ssh
 interface ...
     server ssh accept src ipset:knock3
```

## SEE ALSO
•

firehol(1) - FireHOL program

•

firehol.conf(5) - FireHOL configuration

•

FireHOL Website (http://firehol.org/)

•

FireHOL Online PDF Manual (http://firehol.org/firehol-manual.pdf)

•

FireHOL Online Documentation (http://firehol.org/documentation/)

## AUTHORS
FireHOL Team.


firehol-mac

title: firehol-mac(5)

text:
# firehol-mac(5)

## NAME
firehol-mac - ensure source IP and source MAC address match

## SYNOPSIS
mac IP macaddr

## DESCRIPTION
Any mac commands will affect all traffic destined for the firewall host, or to be forwarded by the host. They must be declared before the first router or interface.

Note

There is also a mac parameter which allows matching MAC addresses within individual rules (see firehol-params(5)).

The mac helper command DROPs traffic from the IP address that was not sent using the macaddr specified.

When packets are dropped, a log is produced with the label "MAC MISSMATCH" (sic.). mac obeys the default log limits (see [LOGGING][] in firehol-params(5)).

Note

This command restricts an IP to a particular MAC address. The same MAC address is permitted send traffic with a different IP.

## EXAMPLES

```
mac 192.0.2.1    00:01:01:00:00:e6
mac 198.51.100.1 00:01:01:02:aa:e8
```

## SEE ALSO
•

firehol(1) - FireHOL program

•

firehol.conf(5) - FireHOL configuration

•

firehol-params(5) - optional rule parameters

•

FireHOL Website (http://firehol.org/)

•

FireHOL Online PDF Manual (http://firehol.org/firehol-manual.pdf)

•

FireHOL Online Documentation (http://firehol.org/documentation/)

## AUTHORS
FireHOL Team.


firehol-mark

title: firehol-mark(5)

text:
# firehol-mark(5)

## NAME
firehol-mac - ensure source IP and source MAC address match

## SYNOPSIS
mac IP macaddr

## DESCRIPTION
Any mac commands will affect all traffic destined for the firewall host, or to be forwarded by the host. They must be declared before the first router or interface.

Note

There is also a mac parameter which allows matching MAC addresses within individual rules (see firehol-params(5)).

The mac helper command DROPs traffic from the IP address that was not sent using the macaddr specified.

When packets are dropped, a log is produced with the label "MAC MISSMATCH" (sic.). mac obeys the default log limits (see [LOGGING][] in firehol-params(5)).

Note

This command restricts an IP to a particular MAC address. The same MAC address is permitted send traffic with a different IP.

## EXAMPLES

```
mac 192.0.2.1    00:01:01:00:00:e6
mac 198.51.100.1 00:01:01:02:aa:e8
```

## SEE ALSO
•

firehol(1) - FireHOL program

•

firehol.conf(5) - FireHOL configuration

•

firehol-params(5) - optional rule parameters

•

FireHOL Website (http://firehol.org/)

•

FireHOL Online PDF Manual (http://firehol.org/firehol-manual.pdf)

•

FireHOL Online Documentation (http://firehol.org/documentation/)

## AUTHORS
FireHOL Team.


firehol-masquerade

title: firehol-masquerade(5)

text:
# firehol-masquerade(5)

## NAME
firehol-masquerade - set up masquerading (NAT) on an interface

## SYNOPSIS
masquerade real-interface rule-params

masquerade [reverse] rule-params

## DESCRIPTION
The masquerade helper command sets up masquerading on the output of a real network interface (as opposed to a FireHOL interface definition).

If a real-interface is specified the command should be used before any interface or router definitions. Multiple values can be given separated by whitespace, so long as they are enclosed in quotes.

If used within an interface definition the definition's real-interface will be used.

If used within a router definition the definition's outface(s) will be used, if specified. If the reverse option is given, then the definition's inface(s) will be used, if specified.

Unlike most commands, masquerade does not inherit its parent definition's rule-params, it only honours its own. The inface and outface parameters should not be used (iptables(8) does not support inface in the POSTROUTING chain and outface will be overwritten by FireHOL using the rules above).

Note

The masquerade always applies to the output of the chosen network interfaces.

FIREHOL_NAT will be turned on automatically (see firehol-defaults.conf(5) ) and FireHOL will enable packet-forwarding in the kernel.

## MASQUERADING AND SNAT
Masquerading is a special form of Source NAT (SNAT) that changes the source of requests when they go out and replaces their original source when they come in. This way a Linux host can become an Internet router for a LAN of clients having unroutable IP addresses. Masquerading takes care to re-map IP addresses and ports as required.

Masquerading is expensive compare to SNAT because it checks the IP address of the outgoing interface every time for every packet. If your host has a static IP address you should generally prefer SNAT.

## EXAMPLES

```
 # Before any interface or router
 masquerade eth0 src 192.0.2.0/24 dst not 192.0.2.0/24
 # In an interface definition to masquerade the output of its real-interface
 masquerade
 # In a router definition to masquerade the output of its outface
 masquerade
 # In a router definition to masquerade the output of its inface
 masquerade reverse
```

## SEE ALSO
•

firehol(1) - FireHOL program

•

firehol.conf(5) - FireHOL configuration

•

firehol-interface(5) - interface definition

•

firehol-router(5) - router definition

•

firehol-params(5) - optional rule parameters

•

firehol-nat(5) - nat, snat, dnat, redirect config helpers

•

FireHOL Website (http://firehol.org/)

•

FireHOL Online PDF Manual (http://firehol.org/firehol-manual.pdf)

•

FireHOL Online Documentation (http://firehol.org/documentation/)

## AUTHORS
FireHOL Team.


firehol-modifiers

title: firehol-modifiers(5)

summary: set up NAT and port redirections

text:
# firehol-modifiers(5)

## NAME
firehol-nat - set up NAT and port redirections

## SYNOPSIS
{ nat to-destination | dnat [to] } ipaddr[:port] [random] [persistent] [id id] [at chain] [rule-params]

{ nat to-source | snat [to] } ipaddr[:port] [random] [persistent] [id id] [at chain] [rule-params]

{ nat redirect-to | redirect [to] } port[-range] [random] [id id] [at chain] [rule-params]

## DESCRIPTION
Destination NAT is provided by nat to-destination and its synonym dnat.

Source NAT is provided by nat to-source and its synonym snat.

Redirection to a port on the local host is provided by nat redirect-to and its synonym redirect.

The port part of the new address is optional with SNAT and DNAT; if not specified it will not be changed.

When you apply NAT to a packet, the Linux kernel will track the changes it makes, so that when it sees replies the transformation will be applied in the opposite direction. For instance if you changed the destination port of a packet from 80 to 8080, when a reply comes back, its source is set as 80. This means the original sender is not aware a transformation is happening.

This means that NAT is only applied on the first packet of each connection (the nat FireHOL helper always appends state NEW to NAT statements).

The NAT helper can be used to setup load balancing. Check the section BALANCING below.

Note

The rule-params are used only to determine the traffic that will be matched for NAT in these commands, not to permit traffic to flow.

Applying NAT does not automatically create rules to allow the traffic to pass. You will still need to include client or server entries in an interface or router to allow the traffic.

When using dnat or redirect, the transformation is in the PREROUTING chain of the NAT table and happens before normal rules are matched, so your client or server rule should match the "modified" traffic.

When using snat, the transformation is in the POSTROUTING chain of the NAT table and happens after normal rules are matched, so your client or server rule should match the "unmodified" traffic.

See the netfilter flow diagram (http://upload.wikimedia.org/wikipedia/commons/3/37/Netfilter-packet-flow.svg) if you would like to see how network packets are processed by the kernel in detail.

The at keyword allows setting a different chain to attach the rules. For dnat and redirect the default is PREROUTING, but OUTPUT is also supported. For snat the default is POSTROUTING, but INPUT is also supported.

random will randomise the port mapping involved, to ensure the ports used are not predictable.

persistent is used when the statement is given alternatives (i.e. many destination servers for dnat, many source IPs for snat, many ports for redirect). It will attempt to keep each client on the same nat map. See below for more information about persistence.

The nat helper takes one of the following sub-commands:

to-destination ipaddr[:port]

Defines a Destination NAT (DNAT). Commonly thought of as port-forwarding (where packets destined for the firewall with a given port and protocol are sent to a different IP address and possibly port), DNAT is much more flexible in that any number of parameters can be matched before the destination information is rewritten.

ipaddr[:port] is the destination address to be set in packets matching rule-params.

If no rules are given, all forwarded traffic will be matched. outface should not be used in DNAT since the information is not available at the time the decision is made.

ipaddr[:port] accepts any --to-destination values that iptables(8) accepts. Run iptables -j DNAT --help for more information. Multiple ipaddr[:port] may be specified by separating with spaces and enclosing with quotes.

to-source ipaddr[:port]

Defines a Source NAT (SNAT). SNAT is similar to masquerading but is more efficient for static IP addresses. You can use it to give a public IP address to a host which does not have one behind the firewall. See also firehol-masquerade(5).

ipaddr[:port] is the source address to be set in packets matching rule-params.

If no rules are given, all forwarded traffic will be matched. inface should not be used in SNAT since the information is not available at the time the decision is made.

ipaddr[:port] accepts any --to-source values that iptables(8) accepts. Run iptables -j SNAT --help for more information. Multiple ipaddr[:port] may be specified by separating with spaces and enclosing with quotes.

redirect-to port[-range]

Redirect matching traffic to the local machine. This is typically useful if you want to intercept some traffic and process it on the local machine.

port[-range] is the port range (from-to) or single port that packets matching rule-params will be redirected to.

If no rules are given, all forwarded traffic will be matched. outface should not be used in REDIRECT since the information is not available at the time the decision is made.

## BALANCING
NAT can balance multiple servers (or IPs in case of snat) when a range is specified. This is handled by the kernel.

Example:

```
dnat4 to 10.0.0.1-10.0.0.10 persistent proto tcp dst 1.1.1.1 dport 80
```

In the above example, the Linux kernel will give a persistent server to all the sockets of any single client.

FireHOL can also setup balancing using a round-robin or weighted average distribution of requests. However persistent cannot be used (the Linux kernel applies persistence on a single NAT statement).

### Round Robin distribution
To enable round robin distribution, give multiple to values, space separated and enclosed in quotes, or comma separated.

Example:

```
 dnat4 to 10.0.0.1,10.0.0.2,10.0.0.3 proto tcp dst 1.1.1.1 port 80
 # or
 dnat4 to "10.0.0.1 10.0.0.2 10.0.0.3" proto tcp dst 1.1.1.1 port 80
```

Ports can also be given per IP:

```
 dnat4 to 10.0.0.1:70,10.0.0.2:80,10.0.0.3:90 proto tcp dst 1.1.1.1 port 80
 # or
 dnat4 to "10.0.0.1:70 10.0.0.2:80 10.0.0.3:90" proto tcp dst 1.1.1.1 port 80
```

### Weighted distribution
To enable weighted distribution, append a slash with the weight requested for each entry.

FireHOL adds all the weights given and calculates the percentage of traffic each entry should receive.

Example:

```
 dnat4 to 10.0.0.1/30,10.0.0.2/30,10.0.0.3/40 proto tcp dst 1.1.1.1 port 80
 # or
 dnat4 to "10.0.0.1/30 10.0.0.2/30 10.0.0.3/40" proto tcp dst 1.1.1.1 port 80
 # or
 dnat4 to 10.0.0.1:70/30,10.0.0.2:80/30,10.0.0.3:90/40 proto tcp dst 1.1.1.1 port 80
 # or
 dnat4 to "10.0.0.1:70/30 10.0.0.2:80/30 10.0.0.3:90/40" proto tcp dst 1.1.1.1 port 80
```

### PERSISTENCE
The kernel supports persistence only if the NAT alternatives are contiguous (i.e. dnat to A-B, snat to A-B, redirect to 1000:1010, etc). If they are contiguous, persistence is left at the kernel. FireHOL does nothing.

If the alternatives are not contiguous, FireHOL will use the recent iptables module to apply persistence itself.

FireHOL supports mixed mode persistence. For example, you can have something like this:

```
dnat to A-B/70,C-D/20,F/10 persistence id mybalancer
```

The above is a weighted distribution of persistence. Group A-B will get 70%, C-D 20% and server F 10%.

Using the above, FireHOL will apply its persistence to pick one of the groups A-B, or C-D, or F. Once the group has been picked by FireHOL, the kernel will apply persistence within the group, to pick the server that will handle the request.

The FireHOL persistence works like this:

1.

A packet is received that should be NATed

2.

A lookup is made using the recent module to find if it has been seen before. The source IP of packet is looked up.

3.

If it has been seen before, the connection is mapped the same way the last time was mapped. The recent module is updated too.

4.

If it has not been seen before, the connection is mapped using the distribution method specified. The recent module is updated too, to be ready for the next connection.

The recent module has a few limitations:

1.

It has lookup tables. We need one lookup table for each member of of the NAT. FireHOL uses the id parameter and the definition of each alternative in the NAT statement to form a name for the lookup table. These lookup tables are persistent to firewall restarts, this is why FireHOL requires from you to set an id.

2.

It can keep entries in its lookup tables for a given time. FireHOL sets this to 3600 seconds. You can control it by setting FIREHOL_NAT_PERSISTENCE_SECONDS.

3.

It has a limit on the number of entries in the lookup tables. FireHOL cannot set this. This is kernel module option. The default is 200 entries.

Check this:

~~~~ # modinfo xt_recent filename: /lib/modules/4.1.12-gentoo/kernel/net/netfilter/xt_recent.ko alias: ip6t_recent alias: ipt_recent license: GPL description: Xtables: "recently-seen" host matching author: Jan Engelhardt <jengelh@medozas.de> author: Patrick McHardy <kaber@trash.net> depends: x_tables intree: Y vermagic: 4.1.12-gentoo SMP preempt mod_unload modversions parm: ip_list_tot:number of IPs to remember per list (uint) parm: ip_list_hash_size:size of hash table used to look up IPs (uint) parm: ip_list_perms:permissions on /proc/net/xt_recent/* files (uint) parm: ip_list_uid:default owner of /proc/net/xt_recent/* files (uint) parm: ip_list_gid:default owning group of /proc/net/xt_recent/* files (uint) parm: ip_pkt_list_tot:number of packets per IP address to remember (max. 255) (uint) ~~~~

```
You have to consult your distribution documentation to set these.
You can find their current values by examining files found in
`/sys/module/xt_recent/parameters/` Unfortunately, these files
are not writable, so to change parameters you have unload and
reload the module (i.e. apply a firewall that does not use the
*recent* module, `rmmod xt_recent`, change the parameter,
re-apply a firewall that uses the *recent* module).
Normally, you will need a line in `/etc/modprobe.d/netfitler.conf`
like this:
~~~~
options xt_recent ip_list_tot=16384
~~~~
The number 16384 I used is the max number of unique client IPs
I expect to have per hour (`FIREHOL_NAT_PERSISTENCE_SECONDS`)
for this service.
`ip_list_hash_size` is calculated by kernel when the module
is loaded to be bigger and up to twice `ip_list_tot`.
```

Once you have the balancer running, you can find its lookup tables in /proc/net/xt_recent/. There you will find files starting with the id parameter, one file for every alternative of the NAT rule.

## EXAMPLES

```
 # Port forwarding HTTP
 dnat4 to 192.0.2.2 proto tcp dport 80
 # Port forwarding HTTPS on to a different port internally
 dnat4 to 192.0.2.2:4443 proto tcp dport 443
 # Fix source for traffic leaving the firewall via eth0 with private address
 snat4 to 198.51.100.1 outface eth0 src 192.168.0.0/24
 # Transparent squid (running on the firewall) for some hosts
 redirect4 to 8080 inface eth0 src 198.51.100.0/24 proto tcp dport 80
 # Send to 192.0.2.1
 #  - all traffic arriving at or passing through the firewall
 nat4 to-destination 192.0.2.1
 # Send to 192.0.2.1
 #  - all traffic arriving at or passing through the firewall
 #  - which WAS going to 203.0.113.1
 nat4 to-destination 192.0.2.1 dst 203.0.113.1
 # Send to 192.0.2.1
 #  - TCP traffic arriving at or passing through the firewall
 #  - which WAS going to 203.0.113.1
 nat4 to-destination 192.0.2.1 proto tcp dst 203.0.113.1
 # Send to 192.0.2.1
 #  - TCP traffic arriving at or passing through the firewall
 #  - which WAS going to 203.0.113.1, port 25
 nat4 to-destination 192.0.2.1 proto tcp dport 25 dst 203.0.113.1
```

## SEE ALSO
•

firehol(1) - FireHOL program

•

firehol.conf(5) - FireHOL configuration

•

firehol-interface(5) - interface definition

•

firehol-router(5) - router definition

•

firehol-params(5) - optional rule parameters

•

firehol-masquerade(5) - masquerade helper

•

FireHOL Website (http://firehol.org/)

•

FireHOL Online PDF Manual (http://firehol.org/firehol-manual.pdf)

•

FireHOL Online Documentation (http://firehol.org/documentation/)

•

NAT HOWTO (http://www.netfilter.org/documentation/HOWTO/NAT-HOWTO-6.html)

•

netfilter flow diagram (http://upload.wikimedia.org/wikipedia/commons/3/37/Netfilter-packet-flow.svg)

## AUTHORS
FireHOL Team.


firehol-nat

title: firehol-nat(5)

summary: set up NAT and port redirections

text:
# firehol-nat(5)

## NAME
firehol-nat - set up NAT and port redirections

## SYNOPSIS
{ nat to-destination | dnat [to] } ipaddr[:port] [random] [persistent] [id id] [at chain] [rule-params]

{ nat to-source | snat [to] } ipaddr[:port] [random] [persistent] [id id] [at chain] [rule-params]

{ nat redirect-to | redirect [to] } port[-range] [random] [id id] [at chain] [rule-params]

## DESCRIPTION
Destination NAT is provided by nat to-destination and its synonym dnat.

Source NAT is provided by nat to-source and its synonym snat.

Redirection to a port on the local host is provided by nat redirect-to and its synonym redirect.

The port part of the new address is optional with SNAT and DNAT; if not specified it will not be changed.

When you apply NAT to a packet, the Linux kernel will track the changes it makes, so that when it sees replies the transformation will be applied in the opposite direction. For instance if you changed the destination port of a packet from 80 to 8080, when a reply comes back, its source is set as 80. This means the original sender is not aware a transformation is happening.

This means that NAT is only applied on the first packet of each connection (the nat FireHOL helper always appends state NEW to NAT statements).

The NAT helper can be used to setup load balancing. Check the section BALANCING below.

Note

The rule-params are used only to determine the traffic that will be matched for NAT in these commands, not to permit traffic to flow.

Applying NAT does not automatically create rules to allow the traffic to pass. You will still need to include client or server entries in an interface or router to allow the traffic.

When using dnat or redirect, the transformation is in the PREROUTING chain of the NAT table and happens before normal rules are matched, so your client or server rule should match the "modified" traffic.

When using snat, the transformation is in the POSTROUTING chain of the NAT table and happens after normal rules are matched, so your client or server rule should match the "unmodified" traffic.

See the netfilter flow diagram (http://upload.wikimedia.org/wikipedia/commons/3/37/Netfilter-packet-flow.svg) if you would like to see how network packets are processed by the kernel in detail.

The at keyword allows setting a different chain to attach the rules. For dnat and redirect the default is PREROUTING, but OUTPUT is also supported. For snat the default is POSTROUTING, but INPUT is also supported.

random will randomise the port mapping involved, to ensure the ports used are not predictable.

persistent is used when the statement is given alternatives (i.e. many destination servers for dnat, many source IPs for snat, many ports for redirect). It will attempt to keep each client on the same nat map. See below for more information about persistence.

The nat helper takes one of the following sub-commands:

to-destination ipaddr[:port]

Defines a Destination NAT (DNAT). Commonly thought of as port-forwarding (where packets destined for the firewall with a given port and protocol are sent to a different IP address and possibly port), DNAT is much more flexible in that any number of parameters can be matched before the destination information is rewritten.

ipaddr[:port] is the destination address to be set in packets matching rule-params.

If no rules are given, all forwarded traffic will be matched. outface should not be used in DNAT since the information is not available at the time the decision is made.

ipaddr[:port] accepts any --to-destination values that iptables(8) accepts. Run iptables -j DNAT --help for more information. Multiple ipaddr[:port] may be specified by separating with spaces and enclosing with quotes.

to-source ipaddr[:port]

Defines a Source NAT (SNAT). SNAT is similar to masquerading but is more efficient for static IP addresses. You can use it to give a public IP address to a host which does not have one behind the firewall. See also firehol-masquerade(5).

ipaddr[:port] is the source address to be set in packets matching rule-params.

If no rules are given, all forwarded traffic will be matched. inface should not be used in SNAT since the information is not available at the time the decision is made.

ipaddr[:port] accepts any --to-source values that iptables(8) accepts. Run iptables -j SNAT --help for more information. Multiple ipaddr[:port] may be specified by separating with spaces and enclosing with quotes.

redirect-to port[-range]

Redirect matching traffic to the local machine. This is typically useful if you want to intercept some traffic and process it on the local machine.

port[-range] is the port range (from-to) or single port that packets matching rule-params will be redirected to.

If no rules are given, all forwarded traffic will be matched. outface should not be used in REDIRECT since the information is not available at the time the decision is made.

## BALANCING
NAT can balance multiple servers (or IPs in case of snat) when a range is specified. This is handled by the kernel.

Example:

```
dnat4 to 10.0.0.1-10.0.0.10 persistent proto tcp dst 1.1.1.1 dport 80
```

In the above example, the Linux kernel will give a persistent server to all the sockets of any single client.

FireHOL can also setup balancing using a round-robin or weighted average distribution of requests. However persistent cannot be used (the Linux kernel applies persistence on a single NAT statement).

### Round Robin distribution
To enable round robin distribution, give multiple to values, space separated and enclosed in quotes, or comma separated.

Example:

```
 dnat4 to 10.0.0.1,10.0.0.2,10.0.0.3 proto tcp dst 1.1.1.1 port 80
 # or
 dnat4 to "10.0.0.1 10.0.0.2 10.0.0.3" proto tcp dst 1.1.1.1 port 80
```

Ports can also be given per IP:

```
 dnat4 to 10.0.0.1:70,10.0.0.2:80,10.0.0.3:90 proto tcp dst 1.1.1.1 port 80
 # or
 dnat4 to "10.0.0.1:70 10.0.0.2:80 10.0.0.3:90" proto tcp dst 1.1.1.1 port 80
```

### Weighted distribution
To enable weighted distribution, append a slash with the weight requested for each entry.

FireHOL adds all the weights given and calculates the percentage of traffic each entry should receive.

Example:

```
 dnat4 to 10.0.0.1/30,10.0.0.2/30,10.0.0.3/40 proto tcp dst 1.1.1.1 port 80
 # or
 dnat4 to "10.0.0.1/30 10.0.0.2/30 10.0.0.3/40" proto tcp dst 1.1.1.1 port 80
 # or
 dnat4 to 10.0.0.1:70/30,10.0.0.2:80/30,10.0.0.3:90/40 proto tcp dst 1.1.1.1 port 80
 # or
 dnat4 to "10.0.0.1:70/30 10.0.0.2:80/30 10.0.0.3:90/40" proto tcp dst 1.1.1.1 port 80
```

### PERSISTENCE
The kernel supports persistence only if the NAT alternatives are contiguous (i.e. dnat to A-B, snat to A-B, redirect to 1000:1010, etc). If they are contiguous, persistence is left at the kernel. FireHOL does nothing.

If the alternatives are not contiguous, FireHOL will use the recent iptables module to apply persistence itself.

FireHOL supports mixed mode persistence. For example, you can have something like this:

```
dnat to A-B/70,C-D/20,F/10 persistence id mybalancer
```

The above is a weighted distribution of persistence. Group A-B will get 70%, C-D 20% and server F 10%.

Using the above, FireHOL will apply its persistence to pick one of the groups A-B, or C-D, or F. Once the group has been picked by FireHOL, the kernel will apply persistence within the group, to pick the server that will handle the request.

The FireHOL persistence works like this:

1.

A packet is received that should be NATed

2.

A lookup is made using the recent module to find if it has been seen before. The source IP of packet is looked up.

3.

If it has been seen before, the connection is mapped the same way the last time was mapped. The recent module is updated too.

4.

If it has not been seen before, the connection is mapped using the distribution method specified. The recent module is updated too, to be ready for the next connection.

The recent module has a few limitations:

1.

It has lookup tables. We need one lookup table for each member of of the NAT. FireHOL uses the id parameter and the definition of each alternative in the NAT statement to form a name for the lookup table. These lookup tables are persistent to firewall restarts, this is why FireHOL requires from you to set an id.

2.

It can keep entries in its lookup tables for a given time. FireHOL sets this to 3600 seconds. You can control it by setting FIREHOL_NAT_PERSISTENCE_SECONDS.

3.

It has a limit on the number of entries in the lookup tables. FireHOL cannot set this. This is kernel module option. The default is 200 entries.

Check this:

~~~~ # modinfo xt_recent filename: /lib/modules/4.1.12-gentoo/kernel/net/netfilter/xt_recent.ko alias: ip6t_recent alias: ipt_recent license: GPL description: Xtables: "recently-seen" host matching author: Jan Engelhardt <jengelh@medozas.de> author: Patrick McHardy <kaber@trash.net> depends: x_tables intree: Y vermagic: 4.1.12-gentoo SMP preempt mod_unload modversions parm: ip_list_tot:number of IPs to remember per list (uint) parm: ip_list_hash_size:size of hash table used to look up IPs (uint) parm: ip_list_perms:permissions on /proc/net/xt_recent/* files (uint) parm: ip_list_uid:default owner of /proc/net/xt_recent/* files (uint) parm: ip_list_gid:default owning group of /proc/net/xt_recent/* files (uint) parm: ip_pkt_list_tot:number of packets per IP address to remember (max. 255) (uint) ~~~~

```
You have to consult your distribution documentation to set these.
You can find their current values by examining files found in
`/sys/module/xt_recent/parameters/` Unfortunately, these files
are not writable, so to change parameters you have unload and
reload the module (i.e. apply a firewall that does not use the
*recent* module, `rmmod xt_recent`, change the parameter,
re-apply a firewall that uses the *recent* module).
Normally, you will need a line in `/etc/modprobe.d/netfitler.conf`
like this:
~~~~
options xt_recent ip_list_tot=16384
~~~~
The number 16384 I used is the max number of unique client IPs
I expect to have per hour (`FIREHOL_NAT_PERSISTENCE_SECONDS`)
for this service.
`ip_list_hash_size` is calculated by kernel when the module
is loaded to be bigger and up to twice `ip_list_tot`.
```

Once you have the balancer running, you can find its lookup tables in /proc/net/xt_recent/. There you will find files starting with the id parameter, one file for every alternative of the NAT rule.

## EXAMPLES

```
 # Port forwarding HTTP
 dnat4 to 192.0.2.2 proto tcp dport 80
 # Port forwarding HTTPS on to a different port internally
 dnat4 to 192.0.2.2:4443 proto tcp dport 443
 # Fix source for traffic leaving the firewall via eth0 with private address
 snat4 to 198.51.100.1 outface eth0 src 192.168.0.0/24
 # Transparent squid (running on the firewall) for some hosts
 redirect4 to 8080 inface eth0 src 198.51.100.0/24 proto tcp dport 80
 # Send to 192.0.2.1
 #  - all traffic arriving at or passing through the firewall
 nat4 to-destination 192.0.2.1
 # Send to 192.0.2.1
 #  - all traffic arriving at or passing through the firewall
 #  - which WAS going to 203.0.113.1
 nat4 to-destination 192.0.2.1 dst 203.0.113.1
 # Send to 192.0.2.1
 #  - TCP traffic arriving at or passing through the firewall
 #  - which WAS going to 203.0.113.1
 nat4 to-destination 192.0.2.1 proto tcp dst 203.0.113.1
 # Send to 192.0.2.1
 #  - TCP traffic arriving at or passing through the firewall
 #  - which WAS going to 203.0.113.1, port 25
 nat4 to-destination 192.0.2.1 proto tcp dport 25 dst 203.0.113.1
```

## SEE ALSO
•

firehol(1) - FireHOL program

•

firehol.conf(5) - FireHOL configuration

•

firehol-interface(5) - interface definition

•

firehol-router(5) - router definition

•

firehol-params(5) - optional rule parameters

•

firehol-masquerade(5) - masquerade helper

•

FireHOL Website (http://firehol.org/)

•

FireHOL Online PDF Manual (http://firehol.org/firehol-manual.pdf)

•

FireHOL Online Documentation (http://firehol.org/documentation/)

•

NAT HOWTO (http://www.netfilter.org/documentation/HOWTO/NAT-HOWTO-6.html)

•

netfilter flow diagram (http://upload.wikimedia.org/wikipedia/commons/3/37/Netfilter-packet-flow.svg)

## AUTHORS
FireHOL Team.


firehol-params

title: firehol-params(5)

summary: optional rule parameters

text:
# firehol-params(5)

## NAME
firehol-params - optional rule parameters

## SYNOPSIS
Common

{ src | src4 | src6 } [not] host

{ dst | dst4 | dst6 } [not] host

srctype [not] type

dsttype [not] type

proto [not] protocol

mac [not] macaddr

dscp [not] value class classid

mark [not] id

connmark [not] id

custommark [not] name id

rawmark [not] id

tos [not] id

custom "iptables-options..."

custom-in "iptables-options..."

custom-out "iptables-options..."

Router Only

inface [not] interface

outface [not] interface

physin [not] interface

physout [not] interface

Interface Only

uid [not] user

gid [not] group

Logging

connlog "log text"

log "log text" [level loglevel]

loglimit "log text" [level loglevel]

Helpers Only

sport port

dport port

state state

ipset [not] name flags [no-counters] [bytes-lt|bytes-eq|bytes-gt|bytes-not-eq number] [packets-lt|packets-eq|packets-gt|packets-not-eq number] [options custom-ipset-options]

limit limit burst

connlimit upto|above limit [mask mask] [saddr|daddr]

hashlimit name upto|above amount/period [burst amount] [mode {srcip|srcport|dstip|dstport},...] [srcmask prefix] [dstmask prefix] [htable-size buckets] [htable-max entries] [htable-expire msec] [htable-gcinterval msec]

## DESCRIPTION
Optional rule parameters are accepted by many commands to narrow the match they make. Not all parameters are accepted by all commands so you should check the individual commands for exclusions.

All matches are made against the REQUEST. FireHOL automatically sets up the necessary stateful rules to deal with replies in the reverse direction.

All matches should be true for a statement to be executed. However, many matches support multiple values. In this case, at least one of the values must match.

Example:

```
server smtp accept src 1.1.1.1 dst 2.2.2.2
```

In the above example all smtp requests coming in from 1.1.1.1 and going out to smtp server 2.2.2.2 will be matched.

```
server smtp accept src 1.1.1.1 dst 2.2.2.2,3.3.3.3
```

In the above example all smtp requests coming in from 1.1.1.1 and going out to either smtp server 2.2.2.2 or 3.3.3.3 will be matched.

Use the keyword not to match any value other than the one(s) specified.

The logging parameters are unusual in that they do not affect the match, they just cause a log message to be emitted. Therefore, the logging parameters don't support the not option.

FireHOL is designed so that if you specify a parameter that is also used internally by the command then a warning will be issued (and the internal version will be used).

## COMMON

### src, dst
Use src and dst to define the source and destination IP addresses of the request respectively. host defines the IP or IPs to be matched.

host can also refer to an ipset, using this syntax: ipset:NAME, where NAME is the name of the ipset. The ipset has to be of type hash:ip for this match to work. The source IP or the destination IP will be used for the match, depending if the ipset is given as src or dst.

IPs and ipsets can be mixed together, like this: src 1.1.1.1,ipset:NAME1,2.2.2.2,ipset:NAME2

Examples:

```
server4 smtp accept src not 192.0.2.1
server4 smtp accept dst 198.51.100.1
server4 smtp accept src not 192.0.2.1 dst 198.51.100.1
server6 smtp accept src not 2001:DB8:1::/64
server6 smtp accept dst 2001:DB8:2::/64
server6 smtp accept src not 2001:DB8:1::/64 dst 2001:DB8:2::/64
```

When attempting to create rules for both IPv4 and IPv6 it is generally easier to use the src4, src6, dst4 and dst6 pairs:

```
server46 smtp accept src4 192.0.2.1 src6 2001:DB8:1::/64
server46 smtp accept dst4 198.51.100.1 dst6 2001:DB8:2::/64
server46 smtp accept dst4 $d4 dst6 $d6 src4 not $d4 src6 not $s6
```

To keep the rules sane, if one of the 4/6 pair specifies not, then so must the other. If you do not want to use both IPv4 and IPv6 addresses, you must specify the rule as IPv4 or IPv6 only. It is always possible to write a second IPv4 or IPv6 only rule.

### srctype, dsttype
Use srctype or dsttype to define the source or destination IP address type of the request. type is the address type category as used in the kernel's network stack. It can be one of:

UNSPEC

an unspecified address (i.e. 0.0.0.0)

UNICAST

a unicast address

LOCAL

a local address

BROADCAST

a broadcast address

ANYCAST

an anycast address

MULTICAST

a multicast address

BLACKHOLE

a blackhole address

UNREACHABLE

an unreachable address

PROHIBIT

a prohibited address

THROW; NAT; XRESOLVE

undocumented

See iptables(8) or run iptables -m addrtype --help for more information. Examples:

```
server smtp accept srctype not "UNREACHABLE PROHIBIT"

```

### proto
Use proto to match by protocol. The protocol can be any accepted by iptables(8).

### mac
Use mac to match by MAC address. The macaddr matches to the "remote" host. In an interface, "remote" always means the non-local host. In a router, "remote" refers to the source of requests for servers. It refers to the destination of requests for clients. Examples:

```
 # Only allow pop3 requests to the e6 host
 client pop3 accept mac 00:01:01:00:00:e6
 # Only allow hosts other than e7/e8 to access smtp
 server smtp accept mac not "00:01:01:00:00:e7 00:01:01:00:00:e8"
```

### dscp
Use dscp to match the DSCP field on packets. For details on DSCP values and classids, see firehol-dscp(5).

```
 server smtp accept dscp not "0x20 0x30"
 server smtp accept dscp not class "BE EF"
```

### mark
Use mark to match marks set on packets. For details on mark ids, see firehol-mark(5).

```
server smtp accept mark not "20 55"

```

### tos
Use tos to match the TOS field on packets. For details on TOS ids, see firehol-tos(5).

```
server smtp accept tos not "Maximize-Throughput 0x10"

```

### custom
Use custom to pass arguments directly to iptables(8). All of the parameters must be in a single quoted string. To pass an option to iptables(8) that itself contains a space you need to quote strings in the usual bash(1) manner. For example:

```
server smtp accept custom "--some-option some-value"
server smtp accept custom "--some-option 'some-value second-value'"
```

## ROUTER ONLY

### inface, outface
Use inface and outface to define the interface via which a request is received and forwarded respectively. Use the same format as firehol-interface(5). Examples:

```
server smtp accept inface not eth0
server smtp accept inface not "eth0 eth1"
server smtp accept inface eth0 outface eth1
```

### physin, physout
Use physin and physout to define the physical interface via which a request is received or send in cases where the inface or outface is known to be a virtual interface; e.g. a bridge. Use the same format as firehol-interface(5). Examples:

```
server smtp accept physin not eth0

```

## INTERFACE ONLY
These parameters match information related to information gathered from the local host. They apply only to outgoing packets and are silently ignored for incoming requests and requests that will be forwarded.

Note

The Linux kernel infrastructure to match PID/SID and executable names with pid, sid and cmd has been removed so these options can no longer be used.

### uid
Use uid to match the operating system user sending the traffic. The user is a username, uid number or a quoted list of the two.

For example, to limit which users can access POP3 and IMAP by preventing replies for certain users from being sent:

```
client "pop3 imap" accept user not "user1 user2 user3"

```

Similarly, this will allow all requests to reach the server but prevent replies unless the web server is running as apache:

```
server http accept user apache

```

### gid
Use gid to match the operating system group sending the traffic. The group is a group name, gid number or a quoted list of the two.

## LOGGING

### connlog
Use connlog to log only the first packet of a connection.

### log, loglimit
Use log or loglimit to log matching packets to syslog. Unlike iptables(8) logging, this is not an action: FireHOL will produce multiple iptables(8) commands to accomplish both the action for the rule and the logging.

Logging is controlled using the FIREHOL_LOG_OPTIONS and FIREHOL_LOG_LEVEL environment variables - see firehol-defaults.conf(5). loglimit additionally honours the FIREHOL_LOG_FREQUENCY and FIREHOL_LOG_BURST variables.

Specifying level (which takes the same values as FIREHOL_LOG_LEVEL) allows you to override the log level for a single rule.

## HELPERS ONLY PARAMETERS

### dport, sport
FireHOL also provides dport, sport and limit which are used internally and rarely needed within configuration files.

dport and sport require an argument port which can be a name, number, range (FROM:TO) or a quoted list of ports.

For dport port specifies the destination port of a request and can be useful when matching traffic to helper commands (such as nat) where there is no implicit port.

For sport port specifies the source port of a request and can be useful when matching traffic to helper commands (such as nat) where there is no implicit port.

### limit
limit requires the arguments frequency and burst and will limit the matching of traffic in both directions.

### connlimit
connlimit matches on the number of connections per IP. It has been added to FireHOL since v3.

saddr matches on source IP. daddr matches on destination IP. mask groups IPs with the mask given upto matches when the number of connections is up to the given limit above matches when the number of connections above to the given limit

The number of connections counted are system wide, not service specific. For example for saddr, you cannot connlimit 2 connections for SSH and 4 for SMTP. If you connlimit 2 connections for SSH, then the first 2 connections of a client can be SSH. If a client has already 2 connections to another service, the client will not be able to connect to SSH.

So, connlimit can safely be used:

•

with daddr to limit the connections a server can accept

•

with saddr to limit the total connections per client to all services.

### hashlimit
hashlimit has been added to FireHOL since v3.

hashlimit hashlimit uses hash buckets to express a rate limiting match (like the limit match) for a group of connections using a single iptables rule. Grouping can be done per-hostgroup (source and/or destination address) and/or per-port. It gives you the ability to express "N packets per time quantum per group" or "N bytes per seconds" (see below for some examples).

A hash limit type (upto, above) and name are required.

name The name for the /proc/net/ipt_hashlimit/name entry.

upto amount[/second|/minute|/hour|/day] Match if the rate is below or equal to amount/quantum. It is specified either as a number, with an optional time quantum suffix (the default is 3/hour), or as amountb/second (number of bytes per second).

above amount[/second|/minute|/hour|/day] Match if the rate is above amount/quantum.

burst amount Maximum initial number of packets to match: this number gets recharged by one every time the limit specified above is not reached, up to this number; the default is 5. When byte-based rate matching is requested, this option specifies the amount of bytes that can exceed the given rate. This option should be used with caution - if the entry expires, the burst value is reset too.

mode {srcip|srcport|dstip|dstport},... A comma-separated list of objects to take into consideration. If no mode option is given, srcip,dstport is assumed.

srcmask prefix When --hashlimit-mode srcip is used, all source addresses encountered will be grouped according to the given prefix length and the so-created subnet will be subject to hashlimit. prefix must be between (inclusive) 0 and 32. Note that srcmask 0 is basically doing the same thing as not specifying srcip for mode, but is technically more expensive.

dstmask prefix Like srcmask, but for destination addresses.

htable-size buckets The number of buckets of the hash table

htable-max entries Maximum entries in the hash.

htable-expire msec After how many milliseconds do hash entries expire.

htable-gcinterval msec How many milliseconds between garbage collection intervals.

Examples:

matching on source host: "1000 packets per second for every host in 192.168.0.0/16"

```
src 192.168.0.0/16 hashlimit mylimit mode srcip upto 1000/sec
```

matching on source port: "100 packets per second for every service of 192.168.1.1"

```
src 192.168.1.1 hashlimit mylimit mode srcport upto 100/sec
```

matching on subnet: "10000 packets per minute for every /28 subnet (groups of 8 addresses) in 10.0.0.0/8"

```
src 10.0.0.8 hashlimit mylimit mask 28 upto 10000/min
```

matching bytes per second: "flows exceeding 512kbyte/s"

```
hashlimit mylimit mode srcip,dstip,srcport,dstport above 512kb/s
```

matching bytes per second: "hosts that exceed 512kbyte/s, but permit up to 1Megabytes without matching"

```
hashlimit mylimit mode dstip above 512kb/s burst 1mb
```

## SEE ALSO
•

firehol(1) - FireHOL program

•

firehol.conf(5) - FireHOL configuration

•

firehol-server(5) - server, route commands

•

firehol-client(5) - client command

•

firehol-interface(5) - interface definition

•

firehol-router(5) - router definition

•

firehol-mark(5) - mark config helper

•

firehol-tos(5) - tos config helper

•

firehol-dscp(5) - dscp config helper

•

firehol-defaults.conf(5) - control variables

•

iptables(8) (http://ipset.netfilter.org/iptables.man.html) - administration tool for IPv4 firewalls

•

ip6tables(8) (http://ipset.netfilter.org/ip6tables.man.html) - administration tool for IPv6 firewalls

•

FireHOL Website (http://firehol.org/)

•

FireHOL Online PDF Manual (http://firehol.org/firehol-manual.pdf)

•

FireHOL Online Documentation (http://firehol.org/documentation/)

## AUTHORS
FireHOL Team.


firehol-policy

title: firehol-policy(5)

text:
# firehol-policy(5)

## NAME
firehol-policy - set default action for an interface or router

## SYNOPSIS
policy action

## DESCRIPTION
The policy subcommand defines the default policy for an interface or router.

The action can be any of the actions listed in firehol-actions(5).

Note

Change the default policy of a router only if you understand clearly what will be matched by the router statement whose policy is being changed.

It is common to define overlapping router definitions. Changing the policy to anything other than the default return may cause strange results for your configuration.

Warning

Do not set a policy to accept unless you fully trust all hosts that can reach the interface. FireHOL CANNOT be used to create valid "accept by default" firewalls.

## EXAMPLE

```
interface eth0 intranet src 192.0.2.0/24
  # I trust this interface absolutely
  policy accept
```

## SEE ALSO
•

firehol(1) - FireHOL program

•

firehol.conf(5) - FireHOL configuration

•

firehol-interface(5) - interface definition

•

firehol-router(5) - router definition

•

FireHOL Website (http://firehol.org/)

•

FireHOL Online PDF Manual (http://firehol.org/firehol-manual.pdf)

•

FireHOL Online Documentation (http://firehol.org/documentation/)

## AUTHORS
FireHOL Team.


firehol-protection

title: firehol-protection(5)

summary: add extra protections to a definition

text:
# firehol-protection(5)

## NAME
firehol-protection - add extra protections to a definition

## SYNOPSIS
protection [reverse] strong [requests/period [burst]]

protection [reverse] flood-protection-type [requests/period [burst]]

protection [reverse] { bad-packets | packet-protection-type }

protection [reverse] connlimit connections [mask prefix]

protection [reverse] connrate rate [burst amount] [srcmask prefix] [htable-size buckets] [htable-max entries] [htable-expire msec] [htable-gcinterval msec]

## DESCRIPTION
The protection subcommand sets protection rules on an interface or router.

Flood protections honour the values requests/period and burst. They are used to limit the rate of certain types of traffic.

The default rate FireHOL uses is 100 operations per second with a burst of 50. Run iptables -m limit --help for more information.

The protection type strong will switch on all protections (both packet and flood protections) except all-floods. It has aliases full and all.

The protection type bad-packets will switch on all packet protections but not flood protections.

You can specify multiple protection types by using multiple protection commands or by using a single command and enclosing the types in quotes.

Note

On a router, protections are normally set up on inface.

The reverse option will set up the protections on outface. You must use it as the first keyword.

## PACKET PROTECTION TYPES
bad-packets:

Drops all the bad packets detected by these rules.

invalid

Drops all incoming invalid packets, as detected INVALID by the connection tracker.

See also FIREHOL_DROP_INVALID in firehol-defaults.conf(5) which allows setting this function globally.

fragments

Drops all packet fragments.

This rule will probably never match anything since iptables(8) reconstructs all packets automatically before the firewall rules are processed whenever connection tracking is running.

new-tcp-w/o-syn

Drops all TCP packets that initiate a socket but have not got the SYN flag set.

malformed-xmas

Drops all TCP packets that have all TCP flags set.

malformed-null

Drops all TCP packets that have all TCP flags unset.

malformed-bad

Drops all TCP packets that have illegal combinations of TCP flags set.

### EXAMPLES

```
protection bad-packets
```

## FLOOD PROTECTION TYPES
icmp-floods [requests/period [burst]]

Allows only a certain amount of ICMP echo requests.

syn-floods [requests/period [burst]]

Allows only a certain amount of new TCP connections.

Be careful to not set the rate too low as the rule is applied to all connections regardless of their final result (rejected, dropped, established, etc).

all-floods [requests/period [burst]]

Allows only a certain amount of new connections.

Be careful to not set the rate too low as the rule is applied to all connections regardless of their final result (rejected, dropped, established, etc).

### EXAMPLES

```
protection all-floods 90/sec 40
```

## CLIENT LIMITING TYPES
These protections were added in v3.

These protections are used to limit the connections client make, per interface or router.

They support appending optional rule parameters to limit their scope to certain clients only.

protection [reverse] connlimit connections [mask prefix]

Allow only a number of connections per client (implemented with connlimit with fixed type=saddr).

protection [reverse] connrate rate [burst amount] [srcmask prefix] [htable-size buckets] [htable-max entries] [htable-expire msec] [htable-gcinterval msec]

Allow up to a rate of new connections per client (implemented with hashlimit with fixed type=upto and mode=srcip).

### EXAMPLES
Limit the number of concurrent connections to 10 per client

```
protection connlimit 10 mask 32
```

Limit the number of concurrent connections to 100 per client class-C and also limit it to 5 for 1.2.3.4

```
protection connlimit 100 mask 24
protection connlimit 5 src 1.2.3.4
```

In the last example above, if you want to give client 1.2.3.4 more connections than all others, you should exclude it from the first connlimit statement, like this:

```
protection connlimit 100 mask 24 src not 1.2.3.4
protection connlimit 200 src 1.2.3.4
```

Limit all clients to 10 concurrect connections and 60 connections/minute

```
protection connlimit 10
protection connrate 60/minute
```

## KNOWN ISSUES
When using multiple types in a single command, if the quotes are forgotten, incorrect rules will be generated without warning.

When using multiple types in a single command, FireHOL will silently ignore any types that come after a group type (bad-packets, strong and its aliases). Only use group types on their own line.

## SEE ALSO
•

firehol(1) - FireHOL program

•

firehol.conf(5) - FireHOL configuration

•

firehol-interface(5) - interface definition

•

firehol-router(5) - router definition

•

FireHOL Website (http://firehol.org/)

•

FireHOL Online PDF Manual (http://firehol.org/firehol-manual.pdf)

•

FireHOL Online Documentation (http://firehol.org/documentation/)

## AUTHORS
FireHOL Team.


firehol-proxy

title: firehol-proxy(5)

summary: create a router definition

text:
# firehol-proxy(5)

## NAME
firehol-router - create a router definition

## SYNOPSIS
{ router | router46 } name rule-params

router4 name rule-params

router6 name rule-params

## DESCRIPTION
A router definition consists of a set of rules for traffic passing through the host running the firewall.

The default policy for router definitions is RETURN, meaning packets are not dropped by any particular router. Packets not matched by any router are dropped at the end of the firewall.

The behaviour of the defined router is controlled by adding subcommands from those listed in ROUTER SUBCOMMANDS.

Note

Writing router4 is equivalent to writing ipv4 router and ensures the defined router is created only in the IPv4 firewall along with any rules within it.

Writing router6 is equivalent to writing ipv6 router and ensures the defined router is created only in the IPv6 firewall along with any rules within it.

Writing router46 is equivalent to writing both router and ensures the defined router is created in both the IPv4 and IPv6 firewalls. Any rules within it will also be applied to both, unless they specify otherwise.

## PARAMETERS
name

This is a name for this router. You should use short names (10 characters maximum) without spaces or other symbols.

A name should be unique for all FireHOL interface and router definitions.

rule-params

The set of rule parameters to further restrict the traffic that is matched to this router.

See firehol-params(5) for information on the parameters that can be used. Some examples:

```
router mylan inface ppp+ outface eth0 src not ${UNROUTABLE_IPS}
router myrouter
```

See firehol.conf(5) for an explanation of ${UNROUTABLE_IPS}.

## WORKING WITH ROUTERS
Routers create stateful iptables(8) rules which match traffic in both directions.

To match some client or server traffic, the input/output interface or source/destination of the request must be specified. All inface/outface and src/dst firehol-params(5) can be given on the router statement (in which case they will be applied to all subcommands for the router) or just within the subcommands of the router.

For example, to define a router which matches requests from any PPP interface and destined for eth0, and on this allowing HTTP servers (on eth0) to be accessed by clients (from PPP) and SMTP clients (from eth0) to access any servers (on PPP):

```
router mylan inface ppp+ outface eth0
  server http accept
  client smtp accept
```

Note

The client subcommand reverses any optional rule parameters passed to the router, in this case the inface and outface.

Equivalently, to define a router which matches all forwarded traffic and within the the router allow HTTP servers on eth0 to be accessible to PPP and any SMTP servers on PPP to be accessible from eth0:

```
router mylan
  server http accept inface ppp+ outface eth0
  server smtp accept inface eth0 outface ppp
```

Note

In this instance two server subcommands are used since there are no parameters on the router to reverse. Avoid the use of the client subcommand in routers unless the inputs and outputs are defined as part of the router.

Any number of routers can be defined and the traffic they match can overlap. Since the default policy is RETURN, any traffic that is not matched by any rules in one will proceed to the next, in order, until none are left.

## SEE ALSO
•

firehol(1) - FireHOL program

•

firehol.conf(5) - FireHOL configuration

•

firehol-params(5) - optional rule parameters

•

firehol-modifiers(5) - ipv4/ipv6 selection

•

firehol-interface(5) - interface definition

•

firehol-iptables(5) - iptables helper

•

firehol-masquerade(5) - masquerade helper

•

FireHOL Website (http://firehol.org/)

•

FireHOL Online PDF Manual (http://firehol.org/firehol-manual.pdf)

•

FireHOL Online Documentation (http://firehol.org/documentation/)

### Router Subcommands
•

firehol-policy(5) - policy command

•

firehol-protection(5) - protection command

•

firehol-server(5) - server, route commands

•

firehol-client(5) - client command

•

firehol-group(5) - group command

•

firehol-tcpmss(5) - tcpmss helper

## AUTHORS
FireHOL Team.


firehol-router

title: firehol-router(5)

summary: create a router definition

text:
# firehol-router(5)

## NAME
firehol-router - create a router definition

## SYNOPSIS
{ router | router46 } name rule-params

router4 name rule-params

router6 name rule-params

## DESCRIPTION
A router definition consists of a set of rules for traffic passing through the host running the firewall.

The default policy for router definitions is RETURN, meaning packets are not dropped by any particular router. Packets not matched by any router are dropped at the end of the firewall.

The behaviour of the defined router is controlled by adding subcommands from those listed in ROUTER SUBCOMMANDS.

Note

Writing router4 is equivalent to writing ipv4 router and ensures the defined router is created only in the IPv4 firewall along with any rules within it.

Writing router6 is equivalent to writing ipv6 router and ensures the defined router is created only in the IPv6 firewall along with any rules within it.

Writing router46 is equivalent to writing both router and ensures the defined router is created in both the IPv4 and IPv6 firewalls. Any rules within it will also be applied to both, unless they specify otherwise.

## PARAMETERS
name

This is a name for this router. You should use short names (10 characters maximum) without spaces or other symbols.

A name should be unique for all FireHOL interface and router definitions.

rule-params

The set of rule parameters to further restrict the traffic that is matched to this router.

See firehol-params(5) for information on the parameters that can be used. Some examples:

```
router mylan inface ppp+ outface eth0 src not ${UNROUTABLE_IPS}
router myrouter
```

See firehol.conf(5) for an explanation of ${UNROUTABLE_IPS}.

## WORKING WITH ROUTERS
Routers create stateful iptables(8) rules which match traffic in both directions.

To match some client or server traffic, the input/output interface or source/destination of the request must be specified. All inface/outface and src/dst firehol-params(5) can be given on the router statement (in which case they will be applied to all subcommands for the router) or just within the subcommands of the router.

For example, to define a router which matches requests from any PPP interface and destined for eth0, and on this allowing HTTP servers (on eth0) to be accessed by clients (from PPP) and SMTP clients (from eth0) to access any servers (on PPP):

```
router mylan inface ppp+ outface eth0
  server http accept
  client smtp accept
```

Note

The client subcommand reverses any optional rule parameters passed to the router, in this case the inface and outface.

Equivalently, to define a router which matches all forwarded traffic and within the the router allow HTTP servers on eth0 to be accessible to PPP and any SMTP servers on PPP to be accessible from eth0:

```
router mylan
  server http accept inface ppp+ outface eth0
  server smtp accept inface eth0 outface ppp
```

Note

In this instance two server subcommands are used since there are no parameters on the router to reverse. Avoid the use of the client subcommand in routers unless the inputs and outputs are defined as part of the router.

Any number of routers can be defined and the traffic they match can overlap. Since the default policy is RETURN, any traffic that is not matched by any rules in one will proceed to the next, in order, until none are left.

## SEE ALSO
•

firehol(1) - FireHOL program

•

firehol.conf(5) - FireHOL configuration

•

firehol-params(5) - optional rule parameters

•

firehol-modifiers(5) - ipv4/ipv6 selection

•

firehol-interface(5) - interface definition

•

firehol-iptables(5) - iptables helper

•

firehol-masquerade(5) - masquerade helper

•

FireHOL Website (http://firehol.org/)

•

FireHOL Online PDF Manual (http://firehol.org/firehol-manual.pdf)

•

FireHOL Online Documentation (http://firehol.org/documentation/)

### Router Subcommands
•

firehol-policy(5) - policy command

•

firehol-protection(5) - protection command

•

firehol-server(5) - server, route commands

•

firehol-client(5) - client command

•

firehol-group(5) - group command

•

firehol-tcpmss(5) - tcpmss helper

## AUTHORS
FireHOL Team.


firehol-server

title: firehol-server(5)

text:
# firehol-server(5)

## NAME
firehol-server - server, route commands: accept requests to a service

## SYNOPSIS
{ server | server46 } service action rule-params

server4 service action rule-params

server6 service action rule-params

{ route | route46 } service action rule-params

route4 service action rule-params

route6 service action rule-params

## DESCRIPTION
The server subcommand defines a server of a service on an interface or router. Any rule-params given to a parent interface or router are inherited by the server.

For FireHOL a server is the destination of a request. Even though this is more complex for some multi-socket services, to FireHOL a server always accepts requests.

The route subcommand is an alias for server which may only be used in routers.

The service parameter is one of the supported service names from firehol-services(5). Multiple services may be specified, space delimited in quotes.

The action can be any of the actions listed in firehol-actions(5).

The rule-params define a set of rule parameters to further restrict the traffic that is matched to this service. See firehol-params(5) for more details.

Note

Writing server4 is equivalent to writing ipv4 server and ensures this subcommand is applied only in the IPv4 firewall rules.

Writing server6 is equivalent to writing ipv6 server and ensures this subcommand is applied only in the IPv6 firewall rules.

Writing server46 is equivalent to writing both server and ensures this subcommand is applied in both the IPv4 and IPv6 firewall rules; it cannot be used as part an interface or router that is IPv4 or IPv6 only.

The default server inherits its behaviour from the enclosing interface or router.

The same rules apply to the variations of route.

## EXAMPLES

```
server smtp accept
server "smtp pop3" accept
server smtp accept src 192.0.2.1
server smtp accept log "mail packet" src 192.0.2.1
```

## SEE ALSO
•

firehol(1) - FireHOL program

•

firehol.conf(5) - FireHOL configuration

•

firehol-modifiers(5) - ipv4/ipv6 selection

•

firehol-services(5) - services list

•

firehol-actions(5) - actions for rules

•

firehol-params(5) - optional rule parameters

•

firehol-client(5) - client subcommand

•

firehol-interface(5) - interface definition

•

firehol-router(5) - router definition

•

FireHOL Website (http://firehol.org/)

•

FireHOL Online PDF Manual (http://firehol.org/firehol-manual.pdf)

•

FireHOL Online Documentation (http://firehol.org/documentation/)

## AUTHORS
FireHOL Team.


firehol-services

title: firehol-services(5)

summary: configure synproxy

text:
# firehol-services(5)

## NAME
firehol-synproxy - configure synproxy

## SYNOPSIS
synproxy type rules-to-match-request action [action options]

## DESCRIPTION
•

type defines where the SYNPROXY will be attached. It can be input (or in), forward (or pass):

•

use input (or in) when the IP of the real server is an IP assigned to a physical interface of the machine (i.e. the IP is at the firewall itself)

•

use forward (or pass) when the IP of the real server is routed by the machine (i.e. SYNPROXY should look at the FORWARD chain for this traffic).

•

rules to match request are FireHOL optional rule parameters and should match the original client REQUEST, before any destination NAT. inface and dst are required:

•

inface is one or more interfaces the REQUEST should be received from

•

dst is the IP of the real server, as seen by the client (before any destination NAT)

•

action defines how SYNPROXY will reach the real server and can be:

•

accept to just allow the REQUEST reach the real server without any destination NAT

•

dnat to IP:PORT or dnat to IP1-IP2:PORT1-PORT2 or dnat to IP or dnat to :PORT to have SYNPROXY reach a server on another machine in a DMZ (different IP and/or PORT compared to the original request). The synproxy statement supports everything supported by the dnat helper (see firehol-nat(5)).

•

redirect to PORT to divert the request to a port on the firewall itself. The synproxy statement supports everything supported by the redirect helper (see firehol-nat(5)).

•

action CUSTOM_ACTION to have any other FireHOL action performed on the NEW socket. Use the action helper to define custom actions (see [firehol-action(5)][]).

•

action options are everything supported by FireHOL optional rule parameters that should be applied only on the final action of SYN packet from SYNPROXY to the real server. For example this can be used to append loglimit "TEXT" to have something logged by iptables, or limit the concurrent sockets with connlimit. Generally, everything you can write on the same line after server http accept is also accepted here.

## BACKGROUND
SYNPROXY is a TCP SYN packets proxy. It can be used to protect any TCP server (like a web server) from SYN floods and similar DDos attacks.

SYNPROXY is a netfilter module, in the Linux kernel. It is optimized to handle millions of packets per second utilizing all CPUs available without any concurrency locking between the connections.

The net effect of this, is that the real servers will not notice any change during the attack. The valid TCP connections will pass through and served, while the attack will be stopped at the firewall.

For more information on why you should use a SYNPROXY, check these articles:

•

http://rhelblog.redhat.com/2014/04/11/mitigate-tcp-syn-flood-attacks-with-red-hat-enterprise-linux-7-beta/

•

https://r00t-services.net/knowledgebase/14/Homemade-DDoS-Protection-Using-IPTables-SYNPROXY.html

SYNPROXY is included in the Linux kernels since version 3.12.

## HOW IT WORKS
•

When a SYNPROXY is used, clients transparently get connected to the SYNPROXY. So the 3-way TCP handshake happens first between the client and the SYNPROXY:

•

Clients send TCP SYN to server A

•

At the firewall, when this packet arrives it is marked as UNTRACKED

•

The UNTRACKED TCP SYN packet is then given to SYNPROXY

•

SYNPROXY gets this and responds (as server A) with TCP SYN+ACK (UNTRACKED)

•

Client responds with TCP ACK (marked as INVALID or UNTRACKED in iptables) which is also given to SYNPROXY

•

Once a client has been connected to the SYNPROXY, SYNPROXY automatically initiates a 3-way TCP handshake with the real server, spoofing the SYN packet so that the real server will see that the original client is attempting to connect:

•

SYNPROXY sends TCP SYN to real server A. This is a NEW connection in iptables and happens on the OUTPUT chain. The source IP of the packet is the IP of the client

•

The real server A responds with SYN+ACK to the client

•

SYNPROXY receives this and responds back to the server with ACK. The connection is now marked as ESTABLISHED

•

Once the connection has been established, SYNPROXY leaves the traffic flow between the client and the server

So, SYNPROXY can be used for any kind of TCP traffic. It can be used for both unencrypted and encrypted traffic, since it does not interfere with the content itself.

## USE CASES
In FireHOL SYNPROXY support is implemented as a helper. The synproxy command can be used to set up any number of SYNPROXYs.

FireHOL can set up SYNPROXY for any of these cases:

1.

real server on the firewall itself, on the same port (e.g. SYNPROXY on port 80, real server on port 80 too).

2.

real server on the firewall itself, on a different port (e.g. SYNPROXY on port 2200, real server on port 22).

3.

real server on a different machine, without NAT (e.g. SYNPROXY on a router catching traffic towards IP A, port 80 and real server is at IP A port 80 too).

4.

real server on a different machine, with NAT (e.g. SYNPROXY on a router catching traffic towards IP A, port 80 and real server is at IP 10.1.1.1 port 90).

5.

screening incoming traffic that should never be sent to a real server so that traps and dynamic blacklists can be created using traffic that has been screened by SYNPROXY (eliminate "internet noise" and spoofed packets).

So, generally, all cases are covered.

## DESIGN
The general guidelines for using synproxy in FireHOL, are:

1.

Design your firewall as you would normally do without SYNPROXY

2.

Test that it works without SYNPROXY. Test especially the servers you want to protect. They should be working too

3.

Add synproxy statements for the servers you want to protect.

To achieve these requirements:

1.

The helper will automatically do everything needed for SYNPROXY to:

•

receive the initial SYN packet from the client

•

respond back to the client with SYN+ACK

•

receive the first ACK packet from the client

•

send the initial SYN packet to the server

There are cases where the above are very tricky to achieve. You don't need to match these in your firehol.conf. The synproxy helper will automatically take care of them. However:

You do need the allow the flow of traffic between the real server and the real client (as you normally do without a synproxy, with a client, server, or route statement in an interface or router section).

2.

The helper will prevent the 3-way TCP handshake between SYNPROXY and the real server interact with other destination NAT rules you may have. However for this to happen, make sure you place the synproxy statements above any destination NAT rules (redirect, dnat, transparent_squid, transparent_proxy, tproxy, etc). So:

SYNPROXY will interact with destination NAT you have in firehol.conf only if the synproxy statements are place below the destination NAT ones.

You normally do not need to have synproxy interact with other destination NAT rules. The synproxy helper will handle the destination NAT (dnat or redirect) it needs by itself.

So place synproxy statements above all destination NAT statements, unless you know what you are doing.

3.

The helper will allow the 3-way TCP handshake between SYNPROXY and the real server interact with source NAT rules you may have (snat, masquerade), since these may be needed to reach the real server.

## LIMITATIONS
1.

Internally there are matches that are made without taking into account the original inface. So, in case different actions have to be taken depending on the interface the request is received, src should be added to differentiate the traffic between the two flows.

2.

SYNPROXY does not inherit MARKs from the original request packets. It should and it would make matching a lot easier, but it does not. This means that for all packets generated by SYNPROXY, inface is lost.

3.

FireHOL internally uses a MARK to tag packets send from SYNPROXY to the target server. This is used for 3 reasons:

•

isolate these packets from other destination NAT rules. If they were not isolated from the destination NAT rules, then packets from the SYNPROXY could be matched by a transparent proxy and enter your web proxy. They could be matched by a transparent proxy because they actually originate from the local machine.

•

isolate the same packets from the rest of the packet filtering rules. Without this isolation, most probably the packets will have been dropped since they come from lo.

•

report if orphan synproxy packets are encountered. So packets the FireHOL engine failed to match properly, should appear with a iptables log saying "ORPHAN SYNPROXY->SERVER". If you don't have such logs, everything works as expected.

## OTHER OPTIONS
You can change the TCP options used by synproxy by setting the variable FIREHOL_SYNPROXY_OPTIONS. The default is this:

```
FIREHOL_SYNPROXY_OPTIONS="--sack-perm --timestamp --wscale 7 --mss 1460"
```

If you want to see it in action in the iptables log, then enable logging:

```
FIREHOL_SYNPROXY_LOG=1
```

The default is disabled (0). If you enable it, every step of the 3-way setup between the client and SYNPROXY and the SYN packet of SYNPROXY towards the real server will be logged by iptables.

Using the variable FIREHOL_CONNTRACK_LOOSE_MATCHING you can set net.netfilter.nf_conntrack_tcp_loose. FireHOL will automatically set this to 0 when a synproxy is set up.

Using the variable FIREHOL_TCP_TIMESTAMPS you can set net.ipv4.tcp_timestamps. FireHOL will automatically set this to 1 when a synproxy is set up.

Using the variable FIREHOL_TCP_SYN_COOKIES you can set net.ipv4.tcp_syncookies. FireHOL will automatically set this to 1 when a synproxy is set up.

On a busy server, you are advised to increase the maximum connection tracker entries and its hash table size.

•

Using the variable FIREHOL_CONNTRACK_HASHSIZE you can set /sys/module/nf_conntrack/parameters/hashsize.

•

Using the variable FIREHOL_CONNTRACK_MAX you can set net.netfilter.nf_conntrack_max.

FireHOL will not alter these variables by itself.

## SYNPROXY AND DYNAMIC IP
By default the synproxy helper requires from you to define a dst IP of the server that is to be protected. This is required because the destination IP will be used to match the SYN packet the synproxy sends to the server.

There is however another way that allows the use of synproxy in environments where the IP of the server is unknown (like a dynamic IP DSL):

1.

First you need to set FIREHOL_SYNPROXY_EXCLUDE_OWNER=1. This will make synproxy not match packets that are generated by the local machine, even if the process that generates them uses your public IP (the packets in order to be matched they will need not have a UID or GID).

2.

Next you will need to exclude you lan IPs by adding src not "${UNROUTABLE_IPS}" (or any other network you know you use) to the synproxy statement.

## EXAMPLES
Protect a web server running on the firewall with IP 1.2.3.4, from clients on eth0:

```
ipv4 synproxy input inface eth0 dst 1.2.3.4 dport 80 accept
interface eth0 wan
    server http accept
```

Protect a web server running on port 90 on the firewall with IP 1.2.3.4, from clients on eth0 that believe the web server is running on port 80:

```
server_myhttp_ports="tcp/90"
client_myhttp_ports="default"
ipv4 synproxy input inface eth0 dst 1.2.3.4 dport 80 redirect to 90
interface eth0 wan
    server myhttp accept # packet filtering works with the real ports
```

Protect a web server running on another machine (5.6.7.8), while the firewall is the router (without NAT):

```
ipv4 synproxy forward inface eth0 dst 5.6.7.8 dport 80 accept
router wan2lan inface eth0 outface eth1
    server http accept dst 5.6.7.8
```

Protect a web server running on another machine in a DMZ (public IP is 1.2.3.4 on eth0, web server IP is 10.1.1.1 on eth1):

```
ipv4 synproxy input inface eth0 \
    dst 1.2.3.4 dport 80 dnat to 10.1.1.1
router wan2lan inface eth0 outface eth1
    server http accept dst 10.1.1.1
```

Note that we used input not forward, because the firewall has the IP 1.2.3.4 on its eth0 interface. The client request is expected on input.

Protect an array of 10 web servers running on 10 other machines in a DMZ (public IP is 1.2.3.4 on eth0, web servers IPs are 10.1.1.1 to 10.1.1.10 on eth1):

```
ipv4 synproxy input inface eth0 \
    dst 1.2.3.4 dport 80 dnat to 10.1.1.1-10.1.1.10 persistent
router wan2lan inface eth0 outface eth1
    server http accept dst 10.1.1.1-10.1.1.10
```

The above configuration is a load balancer. Requests towards 1.2.3.4 port 80 will be distributed to the 10 web servers with persistence (each client will always see one of them).

Catch all traffic towards SSH port tcp/22 and send it to TRAP_AND_DROP as explained in Working With Traps (Working-with-traps). At the same time, allow SSH on port tcp/2200 (without altering the ssh server):

```
 # definition of action TRAP_AND_DROP
 ipv4 action TRAP_AND_DROP sockets_suspects_trap 3600 86400 1 src not "${UNROUTABLE_IPS}" next action DROP
 # send ssh traffic to TRAP_AND_DROP
 ipv4 synproxy input inface eth0 dst 1.2.3.4 dport 22 action TRAP_AND_DROP
 # accept ssh traffic on tcp/2200
 ipv4 synproxy input inface eth0 dst 1.2.3.4 dport 2200 redirect to 22
 interface eth0 wan
    server ssh accept
```

## SEE ALSO
•

firehol(1) - FireHOL program

•

firehol.conf(5) - FireHOL configuration

•

firehol-interface(5) - interface definition

•

firehol-router(5) - router definition

•

firehol-params(5) - optional rule parameters

•

firehol-masquerade(5) - masquerade helper

•

FireHOL Website (http://firehol.org/)

•

FireHOL Online PDF Manual (http://firehol.org/firehol-manual.pdf)

•

FireHOL Online Documentation (http://firehol.org/documentation/)

•

NAT HOWTO (http://www.netfilter.org/documentation/HOWTO/NAT-HOWTO-6.html)

•

netfilter flow diagram (http://upload.wikimedia.org/wikipedia/commons/3/37/Netfilter-packet-flow.svg)

## AUTHORS
FireHOL Team.


firehol-synproxy

title: firehol-synproxy(5)

text:
# firehol-synproxy(5)

## NAME
firehol-tcpmss - set the MSS of TCP SYN packets for routers

## SYNOPSIS
tcpmss { mss | auto } [if-list]

## DESCRIPTION
The tcpmss helper command sets the MSS (Maximum Segment Size) of TCP SYN packets routed through the firewall. This can be used to overcome situations where Path MTU Discovery is not working and packet fragmentation is not possible.

A numeric mss will set MSS of TCP connections to the value given. Using the word auto will set the MSS to the MTU of the outgoing interface minus 40 (clamp-mss-to-pmtu).

If used within a router or interface definition the MSS will be applied to outgoing traffic on the outface(s) of the router or interface.

If used before any router or interface definitions it will be applied to all traffic passing through the firewall. If if-list is given, the MSS will be applied only to those interfaces.

## EXAMPLES

```
tcpmss auto
tcpmss 500
tcpmss 500 "eth1 eth2 eth3"
```

## SEE ALSO
•

firehol(1) - FireHOL program

•

firehol.conf(5) - FireHOL configuration

•

firehol-interface(5) - interface definition

•

firehol-router(5) - router definition

•

FireHOL Website (http://firehol.org/)

•

FireHOL Online PDF Manual (http://firehol.org/firehol-manual.pdf)

•

FireHOL Online Documentation (http://firehol.org/documentation/)

•

TCPMSS target in the iptables tutorial (https://www.frozentux.net/iptables-tutorial/iptables-tutorial.html#TCPMSSTARGET)

## AUTHORS
FireHOL Team.


firehol-tcpmss

title: firehol-tcpmss(5)

text:
# firehol-tcpmss(5)

## NAME
firehol-tcpmss - set the MSS of TCP SYN packets for routers

## SYNOPSIS
tcpmss { mss | auto } [if-list]

## DESCRIPTION
The tcpmss helper command sets the MSS (Maximum Segment Size) of TCP SYN packets routed through the firewall. This can be used to overcome situations where Path MTU Discovery is not working and packet fragmentation is not possible.

A numeric mss will set MSS of TCP connections to the value given. Using the word auto will set the MSS to the MTU of the outgoing interface minus 40 (clamp-mss-to-pmtu).

If used within a router or interface definition the MSS will be applied to outgoing traffic on the outface(s) of the router or interface.

If used before any router or interface definitions it will be applied to all traffic passing through the firewall. If if-list is given, the MSS will be applied only to those interfaces.

## EXAMPLES

```
tcpmss auto
tcpmss 500
tcpmss 500 "eth1 eth2 eth3"
```

## SEE ALSO
•

firehol(1) - FireHOL program

•

firehol.conf(5) - FireHOL configuration

•

firehol-interface(5) - interface definition

•

firehol-router(5) - router definition

•

FireHOL Website (http://firehol.org/)

•

FireHOL Online PDF Manual (http://firehol.org/firehol-manual.pdf)

•

FireHOL Online Documentation (http://firehol.org/documentation/)

•

TCPMSS target in the iptables tutorial (https://www.frozentux.net/iptables-tutorial/iptables-tutorial.html#TCPMSSTARGET)

## AUTHORS
FireHOL Team.


firehol-tos

title: firehol-tos(5)

text:
# firehol-tos(5)

## NAME
firehol-tos - set the Type of Service (TOS) of packets

## SYNOPSIS
tos value chain [rule-params]

## DESCRIPTION
The tos helper command sets the Type of Service (TOS) field in packet headers.

Note

There is also a tos parameter which allows matching TOS values within individual rules (see firehol-params(5)).

The value can be an integer number (decimal or hexadecimal) or one of the descriptive values accepted by iptables(8) (run iptables -j TOS --help for a list).

The chain will be used to find traffic to mark. It can be any of the iptables(8) built in chains belonging to the mangle table. The chain names are: INPUT, FORWARD, OUTPUT, PREROUTING and POSTROUTING. These names are case-sensitive.

The rule-params define a set of rule parameters to match the traffic that is to be marked within the chosen chain. See firehol-params(5) for more details.

Any tos commands will affect all traffic matched. They must be declared before the first router or interface.

## EXAMPLES

```
 # set TOS to 16, packets sent by the local machine
 tos 16 OUTPUT
 # set TOS to 0x10 (16), packets routed by the local machine
 tos 0x10 FORWARD
 # set TOS to Maximize-Throughput (8), packets routed by the local
 #              machine, destined for port TCP/25 of 198.51.100.1
 tos Maximize-Throughput FORWARD proto tcp dport 25 dst 198.51.100.1
```

## SEE ALSO
•

firehol(1) - FireHOL program

•

firehol.conf(5) - FireHOL configuration

•

firehol-params(5) - optional rule parameters

•

firehol-tosfix(5) - tosfix config helper

•

iptables(8) (http://ipset.netfilter.org/iptables.man.html) - administration tool for IPv4 firewalls

•

ip6tables(8) (http://ipset.netfilter.org/ip6tables.man.html) - administration tool for IPv6 firewalls

•

FireHOL Website (http://firehol.org/)

•

FireHOL Online PDF Manual (http://firehol.org/firehol-manual.pdf)

•

FireHOL Online Documentation (http://firehol.org/documentation/)

## AUTHORS
FireHOL Team.


firehol-tosfix

title: firehol-tosfix(5)

text:
# firehol-tosfix(5)

## NAME
firehol-version - set version number of configuration file

## SYNOPSIS
version 6

## DESCRIPTION
The version helper command states the configuration file version.

If the value passed is newer than the running version of FireHOL supports, FireHOL will not run.

You do not have to specify a version number for a configuration file, but by doing so you will prevent FireHOL trying to process a file which it cannot handle.

The value that FireHOL expects is increased every time that the configuration file format changes.

Note

If you pass version 5 to FireHOL, it will disable IPv6 support and warn you that you must update your configuration.

## SEE ALSO
•

firehol(1) - FireHOL program

•

firehol.conf(5) - FireHOL configuration

•

FireHOL Website (http://firehol.org/)

•

FireHOL Online PDF Manual (http://firehol.org/firehol-manual.pdf)

•

FireHOL Online Documentation (http://firehol.org/documentation/)

## AUTHORS
FireHOL Team.


firehol-version

title: firehol-version(5)

text:
# firehol-version(5)

## NAME
firehol-version - set version number of configuration file

## SYNOPSIS
version 6

## DESCRIPTION
The version helper command states the configuration file version.

If the value passed is newer than the running version of FireHOL supports, FireHOL will not run.

You do not have to specify a version number for a configuration file, but by doing so you will prevent FireHOL trying to process a file which it cannot handle.

The value that FireHOL expects is increased every time that the configuration file format changes.

Note

If you pass version 5 to FireHOL, it will disable IPv6 support and warn you that you must update your configuration.

## SEE ALSO
•

firehol(1) - FireHOL program

•

firehol.conf(5) - FireHOL configuration

•

FireHOL Website (http://firehol.org/)

•

FireHOL Online PDF Manual (http://firehol.org/firehol-manual.pdf)

•

FireHOL Online Documentation (http://firehol.org/documentation/)

## AUTHORS
FireHOL Team.


fireqos-class

title: fireqos-class(5)

summary: traffic class definition

text:
# fireqos-class(5)

## NAME
fireqos-class - traffic class definition

## SYNOPSIS
{class|class4|class6|class46} [group] name [optional-class-params]

{class|class4|class6|class46} group end

## DESCRIPTION
There is also an optional match parameter called class; see fireqos-params-match(5).

Writing class inherits the IPv4/IPv6 version from its enclosing interface (see fireqos-interface(5)).

Writing class4 includes only IPv4 traffic in the class.

Writing class6 includes only IPv6 traffic in the class.

Writing class46 includes both IPv4 and IPv6 traffic in the class.

The actual traffic to be matched by a class is defined by adding matches. See fireqos-match(5).

The sequence that classes appear in the configuration defines their priority. The first class is the most important one. Unless otherwise limited it will get all available bandwidth if it needs to.

The second class is less important than the first, the third is even less important than the second, etc. The idea is very simple: just put the classes in the order of importance to you.

Classes can have their priority assigned explicitly with the prio parameter. See fireqos-params-class(5).

Note

The underlying Linux qdisc used by FireQOS, HTB, supports only 8 priorities, from 0 to 7. If you use more than 8 priorities, all after the 8th will get the same priority (prio 7).

All classes in FireQOS share the interface bandwidth. However, every class has a committed rate (the minimum guaranteed speed it will get if it needs to) and a ceiling (the maximum rate this class can reach, provided there is capacity available and even if there is spare).

Classes may be nested to any level by using the class group syntax.

By default FireQOS creates nested classes as classes directly attached to their parent class. This way, nesting does not add any delays.

FireQOS can also emulate new hardware at the group class level. This may be needed, when for example you have an ADSL router that you connect to via Ethernet: you want the LAN traffic to be at Ethernet speed, but WAN traffic at ADSL speed with proper ADSL overheads calculation.

To accomplish hardware emulation nesting, you add a linklayer definition (ethernet, adsl, atm, etc.), or just an mtu to the group class. FireQOS will create a qdisc within the class, where the linklayer parameters will be assigned and the child classes will be attached to this qdisc. This adds some delay to the packets of the child classes, but allows you to emulate new hardware. For linklayer options, see fireqos-params-class(5).

There is special class, called default. Default classes can be given explicitly in the configuration file. If they are not found in the config, FireQOS will append one at the end of each interface or class group.

## PARAMETERS
group

It is possible to nest classes by using a group. Grouped classes must be closed with the class group end command. Class groups can be nested.

name

This is a single-word name for this class and is used for displaying status information.

optional-class-params

The set of optional class parameters to apply to this class.

The following optional class parameters are inherited from the interface the class is in:

•

ceil

•

burst

•

cburst

•

quantum

•

qdisc

If you define one of these at the interface level, then all classes within the interface will get the value by default. These values can be overwritten by defining the parameter on the class too. The same inheritance works on class groups.

Optional class parameters not in the above list are not inherited from interfaces.

FireQOS will by default commit 1/100th of the parent bandwidth to each class. This can be overwritten per class by adding a commit to the class, or adding a minrate at the parent.

## EXAMPLES
To create a nested class, called servers, containing http and smtp:

```
interface eth0 lan input rate 1Gbit
  class voip commit 1Mbit
    match udp ports 5060,10000:10100
  class group servers commit 50%  # define the parent class
    match tcp                     # apply to all child classes
    class mail commit 50%         # 50% of parent ('servers')
      match port 25               # matches within parent ('servers')
    class web commit 50%
      match port 80
  class group end                 # end the group 'servers'
  class streaming commit 30%
```

To create a nested class which emulates an ADSL modem:

```
interface eth0 lan output rate 1Gbit ethernet
  class lan
    match src 192.168.0.0/24 # LAN traffic
  class group adsl rate 10Mbit ceil 10Mbit adsl remote pppoe-llc
    match all # all non-lan traffic in this emulated hardware group
    class voip # class within adsl
      match udp port 5060
    class web # class within adsl
      match tcp port 80,443
  class group end
```

## SEE ALSO
•

fireqos-params-class(5) - QOS class parameters

•

fireqos(1) - FireQOS program

•

fireqos.conf(5) - FireQOS configuration file

•

fireqos-interface(5) - QOS interface definition

•

fireqos-match(5) - QOS traffic match

•

FireHOL Website (http://firehol.org/)

•

FireQOS Online PDF Manual (http://firehol.org/fireqos-manual.pdf)

•

FireQOS Online Documentation (http://firehol.org/documentation/)

## AUTHORS
FireHOL Team.


fireqos-conf

title: fireqos-conf(5)

summary: create an interface definition

text:
# fireqos-conf(5)

## NAME
fireqos-interface - create an interface definition

## SYNOPSIS
{ interface | interface4 } device name direction [optional-class-params] { rate | commit | min } speed

interface46 ...

interface6 ...

## DESCRIPTION
Writing interface or interface4 applies traffic shaping rules only to IPv4 traffic.

Writing interface6 applies traffic shaping rules only to IPv6 traffic.

Writing interface46 applies traffic shaping rules to both IPv4 and IPv6 traffic.

The actual traffic shaping behaviour of a class is defined by adding classes. See fireqos-class(5).

Note

To achieve best results with incoming traffic shaping, you should not use 100% of the available bandwidth at the interface level.

If you use all there is, at 100% utilisation of the link, the neighbour routers will start queuing packets. This will destroy prioritisation. Try 85% or 90% instead.

## PARAMETERS
device

This is the interface name as shown by ip link show (e.g. eth0, ppp1, etc.)

name

This is a single-word name for this interface and is used for retrieving status information later.

direction

If set to input, traffic coming in to the interface is shaped.

If set to output, traffic going out via the interface is shaped.

if set to bidirectional traffic for both input and output can be shaped. If you need to differentiate input and output parameters per statements within the interface, you can prefix them with input or output like this:

```
interface eth0 lan bidirectional ...
    class voip input commit 1Mbit output commit 2Mbit ...
```

optional-class-params

For a list of optional class parameters which can be applied to an interface, see fireqos-params-class(5).

speed

For an interface, the committed speed must be specified with the rate option. The speed can be expressed in any of the units described in fireqos.conf(5).

## EXAMPLES
To create an input policy on eth0, capable of delivering up to 1Gbit of traffic:

```
interface eth0 lan-in input rate 1Gbit
```

## SEE ALSO
•

fireqos.conf(5) - FireQOS configuration file

•

fireqos-class(5) - QOS class definition

•

fireqos-params-class(5) - QOS class parameters

•

FireHOL Website (http://firehol.org/)

•

FireQOS Online PDF Manual (http://firehol.org/fireqos-manual.pdf)

•

FireQOS Online Documentation (http://firehol.org/documentation/)

## AUTHORS
FireHOL Team.


fireqos-interface

title: fireqos-interface(5)

summary: create an interface definition

text:
# fireqos-interface(5)

## NAME
fireqos-interface - create an interface definition

## SYNOPSIS
{ interface | interface4 } device name direction [optional-class-params] { rate | commit | min } speed

interface46 ...

interface6 ...

## DESCRIPTION
Writing interface or interface4 applies traffic shaping rules only to IPv4 traffic.

Writing interface6 applies traffic shaping rules only to IPv6 traffic.

Writing interface46 applies traffic shaping rules to both IPv4 and IPv6 traffic.

The actual traffic shaping behaviour of a class is defined by adding classes. See fireqos-class(5).

Note

To achieve best results with incoming traffic shaping, you should not use 100% of the available bandwidth at the interface level.

If you use all there is, at 100% utilisation of the link, the neighbour routers will start queuing packets. This will destroy prioritisation. Try 85% or 90% instead.

## PARAMETERS
device

This is the interface name as shown by ip link show (e.g. eth0, ppp1, etc.)

name

This is a single-word name for this interface and is used for retrieving status information later.

direction

If set to input, traffic coming in to the interface is shaped.

If set to output, traffic going out via the interface is shaped.

if set to bidirectional traffic for both input and output can be shaped. If you need to differentiate input and output parameters per statements within the interface, you can prefix them with input or output like this:

```
interface eth0 lan bidirectional ...
    class voip input commit 1Mbit output commit 2Mbit ...
```

optional-class-params

For a list of optional class parameters which can be applied to an interface, see fireqos-params-class(5).

speed

For an interface, the committed speed must be specified with the rate option. The speed can be expressed in any of the units described in fireqos.conf(5).

## EXAMPLES
To create an input policy on eth0, capable of delivering up to 1Gbit of traffic:

```
interface eth0 lan-in input rate 1Gbit
```

## SEE ALSO
•

fireqos.conf(5) - FireQOS configuration file

•

fireqos-class(5) - QOS class definition

•

fireqos-params-class(5) - QOS class parameters

•

FireHOL Website (http://firehol.org/)

•

FireQOS Online PDF Manual (http://firehol.org/fireqos-manual.pdf)

•

FireQOS Online Documentation (http://firehol.org/documentation/)

## AUTHORS
FireHOL Team.