Difficulty: Beginner Time: 10 minutes Prerequisites: Tutorial 1 completed, root access
- How to block outbound connections by IP and CIDR
- How to block specific ports and protocols
- How to use direction-aware rules (egress vs bind)
- How to read network block events
# Start in audit mode first
sudo aegisbpf daemon --audit-onlyCreate a policy that blocks connections to a test IP:
cat > /tmp/aegis-net-policy.conf <<'EOF'
version=1
# Block outbound connections to specific IPs
[deny_ip]
# Example: Block connections to a known mining pool
93.184.216.34
# Block entire CIDR ranges
[deny_cidr]
# Example: Block RFC5737 documentation range
198.51.100.0/24
EOF
sudo aegisbpf policy apply /tmp/aegis-net-policy.conf# Try to connect to the blocked IP
curl -m 5 http://93.184.216.34/ 2>&1 || true
# Check the daemon logs for a network block event:
# {"type":"net_connect_block","remote_ip":"93.184.216.34","remote_port":80,...}Block specific ports with protocol and direction:
cat > /tmp/aegis-net-policy.conf <<'EOF'
version=1
[deny_port]
# Block FTP outbound (port 21, TCP, egress only)
21:tcp:egress
# Block Telnet outbound
23:tcp:egress
# Block IRC (common C2 channel)
6667:tcp:egress
# Block a port for both TCP and UDP, all directions
9999:any:both
EOF
sudo aegisbpf policy apply /tmp/aegis-net-policy.confTest:
# This should generate a block event
curl -m 5 ftp://ftp.example.com/ 2>&1 || trueReal-world policies combine file and network rules:
cat > /tmp/aegis-combined-policy.conf <<'EOF'
version=1
# Protect sensitive files
[deny_path]
/etc/shadow
/root/.ssh/id_rsa
# Block dangerous outbound ports
[deny_port]
21:tcp:egress
23:tcp:egress
# Block known malicious infrastructure
[deny_cidr]
# Example: Block connections to a suspicious network
203.0.113.0/24
# Block kernel tampering
[deny_ptrace]
[deny_module_load]
EOF
sudo aegisbpf policy apply /tmp/aegis-combined-policy.conf# View network-specific metrics
sudo aegisbpf metrics | grep net_blockOutput shows blocks broken down by type:
aegisbpf_net_blocks_total{type="connect"} 3
aegisbpf_net_blocks_total{type="bind"} 0
aegisbpf_net_blocks_total{type="sendmsg"} 1
| Direction | Meaning | Hooks |
|---|---|---|
egress |
Outbound connections | socket_connect, socket_sendmsg |
bind |
Listening on a port | socket_bind, socket_listen |
both |
Both directions | All socket hooks |
rm /tmp/aegis-net-policy.conf /tmp/aegis-combined-policy.conf- Tutorial 3: Writing Custom Policies
- Tutorial 4: Debugging Policy Denials