Operating System Ubuntu

How to Install Snort 3 on an Ubuntu 26.04 LTS VPS or Dedicated Server

Build the Snort 3 intrusion detection system from source on Ubuntu 26.04 LTS, test it with a local rule, add the community ruleset and run it as a service.

This guide builds Snort 3, the current generation of the Snort network intrusion detection system, on Ubuntu 26.04 LTS. At the end you will have Snort installed under /usr/local, a validated configuration, a ruleset that produces alerts, and a systemd service that watches your public network interface. The same steps work on Ubuntu 24.04 LTS.

Building from source is not a matter of taste here. Ubuntu 26.04 has no snort package in its archive at all, and its libdaq-dev package is the old 2.0 series, which Snort 3 cannot use. Ubuntu 24.04 does ship a snort package, but it is the legacy Snort 2.9.20, which uses a different configuration format and rule engine. Snort 3 is distributed by the project as source code on GitHub.

Requirements

  • A server running Ubuntu 26.04 LTS or 24.04 LTS and a user with sudo rights.
  • At least 2 GB of RAM for compiling; the build is slow on a single core.
  • The name of the interface you want to monitor. List interfaces with ip -br addr; this guide uses eth0.

Older tutorials for Ubuntu 18.04 compile a long list of helper libraries by hand (Safe C, gperftools, Ragel, Boost, Hyperscan, FlatBuffers). All of those are optional. The required dependencies are available as Ubuntu packages, so only two things are compiled here: LibDAQ and Snort itself.

Install the build dependencies

Update the system and install the compiler toolchain and the libraries Snort 3 requires: dnet, hwloc, LuaJIT, OpenSSL, pcap, PCRE2 and zlib, plus flex and the autotools for LibDAQ.

sudo apt update
sudo apt upgrade -y
sudo apt install -y build-essential cmake git autoconf automake libtool pkgconf \
  flex bison libdumbnet-dev libhwloc-dev libluajit-5.1-dev libssl-dev \
  libpcap-dev libpcre2-dev zlib1g-dev

Two optional libraries are cheap to add: lzma enables decompression of SWF and PDF content, and uuid is used for unique identifiers.

sudo apt install -y liblzma-dev uuid-dev

Build and install LibDAQ

LibDAQ is the data acquisition library through which Snort reads packets. Snort 3 needs the 3.x series from the Snort project. Check the Snort downloads page for the current version and use its tag; 3.0.29 was current when this was written.

mkdir ~/snort-src
cd ~/snort-src
git clone --depth 1 --branch v3.0.29 https://github.com/snort3/libdaq.git
cd libdaq
./bootstrap
./configure
make -j $(nproc)
sudo make install
sudo ldconfig

The library and its modules are installed under /usr/local/lib. ldconfig refreshes the linker cache so that Snort can find them.

Build and install Snort 3

Clone the release you want (3.13.2.0 at the time of writing), configure it with the bundled script and compile it:

cd ~/snort-src
git clone --depth 1 --branch 3.13.2.0 https://github.com/snort3/snort3.git
cd snort3
./configure_cmake.sh --prefix=/usr/local
cd build
make -j $(nproc)
sudo make install
sudo ldconfig

The configure step prints a feature summary; make sure it reports that DAQ was found. If the compiler is killed during make, the server ran out of memory: rerun with make -j 1 or add swap.

Verify the installation

Print the version banner, which also lists the libraries Snort was linked against:

snort -V

List the packet acquisition modules Snort can see. pcap and afpacket should be among them:

snort --daq-list

If the list is empty, point Snort at the module directory explicitly with --daq-dir /usr/local/lib/daq.

The default configuration is installed as /usr/local/etc/snort/snort.lua, with shared defaults in snort_defaults.lua next to it. Loading it without a packet source validates it:

snort -c /usr/local/etc/snort/snort.lua

The run should end with a message that Snort successfully validated the configuration.

Set your network and test with a local rule

Open /usr/local/etc/snort/snort.lua with sudo and set HOME_NET near the top of the file to the address or network you are protecting, for example:

HOME_NET = '203.0.113.10/32'

Create a rules directory and a file for your own rules:

