Skip to content

Commit 814c689

Browse files
troglobitclaude
andcommitted
Add ENABLE_INTERFACES support to nftables container
Allow nftables container to automatically bring up and down network interfaces via the ENABLE_INTERFACES environment variable. This enables tighter integration with systems like Infix OS where interfaces can be disabled in the configuration but need to be brought up when the firewall container starts. Changes: - rc.local: Bring up interfaces listed in ENABLE_INTERFACES on startup - rc.shutdown: Bring down interfaces on container shutdown - README: Document the new environment variable with usage example Usage: docker run --network=host -e ENABLE_INTERFACES="e1 e24" \ ghcr.io/kernelkit/curios-nftables:latest Fixes #20 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
1 parent 38bb78f commit 814c689

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,26 @@ netfilter management with zero-downtime rule updates. Features:
8383
- **Live configuration** - Built-in vi editor for rule modifications
8484
- **Mount-friendly** - Use host-based config files via volumes
8585
- **Sample configurations** included for end-devices and routers
86+
- **Interface management** - Automatically bring up/down interfaces via `ENABLE_INTERFACES`
8687

8788
Ideal for edge devices, containers-as-firewalls, and advanced network policies.
8889

90+
**Environment variables:**
91+
92+
- `ENABLE_INTERFACES` - Space-separated list of network interfaces
93+
(e.g., `"e1 e24"`) to bring up on startup, after the firewall rules
94+
have been applied, and take down on shutdown before disabling the
95+
firewall
96+
97+
**Example usage:**
98+
99+
```bash
100+
# Start with automatic interface management
101+
docker run --network=host -e ENABLE_INTERFACES="e1 e24" \
102+
-v /path/to/nftables.conf:/etc/nftables.conf:ro \
103+
ghcr.io/kernelkit/curios-nftables:latest
104+
```
105+
89106
See this blog post on how to use this container with Infix:
90107

91108
- [Infix w/ WAN+LAN firewall setup](https://kernelkit.org/posts/firewall-container/)

board/nftables/rootfs/etc/rc.local

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ else
2323
msg="STANDBY -- No active firewall!"
2424
fi
2525

26+
# Enable interfaces if specified via environment variable
27+
if [ -n "$ENABLE_INTERFACES" ]; then
28+
echo "> Enabling interfaces: $ENABLE_INTERFACES"
29+
for iface in $ENABLE_INTERFACES; do
30+
if ip link set dev "$iface" up 2>/dev/null; then
31+
echo "> Interface $iface brought up"
32+
else
33+
echo "> WARNING: Failed to bring up interface $iface"
34+
fi
35+
done
36+
fi
37+
2638
echo "> SYSTEM MONITORING $msg"
2739

2840
exit 0

board/nftables/rootfs/etc/rc.shutdown

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ CONF=/etc/nftables.conf
55

66
echo "> SIGNAL RECEIVED"
77

8+
# Disable interfaces if they were enabled via environment variable
9+
if [ -n "$ENABLE_INTERFACES" ]; then
10+
echo "> Disabling interfaces: $ENABLE_INTERFACES"
11+
for iface in $ENABLE_INTERFACES; do
12+
if ip link set dev "$iface" down 2>/dev/null; then
13+
echo "> Interface $iface brought down"
14+
else
15+
echo "> WARNING: Failed to bring down interface $iface"
16+
fi
17+
done
18+
fi
19+
820
if [ -f "$CONF" ]; then
921
echo "> Flushing nftables ruleset..."
1022
nft flush ruleset

0 commit comments

Comments
 (0)