Skip to content

Forum

AI Assistant
Notifications
Clear all

Step by step: setting up a network tap for the agent's virtual interface.

3 Posts
3 Users
0 Reactions
3 Views
(@homelab_hoarder)
Active Member
Joined: 1 week ago
Posts: 15
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
  [#978]

Hey everyone! I've been absolutely obsessed with monitoring my OpenClaw agents, especially after that last dev diary hinted at emergent autonomy features. I wanted a way to see *everything* my agent does on the network, not just what the host OS logs show. The goal? Catching any sneaky little outbound connection attempts the moment they happen. The best way I found? A good old-fashioned network tap, but on the agent's virtual interface inside my Docker host.

Now, my agents run in Docker with a custom bridge network. The virtual `veth` interfaces are the key. You can't just run `tcpdump` on the container's `eth0` from the host and see everything perfectly—you need to tap the virtual pair. Here's my step-by-step journey to get visibility.

First, I needed to find the virtual interface pair for my agent container. I run my main agent in a container named `nemo-claw-agent-01`.

```bash
# Find the container's process ID
docker inspect nemo-claw-agent-01 --format '{{ .State.Pid }}'

# List the network interfaces associated with that PID
sudo nsenter -t -n ip link show
```

From the container's namespace, note the `eth0` interface index (like `10`). Back in the host's global namespace, I looked for the peer interface index.

```bash
# On the host, find the veth peer. Look for the matching 'ifindex' in the link details.
ip link show | grep -A2 -B2 'if10'
```

Once I had the host-side `veth` name (something like `veth123abc`), I could set up the tap. I used `tcpdump` for a quick test, but for persistent monitoring, I opted for a more robust pipeline with `tshark` and logging to a dedicated analysis VM.

My permanent setup uses a traffic mirroring rule with `tc` (traffic control) to copy all traffic to another interface I created just for capturing, called `mon0`. This way I don't interfere with the agent's performance.

```bash
# Create a dummy interface for the mirrored traffic
sudo ip link add mon0 type dummy
sudo ip link set mon0 up

# Mirror ingress traffic from the agent's veth to mon0
sudo tc qdisc add dev veth123abc handle ffff: ingress
sudo tc filter add dev veth123abc parent ffff: u32 match u32 0 0 action mirred egress mirror dev mon0

# Mirror egress traffic from the agent's veth to mon0
sudo tc qdisc add dev veth123abc handle 1: root prio
sudo tc filter add dev veth123abc parent 1: u32 match u32 0 0 action mirred egress mirror dev mon0
```

Now, I can run my monitoring stack (like a Zeek instance or Suricata) on `mon0`, or just capture all packets to a pcap file for later analysis. The beauty is it's completely out-of-band.

I've set this up for all my agent containers, and I pipe the traffic from `mon0` over a dedicated VLAN to a separate logging VM running Wazuh and a custom anomaly detection script that looks for:
* Unexpected DNS queries to non-whitelisted domains
* Connections to IP ranges outside my allowed cloud regions (like my approved VPS subnet)
* Sudden spikes in data volume, especially on non-standard ports

It's been a fantastic learning project for understanding Linux networking, and it gives me so much peace of mind while I'm letting the agents tinker autonomously. Has anyone else tried a similar deep-monitoring approach for their agents? I'd love to compare notes on anomaly detection rules!

/sj


self-hosted, self-suffering


   
Quote
(@home_lab_anna)
Active Member
Joined: 1 week ago
Posts: 14
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 

Oh, you're spot on about needing to tap the veth pair. Finding that interface index is crucial, but I've found the whole `nsenter` step can be skipped if you use `ip link` on the host directly. The trick is that Docker names the host-side veth with something like `vethabcdef@if10`. That `@if10` is the container's eth0 index you're looking for. So you can just `grep` for your container name in the veth list.

Also, a quick caveat: if you're running tcpdump on that host-side veth for a long time, watch your disk space. Those raw packet captures can balloon fast, especially if your agent is chatty. I set up a ring buffer with `-W 5 -C 100` to keep 5 files of 100MB each.

Love this approach though. It's like having a little CCTV for your agent's network brain. 😄


lab.firstname.net


   
ReplyQuote
(@homelab_sec)
Active Member
Joined: 1 week ago
Posts: 11
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 

Oh, that's a brilliant way to find the index without namespace switching, I hadn't thought of that. I've been using the `nsenter` method every single time like a total newb. Your grep trick for the container name in the veth list is going to save me so much typing.

You're so right about the disk space too, it's terrifying how quickly a curious agent can fill a drive. I was thinking of piping the tcpdump output through something like `tshark` for immediate analysis instead of saving raw packets, but your ring buffer idea seems way more reliable for long-term monitoring without bringing in another tool.

Is there any specific filter you use with tcpdump to cut down on noise, or do you just capture everything and parse it later?


Trust no one, verify every packet.


   
ReplyQuote