Router setup
Juniper SRX
Export J-Flow v9 from a Juniper SRX to Heimnull, and stream its NAT session logs so every flow through NAT names the internal host.
This sets up two things:
- Flows (J-Flow v9) on the internet (WAN) interface only. Each packet is counted once: inbound on input, outbound on output.
- Session logs for every session that crosses NAT, so Heimnull knows which internal host is behind the public address in each WAN flow. This is the NAT from session logs switch on the exporter in Heimnull.
Without session logs, WAN flows show only the public address, and sampling the LAN side as well counts traffic twice. Sampled LAN flows still wouldn’t tie the two sides together, because port translation changes the ports.
The examples use these addresses. Replace them with your own:
| In the examples | Value |
|---|---|
| Heimnull | 10.0.0.10 |
| SRX (LAN address, the flows’ source) | 10.0.0.1 |
| WAN interface | ge-0/0/0.0 |
| LAN | 10.0.0.0/24 on irb.0 |
| Public block | 198.51.100.0/29 |
Flow export
Section titled “Flow export”Sample on the WAN unit only, on input and output, for IPv4 and IPv6:
set forwarding-options sampling instance NETFLOW input rate 100set forwarding-options sampling instance NETFLOW family inet output flow-server 10.0.0.10 port 2055 version9 template NF-V4set forwarding-options sampling instance NETFLOW family inet output inline-jflow source-address 10.0.0.1set forwarding-options sampling instance NETFLOW family inet6 output flow-server 10.0.0.10 port 2055 version9 template NF-V6set forwarding-options sampling instance NETFLOW family inet6 output inline-jflow source-address 10.0.0.1set interfaces ge-0/0/0 unit 0 family inet sampling inputset interfaces ge-0/0/0 unit 0 family inet sampling outputset interfaces ge-0/0/0 unit 0 family inet6 sampling inputset interfaces ge-0/0/0 unit 0 family inet6 sampling outputThe two templates the sampling instance names, with short timeouts so detection isn’t kept waiting (check on your release: the statement names and the allowed ranges):
set services flow-monitoring version9 template NF-V4 flow-active-timeout 30set services flow-monitoring version9 template NF-V4 flow-inactive-timeout 10set services flow-monitoring version9 template NF-V4 template-refresh-rate seconds 60set services flow-monitoring version9 template NF-V4 ipv4-templateset services flow-monitoring version9 template NF-V6 flow-active-timeout 30set services flow-monitoring version9 template NF-V6 flow-inactive-timeout 10set services flow-monitoring version9 template NF-V6 template-refresh-rate seconds 60set services flow-monitoring version9 template NF-V6 ipv6-template- Don’t add
samplingtoirb.0or the other LAN units: that counts traffic twice. - In Heimnull, set the interfaces’ roles (Configure → Interface settings):
ge-0/0/0.0as Transit, andirb.0and any other LAN units as Internal. - Add your public block to Networks.
- Add the private LAN too if you want those hosts on host pages under their own hostgroup. NAT correlation works either way.
Session logs to Heimnull
Section titled “Session logs to Heimnull”Stream mode sends logs from the data plane, directly to Heimnull. The source address must be the one the flows come from, because Heimnull matches logs to the exporter by it.
set security log mode streamset security log format sd-syslogset security log source-address 10.0.0.1set security log stream heimnull format sd-syslogset security log stream heimnull category allset security log stream heimnull host 10.0.0.10 port 5514- Check on your release: some releases take
host 10.0.0.10andhost port 5514as separate statements. - Port. UDP 5514 is Heimnull’s default (
HN_SESSIONLOG_PORT). Heimnull opens it only while at least one exporter has NAT from session logs on. Allow it in the firewall from the SRX. - Category.
allalso sends screen and IDP messages; Heimnull ignores everything except session create and close, and counts the rest as ignored. Check whether your release offers a narrower session category. - Format.
sd-syslog(RFC 5424 structured data) is the format Heimnull reads.syslogandbinaryaren’t supported.
Log the sessions that cross NAT
Section titled “Log the sessions that cross NAT”A session is logged only if its policy says so. Heimnull needs both the start (session-init) and the end (session-close):
- The start gives the translation while the session is still running. Flow records arrive long before a session closes.
- The end lets Heimnull drop the translation soon after the session finishes.
List the policies that permit traffic:
show configuration security policies | display set | match "then permit"Then, for each policy that permits traffic crossing NAT, add both logs:
set security policies from-zone trust to-zone untrust policy <name> then log session-init session-closeset security policies from-zone dmz to-zone untrust policy <name> then log session-init session-closeset security policies from-zone untrust to-zone trust policy <name> then log session-init session-close- Outbound policies (trust or dmz to untrust) cover traffic through source NAT.
- Inbound policies (untrust to trust) cover your port forwards (destination NAT).
- Not needed: policies between internal zones, or into GRE and IPsec tunnels, where there’s no NAT. Sessions without NAT are counted as “without NAT” and otherwise ignored.
Commit with commit check first, then commit confirmed 5, so a mistake rolls itself back.
Turn it on in Heimnull
Section titled “Turn it on in Heimnull”Configure → Exporters → the SRX → NAT from session logs. The exporter then shows:
- how many messages arrived, and how many carried NAT;
- when the last one arrived;
- how many translations are held;
- of the flows of NAT addresses, the share that matched a translation, outbound and inbound. Inbound flows without one are mostly unsolicited traffic (scans) that the firewall dropped, which opens no session. Flows of addresses without NAT (routed IPv6, public hosts) are counted apart and need none. ICMP and fragments match by addresses.
Detection and mitigation still act on the public address, since that’s what’s routed to you. Host pages and flow records show the internal host.
Check it
Section titled “Check it”On the SRX:
show security flow session nat # live translationsshow security log stream statistics # check on your releaseOn the Heimnull host, a few messages should arrive within seconds of browsing from the LAN:
sudo tcpdump -n -A -c 5 udp port 5514In Heimnull:
- A host behind NAT appears in flow records as
public → internal. - Its host page (open the internal address) lists its traffic.
Notes and limits
Section titled “Notes and limits”- Volume. Two messages per session. A busy office of a few hundred hosts sends tens of messages a second, far below what the listener handles. Heimnull keeps each translation until 3 minutes after its session closes, for late flow records, and at most 24 hours if the close is lost.
- UDP loss. A lost start leaves that session’s flows without the internal host until its close arrives. A lost close makes the translation last up to 24 hours, which is harmless.
- IPv6 is usually routed, not translated: its flows already show the internal host and need no logs.
- Tunnels. Traffic inside GRE and IPsec tunnels isn’t sampled on the WAN unit (only the outer packets are), so it isn’t in the flows either.
- Security. Logs are accepted only from the address of an approved exporter with the switch on. Anything else is counted as “unknown source” and dropped.