Beyond the Firewall: Why Packet Inspection Matters
A common misconception in the IT world is that a solid firewall is all you need for server security. I shared this belief until I managed a public-facing web server that logged over 4,500 failed SSH attempts in a single two-hour window. Even with key-based authentication, the sheer volume of the noise was a wake-up call. I realized then that a firewall is just a locked door. To actually see who is trying the handle and what tools they are using, you need a detective on the inside.
Standard firewalls like UFW or IPTables operate at the connection level. They block or allow traffic based on IP addresses and ports, but they cannot see the malicious payload hidden inside a packet. This is where Snort 3—a Network Intrusion Detection System (NIDS)—becomes essential. It functions as a high-speed analyzer, comparing live traffic against a library of known attack signatures to catch threats that firewalls miss.
Snort 3: A Modern Security Engine
Snort 3, frequently called Snort++, is a ground-up rewrite of the classic Snort 2. Unlike its predecessor, this version is multi-threaded. This architecture allows it to scale across modern multi-core CPUs, making it capable of monitoring 1Gbps+ links without dropping packets. It also replaces the old, rigid configuration files with a flexible Lua-based system.
NIDS vs. IPS: Choosing Your Strategy
Before diving into the installation, you must decide how Snort will interact with your network:
- NIDS (Detection): Snort monitors a mirror of your traffic. It sends alerts when it spots a threat but does not interfere with the flow. This is the safest way to start.
- IPS (Prevention): Snort sits directly in the traffic path. If it identifies a signature like a SQL injection, it drops the packet instantly.
We will focus on NIDS mode for this setup. It prevents accidental self-inflicted outages caused by overly aggressive rules.
Step-by-Step Implementation
1. Preparing the Environment
Compiling Snort 3 from source is the best way to ensure you have the latest performance optimizations. While it takes longer than a simple apt install, it allows you to enable features like Hyperscan for faster pattern matching. Start by installing the necessary build tools and dependencies.
sudo apt update && sudo apt upgrade -y
sudo apt install -y build-essential autotools-dev libdumbnet-dev libluajit-5.1-dev \
libpcap-dev zlib1g-dev libpcre3-dev libhwloc-dev cmake libssl-dev \
pkg-config liblzma-dev python3-pip uuid-dev libunwind-dev libhyperscan-dev flex bison
2. Installing LibDAQ
The Data Acquisition library (DAQ) acts as the bridge between Snort and your network card. Snort 3 requires a modern version of DAQ to handle multi-threaded traffic processing.
mkdir ~/snort_src && cd ~/snort_src
git clone https://github.com/snort3/libdaq.git
cd libdaq
./bootstrap
./configure
make
sudo make install
sudo ldconfig
3. Compiling Snort 3 with Performance Tweaks
Now for the core installation. We will enable tcmalloc, a memory allocator that can improve Snort’s performance by 10-15% under heavy loads.
cd ~/snort_src
git clone https://github.com/snort3/snort3.git
cd snort3
./configure_cmake.sh --prefix=/usr/local --enable-tcmalloc
cd build
make -j$(nproc)
sudo make install
Confirm the binary is working by running:
/usr/local/bin/snort -V
4. Enabling Promiscuous Mode
Standard interfaces only process packets addressed to them. To inspect all traffic on the wire, you must put your interface into promiscuous mode. Replace eth0 with your specific interface name.
sudo ip link set dev eth0 promisc on
Note that this setting resets after a reboot. For a production environment, you should automate this via a systemd service or netplan configuration.
5. Crafting Your First Detection Rule
Detection logic in Snort is defined by rules. We will create a local rule file to test our engine. This simple rule triggers an alert whenever an ICMP Echo Request (a ping) reaches the server.
sudo mkdir -p /usr/local/etc/rules
sudo nano /usr/local/etc/rules/local.rules
Add this line to the file:
alert icmp any any -> any any (msg:"ICMP Ping Detected"; sid:1000001; rev:1;)
This specific rule breaks down as follows:
- alert: The action Snort takes when the criteria are met.
- icmp: The protocol to inspect.
- any any -> any any: Covers any source IP and port moving to any destination.
- sid: The Snort ID. Custom rules must use IDs above 1,000,000 to avoid conflicts with official rule sets.
6. Integrating Rules into the Lua Configuration
With the rule created, we must tell Snort where to find it. Open the main configuration file, which is written in Lua syntax.
sudo nano /usr/local/etc/snort/snort.lua
Locate the ips table and include your new file path:
ips =
{
include = '/usr/local/etc/rules/local.rules'
}
7. Testing the Detection Engine
Run Snort in the foreground using the alert_fast output plugin. This displays alerts directly on your terminal in real-time.
sudo snort -c /usr/local/etc/snort/snort.lua -i eth0 -A alert_fast
From a different machine, ping your Snort server. Your terminal should immediately populate with alerts like this:
11/15-09:10:45.654321 [**] [1:1000001:1] "ICMP Ping Detected" [**] [Priority: 0] {ICMP} 192.168.1.15 -> 192.168.1.100
Detecting Real-World Exploits
Once basic pings are detected, you can write rules for actual threats. For example, to catch an attacker trying to read your system’s password file via a web browser, use this rule:
alert tcp any any -> any 80 (msg:"Possible Directory Traversal"; content:"/etc/passwd"; nocase; sid:1000002;)
This rule scans the data payload of every HTTP request for the string “/etc/passwd”. This level of visibility is exactly why Snort is a staple in Security Operations Centers (SOCs).
Next Steps
Running a NIDS gives you a granular view of your network health that a firewall simply cannot provide. You have successfully compiled a high-performance engine and implemented custom detection logic.
To move toward a production-grade setup, your next task is to run Snort as a background service and pipe these alerts into a visualization tool like Grafana or an ELK stack. Security is a constant cycle of observation and refinement. By monitoring your traffic, you stay one step ahead of the anomalies that eventually lead to breaches.

