<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jani Willberg</title>
    <description>The latest articles on DEV Community by Jani Willberg (@jwillberg).</description>
    <link>https://dev.to/jwillberg</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3799679%2F53650d4f-968a-46d6-8f49-2aadc2547aa0.PNG</url>
      <title>DEV Community: Jani Willberg</title>
      <link>https://dev.to/jwillberg</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jwillberg"/>
    <language>en</language>
    <item>
      <title>A Lightweight Linux Firewall with Integrated Auto-Ban (nftables-primary backend)</title>
      <dc:creator>Jani Willberg</dc:creator>
      <pubDate>Sun, 01 Mar 2026 12:37:29 +0000</pubDate>
      <link>https://dev.to/jwillberg/a-lightweight-linux-firewall-with-integrated-auto-ban-nftables-primary-backend-443a</link>
      <guid>https://dev.to/jwillberg/a-lightweight-linux-firewall-with-integrated-auto-ban-nftables-primary-backend-443a</guid>
      <description>&lt;p&gt;Any publicly exposed Linux server will receive constant background&lt;br&gt;
noise:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  SSH brute-force attempts&lt;/li&gt;
&lt;li&gt;  SMTP authentication abuse&lt;/li&gt;
&lt;li&gt;  IMAP / POP3 login attempts&lt;/li&gt;
&lt;li&gt;  Port scanning&lt;/li&gt;
&lt;li&gt;  Automated service probing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is normal on the modern internet.&lt;/p&gt;

&lt;p&gt;The traditional protection stack usually looks like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  A firewall (iptables, nftables, UFW, CSF…)&lt;/li&gt;
&lt;li&gt;  Fail2ban for log-based banning&lt;/li&gt;
&lt;li&gt;  Separate services handling detection and enforcement&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It works — but it’s layered and fragmented.&lt;/p&gt;

&lt;p&gt;MEF was built to simplify this model: a lightweight firewall service combined with an integrated auto-ban engine, designed with nftables as the primary backend.&lt;/p&gt;

&lt;h2&gt;
  
  
  What MEF Actually Is
&lt;/h2&gt;

&lt;p&gt;MEF consists of two independent components.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;mef — Firewall Loader&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Loads persistent firewall rules from /etc/mef/mef.rules&lt;/li&gt;
&lt;li&gt;  Runs once at boot (systemd oneshot service)&lt;/li&gt;
&lt;li&gt;  Uses nftables primarily (iptables fallback supported)&lt;/li&gt;
&lt;li&gt;  Keeps rule management explicit and readable&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is the static firewall layer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;mefdaemon — Auto-Ban Engine&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Monitors logs (systemd journal or standard log files)&lt;/li&gt;
&lt;li&gt;  Detects repeated authentication failures across services&lt;/li&gt;
&lt;li&gt;  Responds to suspicious behavior such as repeated connection attempts
or scanning&lt;/li&gt;
&lt;li&gt;  Bans abusive IP addresses directly at the firewall level&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is the dynamic protection layer.&lt;/p&gt;

&lt;p&gt;Both components can run independently — or together.&lt;/p&gt;

&lt;h2&gt;
  
  
  Multi-Service Abuse Detection
&lt;/h2&gt;

&lt;p&gt;MEF is not limited to SSH.&lt;/p&gt;

&lt;p&gt;Common attack patterns look like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Scan open ports&lt;/li&gt;
&lt;li&gt; Identify exposed services&lt;/li&gt;
&lt;li&gt; Attempt repeated logins&lt;/li&gt;
&lt;li&gt; Retry across multiple services&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Protection should not be protocol-specific.&lt;/p&gt;

&lt;p&gt;MEF can respond consistently whether the target is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Port 22 (SSH)&lt;/li&gt;
&lt;li&gt;  25 / 587 (SMTP)&lt;/li&gt;
&lt;li&gt;  143 / 993 (IMAP)&lt;/li&gt;
&lt;li&gt;  110 / 995 (POP3)&lt;/li&gt;
&lt;li&gt;  etc ...&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The goal is practical mitigation of authentication abuse and hostile&lt;br&gt;
probing.&lt;/p&gt;

&lt;h2&gt;
  
  
  nftables-First Enforcement
&lt;/h2&gt;

&lt;p&gt;Instead of inserting firewall rules repeatedly, MEF relies on structured&lt;br&gt;
rule handling.&lt;/p&gt;

