セキュリティ · 5 min read · Jan 10, 2026
Ubuntu 22.04にSnort 3侵入検知システムをインストールして構成する

Snortは、DDoS攻撃から防御するためのオープンソースの侵入防止および検知システム(IDS)です。悪意のあるネットワーク活動を定義するのに役立つ組み込みルールを使用し、それらのルールに一致するパケットを見つけてユーザーにアラートを生成します。Snortは最新の攻撃、マルウェア感染、侵害されたシステム、ネットワークポリシー違反を特定できます。
特徴
- リアルタイムトラフィックモニター。
- パケットログ。プロトコルの分析。
- コンテンツマッチング。OSフィンガープリンティング。
- 任意のネットワーク環境にインストール可能。
- ログを作成します。
このチュートリアルでは、Ubuntu 22.04にSnortをインストールする方法を示します。
前提条件
- Ubuntu 22.04を実行しているサーバー。
- サーバーに設定されたルートパスワード。
必要な依存関係のインストール
始める前に、サーバーにいくつかの依存関係をインストールする必要があります。次のコマンドを実行することで、すべてをインストールできます:
apt install build-essential libpcap-dev libpcre3-dev libnet1-dev zlib1g-dev luajit hwloc libdnet-dev libdumbnet-dev bison flex liblzma-dev openssl libssl-dev pkg-config libhwloc-dev cmake cpputest libsqlite3-dev uuid-dev libcmocka-dev libnetfilter-queue-dev libmnl-dev autotools-dev libluajit-5.1-dev libunwind-dev libfl-dev -yすべての依存関係がインストールされたら、次のステップに進むことができます。
Snort DAQのインストール
次に、システムにデータ取得ライブラリをインストールする必要があります。デフォルトでは、Ubuntuのデフォルトリポジトリにはありません。したがって、ソースからコンパイルする必要があります。
まず、次のコマンドでGitからSnort DAQをダウンロードします:
git clone https://github.com/snort3/libdaq.gitダウンロードが完了したら、ダウンロードしたディレクトリに移動し、次のコマンドで構成します:
cd libdaq
./bootstrap
./configure次の出力が表示されるはずです:
cc: gcc
cppflags:
am_cppflags: -fvisibility=hidden -Wall -Wmissing-declarations -Wpointer-arith -Wcast-align -Wcast-qual -Wformat -Wformat-nonliteral -Wformat-security -Wundef -Wwrite-strings -Wextra -Wsign-compare -Wno-unused-parameter -fno-strict-aliasing -fdiagnostics-show-option
cflags: -g -O2
am_cflags: -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -Wnested-externs
ldflags:
am_ldflags:
libs:
code_coverage_enabled: no
code_coverage_cppflags:
code_coverage_cflags:
code_coverage_ldflags:
Build AFPacket DAQ module.. : yes
Build BPF DAQ module....... : yes
Build Divert DAQ module.... : no
Build Dump DAQ module...... : yes
Build FST DAQ module....... : yes
Build netmap DAQ module.... : no
Build NFQ DAQ module....... : yes
Build PCAP DAQ module...... : yes
Build Savefile DAQ module.. : yes
Build Trace DAQ module..... : yes
Build GWLB DAQ module...... : yes次に、次のコマンドでインストールします:
make
make installGperftoolsのインストール
まず、次のコマンドでGperftoolsの最新バージョンをダウンロードします:
cd
wget https://github.com/gperftools/gperftools/releases/download/gperftools-2.9.1/gperftools-2.9.1.tar.gzダウンロードが完了したら、次のコマンドでダウンロードしたファイルを抽出します:
tar xzf gperftools-2.9.1.tar.gz次に、ダウンロードしたディレクトリに移動し、次のコマンドでコンパイルします:
cd gperftools-2.9.1/
./configure次に、次のコマンドでインストールします:
make
make installSnortのインストール
次に、次のコマンドでSnortの最新バージョンをダウンロードします:
cd
wget https://github.com/snort3/snort3/archive/refs/tags/3.1.43.0.tar.gz次に、次のコマンドでダウンロードしたファイルを抽出します:
tar -xvzf 3.1.43.0.tar.gz次に、抽出したディレクトリに移動し、次のコマンドで構成します:
cd snort3-3.1.43.0
./configure_cmake.sh --prefix=/usr/local --enable-tcmalloc次の出力が表示されます:
snort version 3.1.43.0
Install options:
prefix: /usr/local
includes: /usr/local/include/snort
plugins: /usr/local/lib/snort
Compiler options:
CC: /usr/bin/cc
CXX: /usr/bin/c++
CFLAGS: -fvisibility=hidden -DNDEBUG -g -ggdb -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -O2 -g -DNDEBUG
CXXFLAGS: -fvisibility=hidden -DNDEBUG -g -ggdb -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -O2 -g -DNDEBUG
EXE_LDFLAGS:
MODULE_LDFLAGS:
Feature options:
DAQ Modules: Static (afpacket;bpf;dump;fst;gwlb;nfq;pcap;savefile;trace)
libatomic: System-provided
Hyperscan: OFF
ICONV: ON
Libunwind: ON
LZMA: ON
RPC DB: Built-in
SafeC: OFF
TCMalloc: ON
JEMalloc: OFF
UUID: ON
-------------------------------------------------------
-- Configuring done
-- Generating done
-- Build files have been written to: /root/snort3-3.1.43.0/build次に、ビルドディレクトリに移動し、次のコマンドでSnortをインストールします:
cd build
make
make install
ldconfig次のコマンドを使用してSnortのバージョンを確認できます:
snort -V次の出力が表示されます:
,,_ -*> Snort++ <*-
o" )~ Version 3.1.43.0
'''' By Martin Roesch & The Snort Team
http://snort.org/contact#team
Copyright (C) 2014-2022 Cisco and/or its affiliates. All rights reserved.
Copyright (C) 1998-2013 Sourcefire, Inc., et al.
Using DAQ version 3.0.9
Using LuaJIT version 2.1.0-beta3
Using OpenSSL 3.0.2 15 Mar 2022
Using libpcap version 1.10.1 (with TPACKET_V3)
Using PCRE version 8.39 2016-06-14
Using ZLIB version 1.2.11
Using LZMA version 5.2.5Snortの構成
まず、ネットワークインターフェースをプロミスキャスモードに設定する必要があります。これにより、送信されたすべてのネットワークトラフィックを確認できるようになります。
次のコマンドを使用して設定できます:
ip link set dev eth0 promisc on次のコマンドを使用して確認できます:
ip add sh eth0次に、インターフェースオフロードを無効にする必要があります。まず、次のコマンドを使用してこの機能が有効かどうかを確認します:
ethtool -k eth0 | grep receive-offload次の出力が表示されます:
generic-receive-offload: on
large-receive-offload: off [fixed]次のコマンドを使用して無効にできます:
ethtool -K eth0 gro off lro offSnort NICのためのSystemdサービスファイルの作成
次に、Snort NICのためのsystemdサービスファイルを作成する必要があります。
nano /etc/systemd/system/snort3-nic.service次の行を追加します:
[Unit]
Description=Snort 3 NICをプロミスキャスモードに設定し、起動時にGRO、LROを無効にする
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/sbin/ip link set dev eth0 promisc on
ExecStart=/usr/sbin/ethtool -K eth0 gro off lro off
TimeoutStartSec=0
RemainAfterExit=yes
[Install]
WantedBy=default.targetファイルを保存して閉じたら、次のコマンドを使用してsystemdデーモンを再読み込みして変更を適用します:
systemctl daemon-reload次に、次のコマンドを使用してSnortを開始し、有効にします:
systemctl start snort3-nic.service
systemctl enable snort3-nic.service次のコマンドを使用してSnortのステータスを確認できます:
systemctl status snort3-nic.service次の出力が表示されます:
? snort3-nic.service - Snort 3 NICをプロミスキャスモードに設定し、起動時にGRO、LROを無効にする
Loaded: loaded (/etc/systemd/system/snort3-nic.service; disabled; vendor preset: enabled)
Active: active (exited) since Tue 2022-10-11 16:24:15 UTC; 6s ago
Process: 95745 ExecStart=/usr/sbin/ip link set dev eth0 promisc on (code=exited, status=0/SUCCESS)
Process: 95746 ExecStart=/usr/sbin/ethtool -K eth0 gro off lro off (code=exited, status=0/SUCCESS)
Main PID: 95746 (code=exited, status=0/SUCCESS)
CPU: 11ms
Oct 11 16:24:15 ubuntu2204 systemd[1]: Starting Snort 3 NICをプロミスキャスモードに設定し、起動時にGRO、LROを無効にする...
Oct 11 16:24:15 ubuntu2204 systemd[1]: Finished Snort 3 NICをプロミスキャスモードに設定し、起動時にGRO、LROを無効にする。Snortルールのインストール
ルールは、Snortの侵入検知エンジンにとって非常に重要です。まず、すべてのルールを保存するためのディレクトリを作成します:
mkdir /usr/local/etc/rules次に、次のコマンドでコミュニティルールをダウンロードします:
wget -qO- https://www.snort.org/downloads/community/snort3-community-rules.tar.gz | tar xz -C /usr/local/etc/rules/次に、Snortのメイン構成ファイルを編集します:
nano /usr/local/etc/snort/snort.lua以下のようにネットワークを定義します:
HOME_NET = '192.168.56.124/32'
EXTERNAL_NET = '!$HOME_NET'次に、Snortルールのパスを定義します:
ips =
{
-- デコーダーとインスペクターのアラートを有効にするにはこれを使用します
--enable_builtin_rules = true,
-- ルールファイルのためにincludeを使用します; パスを設定することを忘れないでください
-- ルールファイルは他のルールファイルを含むことができます
-- (snort_defaults.luaの最上部に関連するパス変数も参照)
variables = default_variables,
rules = [[
include /usr/local/etc/rules/snort3-community-rules/snort3-community.rules
]]
}完了したら、ファイルを保存して閉じます。
Snort OpenAppIDのインストール
OpenAppIDは、Snortがネットワークで使用されるさまざまなアプリケーション(Facebook、Netflix、Twitter、Redditなど)を検出できるようにするプラグインです。
次のコマンドでダウンロードできます:
wget https://www.snort.org/downloads/openappid/26425 -O OpenAppId-26425.tgzダウンロードが完了したら、次のコマンドでダウンロードしたファイルを抽出します:
tar -xzvf OpenAppId-26425.tgz次に、OpenAppIDバイナリファイルをシステムディレクトリにコピーします:
cp -R odp /usr/local/lib/次に、Snort構成ファイルを編集し、OpenAppIDの場所を定義します:
nano /usr/local/etc/snort/snort.lua以下の行を変更します:
appid =
{
app_detector_dir = '/usr/local/lib',
log_stats = true,
}ファイルを保存して閉じたら、Snortログディレクトリを作成します:
mkdir /var/log/snort最後に、次のコマンドでSnort構成ファイルを検証します:
snort -c /usr/local/etc/snort/snort.luaすべてが正常であれば、次の出力が表示されます:
--------------------------------------------------
fast pattern groups
src: 59
dst: 158
any: 4
to_server: 56
to_client: 39
--------------------------------------------------
search engine
instances: 316
patterns: 10282
pattern chars: 166369
num states: 112212
num match states: 9885
memory scale: MB
total memory: 3.42574
pattern memory: 0.550588
match list memory: 1.25256
transition memory: 1.58402
fast pattern only: 6822
--------------------------------------------------
pcap DAQ configured to passive.
Snortは構成を正常に検証しました(警告は0)。
o")~ Snort終了Snortカスタムルールの作成
要件に応じて独自のカスタムルールを作成することもできます。着信ICMPリクエストのカスタムルールを作成しましょう:
nano /usr/local/etc/rules/local.rules次の行を追加します:
alert icmp any any -> $HOME_NET any (msg:"ICMP connection test"; sid:1000001; rev:1;)次に、次のコマンドでルールを検証します:
snort -c /usr/local/etc/snort/snort.lua -R /usr/local/etc/rules/local.rules次の出力が表示されます:
search engine
instances: 316
patterns: 10282
pattern chars: 166369
num states: 112212
num match states: 9885
memory scale: MB
total memory: 3.42574
pattern memory: 0.550588
match list memory: 1.25256
transition memory: 1.58402
fast pattern only: 6822
--------------------------------------------------
pcap DAQ configured to passive.
Snortは構成を正常に検証しました(警告は0)。
o")~ Snort終了次に、次のコマンドを実行してカスタムルールを使用してネットワークインターフェースでSnortを開始します:
snort -c /usr/local/etc/snort/snort.lua -R /usr/local/etc/rules/local.rules -i eth0 -A alert_fast -s 65535 -k none次に、別のターミナルインターフェースを開いてサーバーにpingを送信します。最初のターミナルでICMPエラーが表示されるはずです:
10/11-16:45:23.848071 [] [1:1000001:1] "ICMP connection test" [] [Priority: 0] [AppID: ICMP] {ICMP} 157.32.34.228 -> 209.23.11.18
10/11-16:45:23.848071 [] [1:384:8] "PROTOCOL-ICMP PING" [] [Classification: Misc activity] [Priority: 3] [AppID: ICMP] {ICMP} 157.32.34.228 -> 209.23.11.18
10/11-16:45:24.323038 [] [1:366:11] "PROTOCOL-ICMP PING Unix" [] [Classification: Misc activity] [Priority: 3] [AppID: ICMP] {ICMP} 157.32.34.228 -> 209.23.11.18
10/11-16:45:24.323038 [] [1:1000001:1] "ICMP connection test" [] [Priority: 0] [AppID: ICMP] {ICMP} 157.32.34.228 -> 209.23.11.18
10/11-16:45:24.323038 [] [1:384:8] "PROTOCOL-ICMP PING" [] [Classification: Misc activity] [Priority: 3] [AppID: ICMP] {ICMP} 157.32.34.228 -> 209.23.11.18
^C caught int signal
== stopping
10/11-16:45:25.353007 [] [1:366:11] "PROTOCOL-ICMP PING Unix" [] [Classification: Misc activity] [Priority: 3] [AppID: ICMP] {ICMP} 157.32.34.228 -> 209.23.11.18
10/11-16:45:25.353007 [] [1:1000001:1] "ICMP connection test" [] [Priority: 0] [AppID: ICMP] {ICMP} 157.32.34.228 -> 209.23.11.18
10/11-16:45:25.353007 [] [1:384:8] "PROTOCOL-ICMP PING" [**] [Classification: Misc activity] [Priority: 3] [AppID: ICMP] {ICMP} 157.32.34.228 -> 209.23.11.18SnortのためのSystemdサービスファイルの作成
次に、systemdを介してSnortを管理するためのsystemdサービスファイルを作成します。
nano /etc/systemd/system/snort3.service次の構成を追加します:
[Unit]
Description=Snortデーモン
After=syslog.target network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/snort -c /usr/local/etc/snort/snort.lua -s 65535 -k none -l /var/log/snort -D -i eth0 -m 0x1b -u root -g root
ExecStop=/bin/kill -9 $MAINPID
[Install]
WantedBy=multi-user.targetファイルを保存して閉じたら、次のコマンドを使用してsystemdデーモンを再読み込みします:
systemctl daemon-reload次に、次のコマンドを使用してSnortサービスを開始し、有効にします:
systemctl enable --now snort3次のコマンドを使用してSnortのステータスを確認できます:
systemctl status snort3次の出力が表示されます:
? snort3.service - Snortデーモン
Loaded: loaded (/etc/systemd/system/snort3.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2022-10-11 16:48:28 UTC; 17s ago
Main PID: 95898 (snort)
Tasks: 2 (limit: 4579)
Memory: 233.6M
CPU: 2.007s
CGroup: /system.slice/snort3.service
??95898 /usr/local/bin/snort -c /usr/local/etc/snort/snort.lua -s 65535 -k none -l /var/log/snort -D -i eth0 -m 0x1b -u root -g >
Oct 11 16:48:29 ubuntu2204 snort[95898]: num match states: 9885
Oct 11 16:48:29 ubuntu2204 snort[95898]: memory scale: MB
Oct 11 16:48:29 ubuntu2204 snort[95898]: total memory: 3.42574
Oct 11 16:48:29 ubuntu2204 snort[95898]: pattern memory: 0.550588
Oct 11 16:48:29 ubuntu2204 snort[95898]: match list memory: 1.25256
Oct 11 16:48:29 ubuntu2204 snort[95898]: transition memory: 1.58402
Oct 11 16:48:29 ubuntu2204 snort[95898]: fast pattern only: 6822
Oct 11 16:48:29 ubuntu2204 snort[95898]: --------------------------------------------------
Oct 11 16:48:29 ubuntu2204 snort[95898]: pcap DAQ configured to passive.
Oct 11 16:48:29 ubuntu2204 snort[95898]: Commencing packet processing結論
おめでとうございます! Ubuntu 22.04にSnort 3を正常にインストールして構成しました。これで、組織にSnortを実装し、DDoS攻撃から保護できます。質問があればお気軽にお尋ねください。
新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。