Building an Isolated Network Simulation Lab (Incus + INetSim)
- What this builds
- Why a separate VM
- Build
- Gotchas
- Verification
- Operating the lab
- Limitations
- References
Malware Network Behavior Analysis introduces INetSim and FakeNet-NG and sketches the standard two-host topology. This page is the concrete build: a working, reboot-survivable lab on one laptop, using Incus, a non-NATed bridge, and a dedicated INetSim VM.
Everything below was built and verified on real hardware. The gotchas section is the important part — four of the six problems documented there are silent failures that leave you with a lab which looks healthy and intercepts nothing.
What this builds
uplink to the real internet"]):::outside wlan <-->|"NAT"| incusbr(["incusbr0
10.157.65.1/24
ipv4.nat=true"]):::outside incusbr <-->|"DHCP + DNS"| others[["other instances
(win-dev, ...)"]]:::outside end malbr(["malbr0
10.66.6.1/24
ipv4.nat=FALSE"]):::edge end subgraph lab["isolated: no NAT, no DHCP, no route out"] subgraph labchain[" "] direction TB remnux[["remnux
10.66.6.3 (lab0)
victim / analysis box"]]:::victim remnux -->|"gateway + DNS"| inetsim[["inetsim
10.66.6.2 (lab0)
INetSim + dnsmasq + iptables
ip_forward=0"]]:::sim end end %% Invisible link, layout only: puts malbr0 beside the NATed chain %% rather than under it. natchain ~~~ malbr malbr --- lab %% The edge labels above are not decoration: inside a closed subgraph the %% gap between ranks is fixed (rankSpacing has no effect there), and an %% unlabelled edge leaves only 24px -- too little for the two arrowheads %% of a <--> link, which then overlap. A label takes the gap to 72px. style natchain fill:transparent,stroke:transparent style labchain fill:transparent,stroke:transparent style host fill:#23282b,stroke:#7c8a91,color:#eef3f5 style lab fill:#23282b,stroke:#7c8a91,color:#eef3f5 %% Shape carries what a thing IS, colour carries which zone it is in. %% There is no formal standard for "bridge versus VM": network topology %% diagrams conventionally use icon sets (Cisco's, or a cloud vendor's) %% rather than geometry, and ISO 5807 / ANSI X3.5 cover program %% flowcharts, not networks. So this is a convention local to the page, %% applied consistently: %% stadium ([...]) = network plumbing -- an interface or a bridge %% framed [[...]] = a machine -- a VM or an Incus instance %% The framed rectangle is ISO 5807's "predefined process", the nearest %% standard symbol for "a system defined somewhere else". classDef outside fill:#1565c0,stroke:#0d47a1,color:#fff classDef edge fill:#e65100,stroke:#bf360c,color:#fff classDef sim fill:#00695c,stroke:#004d40,color:#fff classDef victim fill:#6a1b9a,stroke:#4a148c,color:#fff
In words, for anyone whose reader does not render the diagram: the host laptop has two Incus bridges. incusbr0 (10.157.65.1/24, ipv4.nat=true) is the normal one — it reaches the internet through wlan0 and serves the other instances. malbr0 (10.66.6.1/24, ipv4.nat=false) is the lab, with no NAT, no DHCP and no route out. Exactly two VMs sit on it: inetsim at 10.66.6.2, running INetSim, dnsmasq, and the iptables redirect with ip_forward=0; and remnux at 10.66.6.3, the victim, which uses inetsim as both gateway and resolver. Neither VM is attached to any other bridge.
The victim’s default route and resolver are both the INetSim VM. That VM has no default route and no second interface, so there is no path to the internet even if the redirect rules are wrong.
Versions this was verified against:
| Component | Version |
|---|---|
| Incus (host) | 7.5.1 |
| INetSim VM | Debian 13 (trixie), kernel 6.12.115 |
| INetSim | 1.3.2+dfsg.1-1 |
| dnsmasq | 2.91-1+deb13u2 |
| Net::DNS | 1.56 |
| REMnux | Ubuntu 24.04.5 LTS |
Why a separate VM
Three placements are possible for the simulated services. The third is the only one that is both safe and maintainable.
On the victim itself (FakeNet-NG in SingleHost mode). Works, and is the only option if you have exactly one machine, but packets from local processes never traverse PREROUTING, so every iptables ... -t nat -A PREROUTING -j REDIRECT recipe you find online silently matches nothing. FakeNet-NG handles this by implementing its own NAT via NFQUEUE, which upstream still labels experimental on Linux. If the sample runs under Wine, this is the layer you would use — Wine has no network stack of its own, so its traffic is ordinary host traffic.
On the host. Tempting, because the host is already the victim’s gateway. But Incus runs its own dnsmasq bound to the bridge address with --bind-interfaces, so INetSim’s DNS service cannot have port 53; the bridge NATs to the internet; and disabling DHCP/DNS on incusbr0 breaks every other instance attached to it. It also terminates malware traffic on your daily driver and runs a dozen listeners there as root.
On a second VM (this page). Isolation stays inside Incus, the lab bridge is yours to configure, the main bridge keeps working, and the whole thing reverts with a snapshot.
Build
1. The isolated bridge
incus network create malbr0 \
ipv4.address=10.66.6.1/24 \
ipv4.nat=false \
ipv4.dhcp=false \
ipv6.address=none
Each setting is load-bearing:
ipv4.nat=false— no masquerade rule, so there is no working path from the lab subnet to the internet.ipv4.dhcp=false— no Incus dnsmasq on this bridge, which leaves port 53 free and forces deterministic static addressing.ipv6.address=none— a v6 path you are not watching is a v6 path you are not blocking.
The host keeps 10.66.6.1 on the bridge. That is for management only (SSH to the VMs); it is deliberately not the victim’s gateway.
2. The INetSim VM
incus launch images:debian/13 inetsim --vm \
-c limits.cpu=1 -c limits.memory=1GiB \
-d root,size=8GiB
It launches on incusbr0 (from the default profile) so it has internet to install packages. That NIC gets removed in step 6.
incus exec inetsim -- apt-get update
incus exec inetsim -- apt-get install -y inetsim iptables dnsmasq
Then attach it to the lab bridge:
incus config device add inetsim eth1 nic network=malbr0 name=eth1
3. Pin the interface name
Do this before writing any config that names an interface. See gotcha 1: removing a NIC renames the remaining one.
incus config get inetsim volatile.eth1.hwaddr # -> 10:66:6a:f9:4f:b6
/etc/systemd/network/10-lab0.link:
[Match]
MACAddress=10:66:6a:f9:4f:b6
[Link]
Name=lab0
/etc/systemd/network/20-lab0.network:
[Match]
Name=lab0
[Link]
# No default route on this link, so networkd never calls it "routable" and
# wait-online would hang forever. "degraded" == addressed but not routable.
RequiredForOnline=degraded
[Network]
DHCP=no
Address=10.66.6.2/24
IPv6AcceptRA=no
LinkLocalAddressing=no
Delete the image’s stock enp5s0.network so DHCP never runs on the lab link.
4. INetSim configuration
Append to /etc/inetsim/inetsim.conf:
service_bind_address 10.66.6.2
redirect_unknown_services yes
and comment out the DNS service, which does not work on current Debian (gotcha 3: INetSim’s DNS service is broken against Net::DNS 1.x):
#start_service dns
Two package defaults are worth knowing about:
service_bind_addressdefaults to127.0.0.1(Default_BindAddressin/usr/share/perl5/INetSim/Config.pm). Left unset, INetSim listens on loopback only and catches nothing from the victim. The sample config’s commented-out10.10.10.1is a suggestion, not the default.redirect_external_address 10.10.10.1ships uncommented in the Debian package. It is inert unless you also defineredirect_static_rule, and it has misled more than one person into thinking redirection was configured. Comment it out.
5. DNS and redirection
INetSim’s own DNS service and its own redirector are both unusable here (gotcha 2: the redirector cannot run and gotcha 3: the DNS service is broken), so dnsmasq does DNS and plain iptables does redirection.
/etc/dnsmasq.d/mallab.conf:
interface=lab0
except-interface=lo
bind-interfaces
listen-address=10.66.6.2
# Never consult a real upstream. Without this, a C2 domain lookup leaks
# to the outside world and tips off the operator.
no-resolv
no-hosts
# Answer every A query for every domain with the INetSim address.
address=/#/10.66.6.2
# Be authoritative for everything, so a type we hold no data for (AAAA)
# returns NODATA instead of REFUSED. See gotcha 4.
local=/#/
# Every lookup is an IOC.
log-queries
log-facility=/var/log/dnsmasq-queries.log
no-dhcp-interface=lab0
/usr/local/sbin/mallab-redirect.sh (mode 0755) sinkholes everything arriving from the lab bridge onto the local listeners:
#!/bin/bash
set -euo pipefail
LAB_IF="lab0"
DUMMY_PORT=1
# INetSim's bound ports. Keep in sync with: ss -tuln | grep 10.66.6.2
# xt_multiport takes at most 15 ports per rule, hence two TCP groups.
TCP_A="1,7,9,13,17,19,21,25,37,79,80,110,113,443,465"
TCP_B="990,995,6667"
UDP_A="1,7,9,13,17,19,37,69,123,514"
iptables -t nat -N MALLAB 2>/dev/null || iptables -t nat -F MALLAB
iptables -t nat -C PREROUTING -i "$LAB_IF" -j MALLAB 2>/dev/null \
|| iptables -t nat -A PREROUTING -i "$LAB_IF" -j MALLAB
# DNS first: a sample with a hardcoded resolver must still reach our dnsmasq.
iptables -t nat -A MALLAB -p udp --dport 53 -j REDIRECT
iptables -t nat -A MALLAB -p tcp --dport 53 -j REDIRECT
# Simulated ports: preserve the port.
iptables -t nat -A MALLAB -p tcp -m multiport --dports "$TCP_A" -j REDIRECT
iptables -t nat -A MALLAB -p tcp -m multiport --dports "$TCP_B" -j REDIRECT
iptables -t nat -A MALLAB -p udp -m multiport --dports "$UDP_A" -j REDIRECT
# Everything else -> dummy service, so the sample gets an answer rather than
# a refusal. A refused connect and a sinkholed one look very different to
# malware that probes for connectivity before unpacking.
iptables -t nat -A MALLAB -p tcp -j REDIRECT --to-ports "$DUMMY_PORT"
iptables -t nat -A MALLAB -p udp -j REDIRECT --to-ports "$DUMMY_PORT"
REDIRECT with no --to-ports keeps the original destination port and only rewrites the destination address to the inbound interface’s address. A sample dialling 203.0.113.9:443 lands on 10.66.6.2:443, where INetSim’s https service is listening. The DNAT happens in PREROUTING, before the routing decision, so the packet becomes locally destined and ip_forward can stay 0.
Unlike the victim-local case, PREROUTING does apply here: this traffic is routed through the gateway rather than originating on it.
Make it persistent with /etc/systemd/system/mallab-redirect.service:
[Unit]
Description=Malware-lab iptables sinkhole rules for the malbr0 bridge
After=network-online.target inetsim.service
Wants=network-online.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/sbin/mallab-redirect.sh
[Install]
WantedBy=multi-user.target
6. Seal both VMs
# turn off forwarding in the INetSim VM: it is a sinkhole, not a router
incus exec inetsim -- sh -c 'echo "net.ipv4.ip_forward = 0" > /etc/sysctl.d/99-no-forward.conf'
# attach the victim to the lab bridge
incus config device add remnux eth1 nic network=malbr0 name=eth1
# then mask the inherited management NIC on both
incus config device add remnux eth0 none
incus config device add inetsim eth0 none
type=none masks a device inherited from a profile — remnux and inetsim both get eth0 from the default profile, so you cannot simply remove it.
incus exec keeps working with no NIC at all, because the Incus agent talks over vsock. You also keep SSH to the victim from the host at 10.66.6.3 across malbr0.
7. Victim configuration
On REMnux (netplan), /etc/netplan/99-mallab.yaml, mode 0600:
network:
version: 2
ethernets:
lab0:
match:
macaddress: "10:66:6a:dd:70:f5"
set-name: lab0
dhcp4: false
dhcp6: false
accept-ra: false
addresses:
- 10.66.6.3/24
routes:
- to: default
via: 10.66.6.2
nameservers:
addresses:
- 10.66.6.2
Move the image’s stock 10-lxc.yaml out of the way, since the management NIC it configures is gone.
8. Fix the boot order
The services bind 10.66.6.2, so they must not start before that address exists. Both of these are needed; see gotcha 5: services race the interface at boot.
/etc/systemd/system/systemd-networkd-wait-online.service.d/lab-iface.conf:
[Service]
ExecStart=
ExecStart=/usr/lib/systemd/systemd-networkd-wait-online --interface=lab0
/etc/systemd/system/inetsim.service.d/wait-for-network.conf:
[Unit]
After=network-online.target
Wants=network-online.target
A Restart=on-failure drop-in for dnsmasq.service is a cheap safety net.
Then snapshot, so a wrecked lab is one command from working:
incus snapshot create inetsim lab-ready
incus snapshot create remnux lab-ready
Gotchas
These are the failures actually hit while building this. Most are silent.
1. Removing a NIC renames the remaining one
Predictable interface names come from the PCI slot. Detaching the management NIC moved the lab NIC from slot 6 to slot 5, so enp6s0 became enp5s0 on the next boot. The running system kept the old name, so everything looked fine until a reboot — at which point the .network file matched nothing, the VM came up with no IPv4 address at all, and every service that binds 10.66.6.2 failed.
Match on MAC and rename to a fixed name (lab0) before writing anything that names an interface. The MAC is stable in volatile.eth1.hwaddr.
2. INetSim’s redirector cannot run on current Debian
redirect_enabled yes fails with:
redirect failed! Error: Sorry, this module requires the perl nfqueue-bindings!
/usr/share/perl5/INetSim/Redirect.pm does use nfqueue — the SWIG-generated nfqueue-bindings, dead upstream for over a decade and not packaged for Debian 13 (apt-cache search nfqueue offers only Go and Ruby bindings). There is no apt-get fix.
Plain iptables ... -j REDIRECT replaces it for sinkhole purposes. What you lose is INetSim’s static rules for routing selected traffic to real external networks, which an isolated lab does not want anyway.
Note this failure appears only in /var/log/inetsim/main.log. The service still reports active, and every other listener starts normally.
3. INetSim’s DNS service is broken against Net::DNS 1.x
main.log claims dns_53_tcp_udp started (PID …), and the process is gone moments later. Nothing binds port 53. Run INetSim in the foreground to see the real error:
Can't locate object method "main_loop" via package "Net::DNS::Nameserver"
at /usr/share/perl5/INetSim/DNS.pm line 69.
INetSim 1.3.2 (2020) calls Net::DNS::Nameserver->main_loop(). Net::DNS 1.56 has no such method — only start_server and stop_server remain. Patching is not worth it: start_server($timeout) forks its listeners and returns immediately, defaults to a 600-second lifetime, and the module’s own POD says it “is not, nor will it ever be, a general-purpose DNS nameserver implementation.”
dnsmasq with address=/#/10.66.6.2 does the same job, is maintained, and gives a cleaner per-query IOC log.
This is the one to check first on any INetSim install, because DNS is the linchpin: without it, domain-based C2 never reaches the sinkhole.
4. no-resolv makes dnsmasq REFUSE AAAA
With no-resolv and only an A-record wildcard, dnsmasq has no upstream and no AAAA data, so AAAA queries return REFUSED (rcode 5):
query[AAAA] totally-fake-c2.test from 10.66.6.3
config error is REFUSED (EDE: not ready)
REFUSED is an anomaly a sample can notice, and clients retry on it. filter-AAAA is not the fix — it produces the same REFUSED. Adding local=/#/ makes dnsmasq authoritative for every domain, after which AAAA returns a normal NODATA (rcode 0, zero answers) while A still answers:
AAAA rcode: 0 answers: 0
A rcode: 0 answers: 1
5. Services race the interface at boot
First reboot: dnsmasq dead, INetSim with 31 failed listeners, nothing bound.
dnsmasq: failed to create listening socket for 10.66.6.2: Cannot assign requested address
Two separate causes, both needing a fix:
- INetSim’s unit is generated from a SysV init script and orders only
After=remote-fs.target— nothing about the network. systemd-networkd-wait-onlinewith no--interfaceis satisfied too early to help.
And then a third, caused by fixing the second: once wait-online is told to wait for lab0 specifically, it waits forever, because the interface has no default route by design and never becomes routable. network-online.target never activates and every service after it stays dead. RequiredForOnline=degraded in the .network file is what unblocks it — degraded means addressed but not routable, which is exactly the intent.
6. systemctl start on an already-running service is a no-op
The Debian package starts INetSim at install time, before you have edited the config. A later systemctl start inetsim does nothing, so the process keeps running with service_bind_address still at 127.0.0.1 while the config on disk says otherwise. Use restart. When a config change seems not to take, check the bind addresses rather than the config file:
ss -tulnp | grep inetsim | head
Verification
Run every one of these. Four of the six gotchas above produce a lab that looks healthy.
# all three services up, listeners bound, rules present
incus exec inetsim -- sh -c 'systemctl is-active inetsim dnsmasq mallab-redirect'
incus exec inetsim -- sh -c 'ss -tuln | grep -c 10.66.6.2' # expect ~30
incus exec inetsim -- sh -c 'iptables -t nat -S MALLAB | wc -l' # expect 8
incus exec inetsim -- sh -c 'sysctl -n net.ipv4.ip_forward' # expect 0
From the victim:
# 1. any domain resolves to the sinkhole
getent hosts c2.evil-domain.test
# 10.66.6.2 c2.evil-domain.test
# 2. HTTP by domain reaches INetSim
curl -s http://c2.evil-domain.test/ | grep -i title
# <title>INetSim default HTML page</title>
# 3. hardcoded IP is redirected
curl -s -o /dev/null -w "HTTP %{http_code}\n" http://203.0.113.9/
# HTTP 200
# 4. non-HTTP protocol on a hardcoded IP
exec 3<>/dev/tcp/198.51.100.7/25 && read -t 6 -r l <&3 && echo "$l"
# 220 mail.inetsim.org INetSim Mail Service ready.
# 5. hardcoded resolver is captured too
dig +short @8.8.8.8 hardcoded.test
# 10.66.6.2
# 6. and the INetSim VM itself has no way out
incus exec inetsim -- sh -c 'timeout 5 sh -c "echo > /dev/tcp/1.1.1.1/443"' \
&& echo LEAK || echo "no route - good"
Test 5 is the one people skip. A sample that ships its own resolver address bypasses your DHCP/netplan DNS entirely, and only the port-53 REDIRECT catches it.
Beware a misleading negative: an early egress check against 93.184.216.34 (the retired example.com address) “fails” on any network, isolated or not. Use 1.1.1.1:443, 8.8.8.8:53, or 9.9.9.9:443.
Note that a successful connection to 1.1.1.1:443 from the victim is the correct result — INetSim is answering. Confirm by content, not by reachability:
curl -s http://1.1.1.1/ | grep -i inetsim
Operating the lab
Revert after a detonation. This is the whole point of the snapshots:
incus snapshot restore remnux lab-ready
Reading the IOCs. Attempted lookups, with source addresses, land in /var/log/dnsmasq-queries.log on the INetSim VM. INetSim’s own service logs and per-session report are under /var/log/inetsim/.
Installing something on a sealed VM. incus exec works over vsock with no NIC, but apt needs a route. Re-attach a management NIC, then remove it again before running a sample:
incus config device add remnux eth0 nic network=incusbr0 name=eth0
# ... apt-get install ...
incus config device add remnux eth0 none
A VM restarted with the management NIC attached will have both a NATed route and the lab route. Do not run a sample in that state.
Adding a simulated port. INetSim’s bound ports are hardcoded in mallab-redirect.sh. After enabling a new start_service, update TCP_A/TCP_B/UDP_A (remember the 15-port multiport limit) and re-run the script — it is idempotent.
Limitations
Host-side forwarding is not explicitly blocked. The victim cannot reach the internet by pointing its default route at the host — verified empirically, with a temporary ip route add default via 10.66.6.1 metric 10 — but that is because ipv4.nat=false means no masquerade, so a 10.66.6.x source address is unroutable upstream. It is not an explicit DROP. The host has ip_forward=1, so SYNs may physically leave wlan0 with a private source address where a passive observer on the LAN could see them.
sudo on this host requires a password, so the host firewall was neither inspected nor modified. To close this properly, run on the host:
sudo iptables -I FORWARD -i malbr0 -j DROP
sudo iptables -I FORWARD -o malbr0 -j DROP
Both commands are untested here. Note also that the host’s iptables is the nf_tables backend (iptables v1.8.13 (nf_tables)), so these write nft rules and will not appear as you typed them under nft list ruleset. Persisting them is a separate exercise, since Incus rewrites its own rules on restart.
Unknown ports get a silent accept. Connections to ports INetSim does not simulate reach the dummy service, which accepts and says nothing. That is better than a refusal for connectivity checks, but it means you cannot tell “sample spoke a protocol we do not simulate” from “sample connected and waited” without a packet capture. Capture on the INetSim VM’s lab0 for anything protocol-specific.
ICMP is not redirected. Pings to arbitrary addresses reach the gateway and are answered or dropped by its kernel, not by INetSim. A sample using ICMP as a covert channel will not be captured by these rules.
Wine remains detectable. If you detonate under Wine on the victim rather than in a Windows guest, a sample that checks for kernel32!wine_get_unix_file_name will know. A quiet capture may mean the sample recognized Wine, not that it has no network behavior. For network-behavior work specifically, prefer a real Windows guest on malbr0; see Dynamic Analysis of Windows Malware from Linux.
This is not a containment boundary for targeted malware. It is an Incus VM on a laptop with a shared kernel on the host side of virtio devices. It is appropriate for coursework and commodity samples, not for anything you believe is hunting for a hypervisor escape.
References
- INetSim — upstream project and documentation
inetsim.conf(5)— full configuration reference- INetSim
Redirect.pmsource — theuse nfqueuedependency behind gotcha 2 Net::DNS::Nameserver— current API, showingmain_loopis gone (gotcha 3)- dnsmasq manual —
address=/#/,local=/#/,filter-AAAA,log-queries - Incus network configuration —
ipv4.nat,ipv4.dhcp, and other bridge options systemd.network(5)—RequiredForOnlineand thedegradedstate (gotcha 5)systemd.link(5)— MAC-matched interface renaming (gotcha 1)- Netplan reference —
match/set-namefor stable victim interface naming - FakeNet-NG internals — why local process traffic skips
PREROUTING - Introducing Linux Support for FakeNet-NG — FLARE on SingleHost vs MultiHost mode