sudo mkdir -p /usr/local/etc/snort/rules /var/log/snort
sudo nano /usr/local/etc/snort/rules/local.rules

Add a simple rule that fires on any ICMP packet. It is only a test and should be removed afterwards:

alert icmp any any -> $HOME_NET any (msg:"ICMP test"; sid:1000001; rev:1;)

Start Snort in the foreground on your interface. -R loads a rules file and -A alert_fast prints one line per alert to the terminal:

sudo snort -c /usr/local/etc/snort/snort.lua \
  -R /usr/local/etc/snort/rules/local.rules \
  -i eth0 -A alert_fast -q

Ping the server from another machine. Each echo request should produce an alert line containing ICMP test. Stop Snort with Ctrl+C; it prints packet and detection statistics on exit.

Add the community rules

The Snort project publishes a free community ruleset for Snort 3. The larger registered and subscriber rulesets from Cisco Talos require a snort.org account.

cd /tmp
wget https://www.snort.org/downloads/community/snort3-community-rules.tar.gz
sudo tar -xzf snort3-community-rules.tar.gz -C /usr/local/etc/snort/rules/

Rather than passing every file with -R, reference the rules from the configuration. In snort.lua, find the ips table and include the files:

ips =
{
    enable_builtin_rules = true,
    rules = [[
        include /usr/local/etc/snort/rules/local.rules
        include /usr/local/etc/snort/rules/snort3-community-rules/snort3-community.rules
    ]],
}

Validate again; the summary shows how many rules were loaded:

snort -c /usr/local/etc/snort/snort.lua

Run Snort as a service

Snort does not install a systemd unit. Create /etc/systemd/system/snort3.service with the following content, replacing eth0 with your interface:

[Unit]
Description=Snort 3 network intrusion detection
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
ExecStart=/usr/local/bin/snort -c /usr/local/etc/snort/snort.lua -i eth0 -q \
  -l /var/log/snort -A alert_fast --lua "alert_fast = { file = true }"
Restart=on-failure

[Install]
WantedBy=multi-user.target

With file = true the alerts are written to /var/log/snort/alert_fast.txt instead of standard output. Enable and start the service, then check it:

sudo systemctl daemon-reload
sudo systemctl enable --now snort3
systemctl status snort3
sudo tail -f /var/log/snort/alert_fast.txt

In this mode Snort is passive: it reports traffic that matches a rule but does not block it. Rotate the alert file with logrotate and restart the service after each rule update.

Troubleshooting

  • error while loading shared libraries: libdaq.so: run sudo ldconfig. On Ubuntu, /usr/local/lib is already in the linker search path.
  • No alerts on a virtual machine: network cards that merge packets (GRO/LRO) can hide traffic from an IDS. Disable them for the session with sudo ethtool -K eth0 gro off lro off and test again.
  • Rule parse errors: Snort 2 rules are not always valid in Snort 3. Use rulesets published for Snort 3, and convert old configurations with the snort2lua tool that is installed alongside snort.

Frequently asked questions

Why not install Snort with apt?

Ubuntu 26.04 has no Snort package, and the one in Ubuntu 24.04 is Snort 2.9.20. Snort 3 is a rewrite with a Lua configuration, multiple packet threads and its own rule syntax extensions, and upstream ships it as source.

Can Snort block traffic instead of only alerting?

Yes, in inline mode. Snort then sits between two interfaces using the afpacket DAQ (--daq afpacket -i "eth0:eth1" -Q) and drop rules discard packets. On a single-interface VPS, passive detection is the usual setup.

How do I update Snort later?

Fetch the new tags in ~/snort-src/libdaq and ~/snort-src/snort3, or clone them again, and repeat the build and sudo make install steps. Your snort.lua may be overwritten by the install, so keep a copy of your changes, then restart the service.

What do the optional libraries add?

Hyperscan speeds up pattern matching on busy links, FlatBuffers adds a serialisation format, Safe C adds runtime bounds checks and libunwind gives better backtraces. None is needed for a working sensor, and Snort's configure summary shows which ones it found.

Share story:

Continue reading other guides on How VPS.