&lt;p&gt;Conceptually, enforcement can look like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;nft add set inet filter banned_ips { type ipv4_addr; flags timeout; }&lt;br&gt;
nft add rule inet filter input ip saddr @banned_ips drop&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When an IP crosses defined thresholds, it is added to the set. nftables&lt;br&gt;
handles enforcement efficiently and cleanly.&lt;/p&gt;

&lt;p&gt;This avoids:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Growing rule chains&lt;/li&gt;
&lt;li&gt;  Repeated rule insert overhead&lt;/li&gt;
&lt;li&gt;  Fragmented firewall logic&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Lightweight by Design
&lt;/h2&gt;

&lt;p&gt;MEF is intentionally minimal.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  No heavy dependency stack&lt;/li&gt;
&lt;li&gt;  No complex jail abstraction layers&lt;/li&gt;
&lt;li&gt;  No bloated background processing&lt;/li&gt;
&lt;li&gt;  Designed for VPS and hosting environments&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The focus is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Practical abuse mitigation&lt;/li&gt;
&lt;li&gt;  Clear rule structure&lt;/li&gt;
&lt;li&gt;  Low resource usage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is meant to run quietly in the background while protecting exposed&lt;br&gt;
services.&lt;/p&gt;

&lt;h2&gt;
  
  
  What It Is Not
&lt;/h2&gt;

&lt;p&gt;MEF is not:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  A full IDS/IPS platform&lt;/li&gt;
&lt;li&gt;  A behavioral AI engine&lt;/li&gt;
&lt;li&gt;  An enterprise security appliance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  A modular firewall + auto-ban system&lt;/li&gt;
&lt;li&gt;  Focused on real-world abuse patterns&lt;/li&gt;
&lt;li&gt;  Built around modern Linux firewall tooling&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why Not Just Fail2ban?
&lt;/h2&gt;

&lt;p&gt;Fail2ban works well and has been battle-tested for years.&lt;/p&gt;

&lt;p&gt;MEF differs in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A simpler, modular structure&lt;/li&gt;
&lt;li&gt;nftables-first enforcement&lt;/li&gt;
&lt;li&gt;Optional RBL and cloud-based preemptive blocking&lt;/li&gt;
&lt;li&gt;Minimal runtime dependencies&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is not meant to replace every security tool — but to offer a modern, lightweight alternative for common abuse scenarios.&lt;/p&gt;

&lt;h2&gt;
  
  
  Core Capabilities
&lt;/h2&gt;

&lt;p&gt;Beyond basic firewall + log banning, MEF includes:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dual-Stack Support&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Native support for both IPv4 and IPv6 environments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RBL Integration&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Optional DNS-based Real-time Blackhole List (RBL) lookups allow blocking known malicious IP addresses proactively.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Community Cloud Protection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Optional cloud-based threat lookups enable shared intelligence between installations, allowing preemptive blocking of known abusive IPs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Port Scan Detection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Basic port scan detection by monitoring connection attempts across multiple unique destination ports over time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Flexible Allow/Deny Control&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Support for static and dynamic whitelists and blacklists, with automatic rule updates.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Minimal Dependency Footprint&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No Python or Perl runtime requirements. Designed to keep CPU and memory usage low.&lt;/p&gt;




&lt;p&gt;Use Case&lt;/p&gt;

&lt;p&gt;MEF fits environments where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Services are publicly exposed&lt;/li&gt;
&lt;li&gt;  Authentication abuse is common&lt;/li&gt;
&lt;li&gt;  Administrators prefer nftables over legacy stacks&lt;/li&gt;
&lt;li&gt;  Minimal overhead is important&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Feedback Welcome
&lt;/h2&gt;

&lt;p&gt;I’m interested in any feedback from real-world deployments, testing, or production use.&lt;/p&gt;

&lt;p&gt;In particular, I’m exploring the idea of more service-specific handling based on live activity data.&lt;/p&gt;

&lt;p&gt;Project repository: [&lt;a href="https://github.com/jwillberg/mef" rel="noopener noreferrer"&gt;https://github.com/jwillberg/mef&lt;/a&gt;]&lt;/p&gt;

</description>
      <category>linux</category>
      <category>security</category>
      <category>devops</category>
      <category>firewall</category>
    </item>
  </channel>
</rss>
