firehol.conf is the configuration file for firehol(1), which creates an iptables firewall from the simple rules in this file.
This file is parsed as a bash(1) script, so it's no problem to use variables or complex bashisms.
interface <real interface> <name> [optional rule parameters]
Parameters
interface eth0 internet src not "$UNROUTABLE_IPS" (note: UNROUTABLE_IPS is a variable defined by FireHOL that includes all IPs that should not be routable by the Internet).
router <name> [optional rule parameters]
Parameters
Description
To match some client or server traffic the administrator has to specify the input/output interface or the source/destination of the request. All inface/outface, src/dst optional rule parameters can be given either on the router statement in which case will be applied to all subcommands for this router, or on each subcommand within a router. Both are valid.
For example:
The above says: Define a router that matches all requests that originate from some PPP interface and go out to eth0. There is an HTTP server in eth0 that client from the PPP interfaces are allowed to reach. Clients on eth0 are allowed to get SMTP traffic from the PPP interfaces.
While:
The above says: Define a router that matches any kind of forwarded traffic. For HTTP traffic the clients are on a PPP interface and the servers on eth0. For SMTP traffic the clients are on a eth0 interface and the servers o a PPP interface.
Please note that in the second example the SMTP traffic is matched again with a server subcommand, not a client (as in the first example).
The client subcommand reverses all the optional rules that are applied indirectly to it. Indirect rule parameters are those that are inherited from the parent command (router in this case). To make it simple, for FireHOL a client is: "a server with all the implicit optional rule parameters reversed".
So, in the first example, the client simply flipped the inface and outface rules defined at the router and became an SMTP server. In the second example there is nothing to be flipped, so server and client are exactly the same.
I suggest to use client subcommands in routers only if you have inface/outface or src/dst in the router statements. If you are building routers like the second example, don't use client, it is confusing.
Older versions of FireHOL did not allow server and client subcommands in routers. Only the route subcommand was allowed. Today, route is just an alias for server and can be used only in routers, not interfaces.
Any number of router statements can exist. Since the policy is RETURN on all of them, any traffic not matched by a router will continue to be checked against the second.
Subcommands must be given within Primary commands.
policy <action>
This directive accepts all the actions specified in the section Actions.
The policy of routers cannot be changed and is always RETURN.
protection [reverse] <type>
In router configurations, protections are setup on inface.
Parameters
server <service> <action> [optional rule parameters]
The optional rule parameters given to the parent primary command (interface or router) are inherited by the server as they have been given.
This subcommand can be used on both interfaces and routers.
Parameters
server "smtp pop3 imap" accept
FireHOL supports the actions defined in the section Actions.
server smtp accept log "its mail" src 1.2.3.4
client <service> <action> [optional rule parameters]
The optional rule parameters given to the parent primary command (interface or router) are inherited by the client, but they are reversed. For an explanation of this please refer to the documentation of the router primary command.
This subcommand can be used on both interfaces and routers.
route <service> <action> [optional rule parameters]
version <number>
This command is here to allow you or anyone else design and distribute FireHOL configuration files, while ensuring that the correct FireHOL version is going to run them.
The FireHOL release is increased every time the format of the configuration file and the internals of FireHOL are changed.
Since FireHOL v1.67 version is not required to be present in every configuration file.
iptables <arguments>
You should not use /sbin/iptables directly to alter a FireHOL firewall in its configurations. If you do, your commands will be run before FireHOL activates its firewall and while the previous firewall is still running. Also, since FireHOL will delete all previous firewall rules in order to activate the new firewall, any changes you will make, will be deleted too.
Always use the iptables directive to hook iptables commands in a FireHOL firewall. Nothing else.
masquerade [reverse ⎪ interface] [optional rule parameters]
Masquerading is "expensive" compared to SNAT because it checks the IP address of the ougoing interface every time for every packet, and therefore it is suggested that if you connect to the internet with a static IP address, to prefer SNAT.
The masquerade helper sets up masquerading on the output of a network interface (not the interface command, but a real network interface).
If the masquerade command is placed within an interface command, its network interface[s] will be used.
If the masquerade command is placed within a router command that has an outface defined, then the outface network interface[s] will be used.
If placed within a router command but the keyword reverse is specified and the router command has an inface defined, then the inface network interface[s] will be used.
If placed outside and before all primary commands, an interface (or list of space separated interfaces, within double quotes) can be specified on the masquerade command.
In all cases, masquerade will setup itself on the output of the given interface[s].
Please note that if masquerade is used within some interface or router, it does not respect the optional rule parameters given to this interface or router command. Masquerade uses only its own optional rule parameters.
inface and outface should not be given as parameters to masquerade (inface because iptables does not support this in the POSTROUTING chain, and outface because it will be overwritten by the interface(s) mentioned above).
Finally, the masquerade helper will turn on FIREHOL_NAT and instruct the kernel to do packet forwarding (like the router commands do).
Examples:
Within an interface rule to masquerade on the output of this
interface:
masquerade
Within a router rule to masquerade on the output of the router's
inface:
masquerade reverse
transparent_squid <port> <user> [optional rule parameters]
The transparent_squid helper can be used for two kinds of traffic:
The optional rule parameters can be used to specify which kind of incoming traffic to be catched (by using inface, src, dst, etc -- outface should not be used here, because the rules generated are placed before the routing decision and therefore the outgoing interface is not yet known).
If no optional rule parameters are given, then the transparent cache will be setup on all network interfaces for all HTTP traffic (use this with care since you are risking to serve requests from the internet using your squid).
This kind of matching makes it possible to support transparent caching for WEB browsers running on the firewall host, as far as they do not run as the user excluded. More than one users can be specified by space-separating and enclosing them in double quotes.
This rule can be disabled by specifying as user the empty string: ""
Examples:
transparent_squid 8080 "squid privoxy root bin" inface not "ppp+ ipsec+" dst not "a.not.proxied.server"
nat <type> <target> [optional rule parameters]
The type parameter can be:
The target in this case is the source address to be set in packets matching the optional rule parameters (if no optional rule parameters, all forwarded traffic will be matched). target accepts all --to-source values iptables accepts (see iptables -j SNAT --help). Multiple --to-source values can be given, if separated by space and quoted as a single argument.
inface should not be used in SNAT, because iptables does provide this information at this point.
The target in this case is the destination address to be set in packets matching the optional rule parameters (if no optional rule parameters, all forwarded traffic will be matched). target accepts all --to-destination values iptables accepts (see iptables -j DNAT --help). Multiple --to-destination values can be given, if separated by space and quoted as a single argument.
outface should not be used in DNAT, because iptables does provide this information at this point.
The target in this case is a port or a range of ports (XXX-YYY) that packets matching the rule will be redirected to (if no optional rule parameters are given, all incoming traffic will be matched). target accepts all --to-ports values iptables accepts (see iptables -j REDIRECT --help).
outface should not be used in REDIRECT, because iptables does provide this information at this point.
Please understand that the optional rule parameters are used only to limit the traffic to be matched. Consider these examples:
nat to-destination 1.1.1.1 dst 2.2.2.2
nat to-destination 1.1.1.1 proto tcp dst 2.2.2.2
nat to-destination 1.1.1.1 proto tcp dport 25 dst 2.2.2.2
More examples:
nat to-destination 4.4.4.4 inface eth0 src 5.5.5.5 dst 6.6.6.6
nat redirect-to 8080 inface eth0 src 2.2.2.0/24 proto tcp dport 80
snat [to] <target> [optional rule parameters]
See the nat helper.
Example:
dnat [to] <target> [optional rule parameters]
See the nat helper.
Example:
redirect [to] <target> [optional rule parameters]
See the nat helper.
Example:
Actions are the actions to be taken on services and traffic
described by other commands and functions. Please note that normally,
FireHOL will pass-through to the generated iptables statements all the
possible actions iptables accepts, but only the ones defined here can be
used with lower case letters and currently it will be impossible to pass
arguments to some unknown action. Also, keep in mind that the iptables
action LOG is a FireHOL optional rule parameter (see log and loglimit) that
can be defined together with one of the following actions and FireHOL will
actually produce multiple iptables statements to achieve both the logging
and the action.
accept
Example:
reject [with message]
with is used to offer control on the message to be returned to the sender. with accepts all the arguments the --reject-with iptables expression accepts. For an updated list of these messages type iptables -j REJECT --help.
Examples:
server ident reject with tcp-reset
UNMATCHED_INPUT_POLICY="reject with host-prohib"
drop
Example:
deny
Example:
return
Example:
mirror
redirect [to-port port]
Optional rule parameters are accepted by many commands to narrow the match they do by default. The parameters described bellow are all that FireHOL supports. You should check the documentation of each command to find which parameters should not be used with it. Normally, all FireHOL commands are designed so that if you specify a parameters that is also used internally, the internal one will overwrite the one given in the configuration file. In such a case, FireHOL will present you a warning with the old and the new value.
Not all parameters should be used in all cases. For example
sport and dport should not be used in normal server and client
commands since such ports are internally defined by the services themselves.
In any case, FireHOL will complain about optional rule parameters that
should not be used in certain commands.
src [not] <host>
Parameters
dst [not] <host>
dst accepts the same parameters as src.
inface [not] <interface>
Parameters
outface [not] <interface>
outface accepts the same parameters as inface.
custom <parameters>
It is required to quote all the parameters given to custom. If the parameters include a space character between some text that is required to be given to iptables as one argument, it is required to escape another set of quotes in order. Another way is to use double quotes externally and single quotes internally.
Examples:
server smtp accept custom "--some-iptables-option and_its_value"
server smtp accept custom "--some-iptables-option 'one_value another_value'
log "<some text>" [level a_level]
FireHOL logs traffic, exactly the same way iptables does. Many users have complained about packet logs appearing at their console. To avoid this you will have to:
Actually klogd's -c option and iptables' --log-level option are the same thing (iptables accepts also the numeric values klogd accepts). If iptables logs at a higher priority than klogd is configured to use, then your packets will appear in the console too.
loglimit "<some text>"
proto [not] <protocol>
limit <frequency> <burst>
sport <port>
dport <port>
uid [not] <user> =head2 user [not] <user>
This parameter can be used only in services (client and server commands) defined within interfaces, not routers. FireHOL is "smart" enough to apply this parameter only to traffic send by the localhost, i.e. the replies of servers and requests of clients. It is not possible, and FireHOL will simply ignore this parameter, on traffic coming in or passign through the firewall host.
Example 1:
client "pop3 imap" accept user not "user1 user2 user3" dst mymailer.example.com
The above will allow local users except user1, user2 and user3 to use POP3 and IMAP services on mymailer.example.com. You can use this, for example, to allow only a few of the local users use the fetchmail program to fetch their mail from the mail server.
Example 2:
server http accept user apache
The above will allow all HTTP to reach the local http server, but only if the web server is running as user apache the replies will be send back to the HTTP client.
gid <group> =head2 group <group>
This parameter can be used only in services (client and server commands) defined within interfaces, not routers. FireHOL is "smart" enough to apply this parameter only to traffic send by the localhost, i.e. the replies of servers and requests of clients. It is not possible, and FireHOL will simply ignore this parameter, on traffic coming in or passing through the firewall host.
pid <process> =head2 process <process>
This parameter can be used only in services (client and server commands) defined within interfaces, not routers. FireHOL is "smart" enough to apply this parameter only to traffic send by the localhost, i.e. the replies of servers and requests of clients. It is not possible, and FireHOL will simply ignore this parameter, on traffic coming in or passign through the firewall host.
sid <session> =head2 session <session>
This parameter can be used only in services (client and server commands) defined within interfaces, not routers. FireHOL is "smart" enough to apply this parameter only to traffic send by the localhost, i.e. the replies of servers and requests of clients. It is not possible, and FireHOL will simply ignore this parameter, on traffic coming in or passign through the firewall host.
DEFAULT_INTERFACE_POLICY
All packets that reach the end of an interface are logged only if the action is not return or accept. You can control the frequency of this logging by altering the frequency loglimit uses.
Default: DEFAULT_INTERFACE_POLICY="DROP"
Example: DEFAULT_INTERFACE_POLICY="REJECT"
UNMATCHED_INPUT_POLICY
UNMATCHED_OUTPUT_POLICY
UNMATCHED_FORWARD_POLICY
UNMATCHED_OUTPUT_POLICY controls the default action to be taken for outgoing traffic not matched by any interface command.
UNMATCHED_FORWARD_POLICY controls the default action to be taken for forwarded traffic not matched by any router command.
All variables accept all the Actions FireHOL supports.
All packets that reach the end of firewall in all three chains are logged (always, regardless of these settings). You can control the frequency of this logging by altering the frequency loglimit uses.
Default: UNMATCHED_INPUT_POLICY="DROP"
Default: UNMATCHED_OUTPUT_POLICY="DROP"
Default: UNMATCHED_FORWARD_POLICY="DROP"
Example: UNMATCHED_INPUT_POLICY="REJECT"
Example: UNMATCHED_OUTPUT_POLICY="REJECT"
Example: UNMATCHED_FORWARD_POLICY="REJECT"
FIREHOL_LOG_LEVEL =head2 FIREHOL_LOG_OPTIONS =head2 FIREHOL_LOG_FREQUENCY =head2 FIREHOL_LOG_BURST
FIREHOL_LOG_OPTIONS controls the way iptables will log things to the syslog. The value of this variable is passed as is to iptables, so use exact iptables parameters.
FIREHOL_LOG_FREQUENCY and FIREHOL_LOG_BURST (added in v1.39 of FireHOL) control the frequency at each each logging rule will write packets to the syslog. FIREHOL_LOG_FREQUENCY is set to the maximum average frequency and FIREHOL_LOG_BURST specifies the maximum initial number of packets to match.
Default: FIREHOL_LOG_OPTIONS="--log-level warning"
Default: FIREHOL_LOG_FREQUENCY="1/second"
Default: FIREHOL_LOG_BURST="5"
Example: FIREHOL_LOG_OPTIONS="--log-level info --log-tcp-options --log-ip-options"
Example: FIREHOL_LOG_FREQUENCY="30/minute"
Example: FIREHOL_LOG_BURST="2"
To see the available iptables log options, run "/sbin/iptables -j LOG --help" To see what iptables accepts as frequencies and bursts, run "/sbin/iptables -m limit --help"
You can also check man iptables.
DEFAULT_CLIENT_PORTS
Default: 1000:65535
Example: DEFAULT_CLIENT_PORTS="0:65535"
FIREHOL_NAT
Default: FIREHOL_NAT="0"
Example: FIREHOL_NAT="1"
FIREHOL_AUTOSAVE
Default: FIREHOL_AUTOSAVE="" Example: FIREHOL_AUTOSAVE="/tmp/firehol-saved.txt"
RESERVED_IPS
Example: interface eth0 internet src not "${RESERVED_IPS}"
PRIVATE_IPS
Example: interface eth0 internet src not "${PRIVATE_IPS}"
UNROUTABLE_IPS
Example: interface eth0 internet src not "${UNROUTABLE_IPS}"
/etc/firehol/firehol.conf
firehol written by Costa Tsaousis <costa@tsaousis.gr>.
Man page written by Marc Brockschmidt <<marc@marcbrockschmidt.de>.