Back to Insights
VoIP Engineering

FreeSWITCH Fail2ban and Firewall Hardening: Blocking SIP Attacks Automatically

Telephony Engineering Team
4 min read
FreeSWITCH Fail2ban and Firewall Hardening: Blocking SIP Attacks Automatically

A FreeSWITCH server on a public IP will be scanned within hours. The standard defence is layered: a default-deny firewall, Fail2ban to ban sources that fail authentication, and Sofia settings that avoid answering unknown callers. None of these is exotic, and together they remove most automated attack traffic.

Layer 1: Firewall

Start from default deny and open only what you need:

  • SIP signaling port(s) from known carrier IPs and, if needed, rate-limited from the wider internet
  • The RTP range you configured (for example 16384 to 32768), not the whole UDP space
  • Management (SSH, ESL port 8021) only from VPN or admin IPs. Never expose the event socket publicly.

Use ipset or equivalent with iptables/nftables so you can maintain large allow- and block-lists efficiently.

Layer 2: Fail2ban

FreeSWITCH logs failed authentication, and Fail2ban can watch those log lines and add firewall bans.

Make sure logging captures auth failures. Set the sofia log level so that lines like SIP auth failure (REGISTER) and SIP auth challenge are written to the log file Fail2ban reads.

Filter: a regex matching auth-failure lines and capturing the source IP.

Jail (example values to tune):

[freeswitch]
enabled  = true
port     = 5060,5061
filter   = freeswitch
logpath  = /var/log/freeswitch/freeswitch.log
maxretry = 5
findtime = 600
bantime  = 3600
action   = iptables-allports

Adjust maxretry and findtime to your traffic. Legitimate devices that mistype a password or sit behind NAT with many users can be banned together, so allow-list known office IPs.

Layer 3: Sofia Profile Settings

  • Require authentication for registrations and inbound calls from unknown sources
  • Use ACLs on the profile so that only trusted IPs can send INVITEs without authenticating
  • Disable accept-blind-reg and accept-blind-auth, which skip checks
  • Avoid default users and the sample extensions (such as 1000 to 1019) with default passwords
  • Rate-limit with mod_limit or at an upstream proxy

Layer 4: Put an Edge in Front

A hardened Kamailio or SBC absorbs scanning and floods so FreeSWITCH never sees them (see open-source SBC with Kamailio and RTPengine and FreeSWITCH horizontal scaling with Kamailio).

Verify It Works

  1. From a test host, send repeated failed REGISTER attempts and confirm a ban appears.
  2. Confirm your own carrier and office IPs are not banned.
  3. Check that a banned IP is released after the ban time.
  4. Monitor for ban volume spikes, which signal an active attack (see VoIP security best practices).

What Fail2ban Does Not Do

It reacts after failures, so a distributed attack from many IPs with few attempts each may slip through. Strong passwords, default-deny rules, and spend limits remain essential (see toll fraud prevention).


Want your FreeSWITCH platform audited and hardened? Our FreeSWITCH development team secures and tunes production media servers.

Discussion

0

Join the conversation

Sign in with your preferred account to comment, reply, and keep the discussion useful for other engineers.

Takes a few seconds. No separate password required.

C

Controva LLC

Engineering Team

We build digital empires that scale. Specializing in high-performance web architecture, AI automation, and headless commerce.

Work with us

Share this article