{"id":8602,"date":"2024-01-06T00:12:59","date_gmt":"2024-01-06T00:12:59","guid":{"rendered":"https:\/\/cheapwindowsvps.com\/blog\/how-to-configure-iptables-using-firehol-a-comprehensive-guide\/"},"modified":"2025-01-20T09:54:08","modified_gmt":"2025-01-20T09:54:08","slug":"how-to-configure-iptables-using-firehol-a-comprehensive-guide","status":"publish","type":"post","link":"https:\/\/cheapwindowsvps.com\/blog\/how-to-configure-iptables-using-firehol-a-comprehensive-guide\/","title":{"rendered":"How to Configure iptables Using Firehol: A Comprehensive Guide"},"content":{"rendered":"<p><div>Firehol is an open-source tool used to configure Linux firewalls, such as those based on iptables. Advanced users can delve deeper into the rule set with optional parameters. Firehol ensures that the rules are coherent in both directions.<\/div>\n<p>By default, Firehol generates rules for both IPv4 and IPv6. This can be changed in the configuration file <em>firehol-defaults.con<\/em>f by setting the variables <em>ENABLE_IPV4 and ENABLE_IPV6 <\/em>to either 0 or 1 as needed.<\/p>\n<h2>Installing and configuring Firehol<\/h2>\n<p>Install Firehol on Debian and Ubuntu with:<\/p>\n<\/p>\n<p><pre>sudo apt install firehol<\/pre>\n<\/p>\n<p><p>Configure it through the file <em>firehol.conf <\/em>in the <em>\/etc\/firehol\/<\/em> directory. You can open it with:<\/p>\n<\/p>\n<p><pre>sudo nano firehol.conf<\/pre>\n<\/p>\n<p><p><a href=\"https:\/\/4sysops.com\/wp-content\/uploads\/2024\/01\/Editing-the-firehol.conf-configuration-file.png\" rel=\"nofollow noopener\" target=\"_blank\">Editing the firehol.conf configuration file<\/a><\/p>\n<\/p>\n<p><em>\/etc\/default\/firehol<\/em> <\/p>\n<pre>START_FIREHOL=YES<\/p><p><\/pre>\n<div><a href=\"https:\/\/4sysops.com\/wp-content\/uploads\/2024\/01\/Adding-settings-for-Firehol-to-start-automatically.png\" rel=\"nofollow noopener\" target=\"_blank\">Adding settings for Firehol to start automatically<\/a><\/div>\n<pre>sudo \/etc\/init.d\/firehol start<\/p><p><\/pre>\n<\/p>\n<p><p>Keep in mind that the service might be installed in a different directory. To enable autostart for the service use this command:<\/p>\n<pre>sudo update-rc.d firehol defaults<\/p><p><\/pre>\n<h2>Firehol QuickStart<\/h2>\n<p>To quickly configure a functional firewall, you can generate a sample configuration with the most important functions:<\/p>\n<\/p>\n<p><pre>sudo firehol helpme &gt; \/tmp\/firehol.conf<\/pre>\n<\/p>\n<p><p>Firehol reads the local system services and adjusts the configuration accordingly.<\/p>\n<\/p>\n<p><a href=\"https:\/\/4sysops.com\/wp-content\/uploads\/2024\/01\/Generating-basic-configuration-for-Firehol.png\" rel=\"nofollow noopener\" target=\"_blank\">Link<\/a><\/p>\n<p><p>Generating basic configuration for Firehol<\/p>\n<\/p>\n<p><em>firehol-defaults.co<\/em><\/p>\n<p><em>\/etc\/firehol<\/em> <\/p>\n<p>The options in <em>firehol-default.conf<\/em> come into play when no rule or variable is set in <em>firehol.conf.<\/em> This is useful, for example, for logging.<\/p>\n<div><a href=\"https:\/\/4sysops.com\/wp-content\/uploads\/2024\/01\/The-variables-in-firehol-defaults.conf-control-the-behavior-of-Firehol.png\" rel=\"nofollow noopener\" target=\"_blank\"><\/a><\/p>\n<p>The variables in firehol-defaults.conf control the behavior of Firehol<\/p>\n<\/div>\n<h2>Firehol operates as a stateful olution<\/h2>\n<\/p>\n<p><p>Firehol effectively matches both requests and responses. This is possible because the Linux kernel is aware of all active connections and consequently determines expected packets from those that are not. Firehol&#8217;s usage of the In-Kernel-Connection-Tracker allows it to automatically dispose of all packets considered invalid.<\/p>\n<\/p>\n<p><p>Setting a new rule using Firehol means focusing mainly on the requests. Through this, the tool automatically generates the matching answer or reply in the iptables.<\/p>\n<\/p>\n<p><p>Maintenance of individual rules occurs through simple commands inside <em>firehol.conf<\/em>. For illustration, if there is an active HTTP service on the server, merely typing the command into the file will do:<\/p>\n<\/p>\n<p><pre>server http accept<\/p><p><\/pre>\n<\/p>\n<p><p>To allow HTTP client requests, use this command:<\/p>\n<\/p>\n<p><pre>client http accept<\/p><p><\/pre>\n<\/p>\n<p><p>To filter traffic, it&#8217;s not necessary to define every service. However, you can also create your own services, for example with these commands:<\/p>\n<\/p>\n<p><pre>server_myhttp_ports=\"tcp\/80,443\"<\/p><p>client_myhttp_ports=\"default\"<\/p><p><\/pre>\n<\/p>\n<p><p>Then, you can allow packets through the server:<\/p>\n<pre>server myhttp accept<\/p><p>client myhttp accept<\/p><p><\/pre>\n<p>It&#8217;s also possible to use multiple ports:<\/p>\n<pre>server_emule_ports=\"tcp\/4662,64397,7037,23213,25286 udp\/4672\"<\/p><p>client_emule_ports=\"default\"<\/p><p><\/pre>\n<\/p>\n<p><p>Using multiple protocols for all ports can be configured this way:<\/p>\n<\/p>\n<p><pre>server_sip_ports=\"tcp,udp\/5060\"<\/p><p>client_sip_ports=\"default\"<\/p><p><\/pre>\n<\/p>\n<p><h2>Defining Rules with Firehol<\/h2>\n<\/p>\n<p><p>In principle, the firewall applies rules to all packets entering the system. For example, if the server smtp accept is entered in <em>firehol.conf<\/em>, the firewall allows SMTP packets.<\/p>\n<\/p>\n<p><p>However, it&#8217;s possible to create additional rules for Requests using parameters. These are explained in detail in the documentation. For example, to match all SMTP requests from IP address 1.1.1.1 to SMTP server 2.2.2.2, use this command:<\/p>\n<\/p>\n<p><pre>server smtp accept src 1.1.1.1 dst 2.2.2.2<\/pre>\n<\/p>\n<p><h2>Troubleshooting with Firehol: Syslog and NFLOG<\/h2>\n<\/p>\n<p><p>It may happen that the firewall blocks packets, disrupting communication. The documentation provides guidelines on how to troubleshoot.<\/p>\n<\/p>\n<p><p>Firehol records its events in the system log, which can be utilized for analysis. It&#8217;s located in the <em>\/var\/log\/messages<\/em> or <em>\/var\/log\/syslog <\/em>directory.<\/p>\n<p>In there, you can see which packets Firehol implicitly discards, that is, without a rule in the config file. Hence, it&#8217;s also useful to set up logging in advance.<\/p>\n<p>The developers of Firehol suggest using NFLOG for logging firewall actions. To accomplish this, add the line in the file <em>\/etc\/firehol\/firehol-defaults.conf<\/em>:<\/p>\n<pre>FIREHOL_LOG_MODE=\"NFLOG\"<\/p><p><\/pre>\n<\/p>\n<p><p>This relieves the system log.<\/p>\n<\/p>\n<p><p>With this command, the firewall shows which actions it performs based on the current configuration:<\/p>\n<\/p>\n<p><pre>firehol debug<\/p><p><\/pre>\n<\/p>\n<p><p>This helps identify problems. Since Firehol runs as a bash script, additional information can be logged by adding the following lines to the configuration:<\/p>\n<\/p>\n<p><h2>Subscribe to 4sysops newsletter!<\/h2><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Firehol is an open-source tool used to configure Linux firewalls, such as those based on iptables. Advanced users can delve deeper into the rule set with optional parameters. Firehol ensures that the rules are coherent in both directions. By default, Firehol generates rules for both IPv4 and IPv6. This can be changed in the configuration [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":8603,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[92,151,116,114],"tags":[],"class_list":["post-8602","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-articles","category-firewalls","category-linux","category-security"],"_links":{"self":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/8602","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/comments?post=8602"}],"version-history":[{"count":2,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/8602\/revisions"}],"predecessor-version":[{"id":10308,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/8602\/revisions\/10308"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/media\/8603"}],"wp:attachment":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/media?parent=8602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/categories?post=8602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/tags?post=8602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}