22title : Gentle Container Introduction
33author : troglobit
44date : 2024-10-15 07:00:00 +0100
5+ last_modified_at : 2026-02-27 12:00:00 +0100
56categories : [showcase]
67tags : [container, containers, networking, docker, podman]
78---
@@ -42,23 +43,24 @@ which is usually hidden from users.
4243
4344## Configuration
4445
45- The Infix configuration consists of two parts: networking setup and the
46- container. We start with the networking, we want a single port as our
47- WAN port, connected to the Internet, and a VETH pair where one end will
48- be handed over to the container.
46+ We start with the networking: a single port as WAN, connected to the
47+ Internet, and a VETH pair where one end will be handed over to the
48+ container.
4949
5050Notice the * DHCP client* on interface ` e1 ` , it is required since we need
5151Internet access to download the container image below.
5252
5353``` console
5454admin@infix:/ > configure
55- admin@infix:/config/ > set dhcp-client client-if e1
55+ admin@infix:/config/ > edit interface e1
56+ admin@infix:/config/interface/e1/ > set ipv4 dhcp
57+ admin@infix:/config/interface/e1/ > end
5658admin@infix:/config/ > edit interface veth0a
5759admin@infix:/config/interface/veth0a/ > set veth peer veth0b
58- admin@infix:/config/interface/veth0a/ > set ipv4 address 192.168.0.1 prefix-length 24
60+ admin@infix:/config/interface/veth0a/ > set ipv4 address 192.168.0.1 prefix-length 30
5961admin@infix:/config/interface/veth0a/ > end
6062admin@infix:/config/ > edit interface veth0b
61- admin@infix:/config/interface/veth0b/ > set ipv4 address 192.168.0.2 prefix-length 24
63+ admin@infix:/config/interface/veth0b/ > set ipv4 address 192.168.0.2 prefix-length 30
6264admin@infix:/config/interface/veth0b/ > set container-network
6365admin@infix:/config/interface/veth0b/ > leave
6466```
@@ -68,25 +70,75 @@ containers.
6870
6971``` console
7072admin@infix:/ > configure
71- admin@infix:/config > edit container system
72- admin@infix:/config/container/system/ > set image docker://ghcr.io/kernelkit/curios:edge
73+ admin@infix:/config/ > edit container system
74+ admin@infix:/config/container/system/ > set image docker://ghcr.io/kernelkit/curios:latest
7375admin@infix:/config/container/system/ > set hostname sys101
76+ admin@infix:/config/container/system/ > set privileged true
7477admin@infix:/config/container/system/ > set network interface veth0b
78+ admin@infix:/config/container/system/ > set volume etc target /etc
79+ admin@infix:/config/container/system/ > set volume var target /var
7580admin@infix:/config/container/system/ > leave
7681```
7782
7883> We don't have to ` leave ` after each of the above sections, we could
7984> just as easily kept going all through the new configuration.
8085 {: .prompt-info }
8186
87+ ## Firewall
88+
89+ To route traffic between the container and the WAN we first enable IP
90+ forwarding on both ends of the VETH pair:
91+
92+ ``` console
93+ admin@infix:/ > configure
94+ admin@infix:/config/ > edit interface veth0a
95+ admin@infix:/config/interface/veth0a/ > set ipv4 forwarding true
96+ admin@infix:/config/interface/veth0a/ > end
97+ admin@infix:/config/ > edit interface veth0b
98+ admin@infix:/config/interface/veth0b/ > set ipv4 forwarding true
99+ admin@infix:/config/interface/veth0b/ > leave
100+ ```
101+
102+ Next, a [ zone-based firewall] [ 8 ] to protect the WAN port and let the
103+ container reach the Internet via masquerade (NAT). The ` containers `
104+ zone covers ` veth0a ` — the host end of the pair — and the policy routes
105+ traffic from there out through the ` public ` zone on ` e1 ` :
106+
107+ ``` console
108+ admin@infix:/ > configure
109+ admin@infix:/config/ > edit firewall
110+ admin@infix:/config/firewall/ > set default public
111+ admin@infix:/config/firewall/ > set zone public action reject
112+ admin@infix:/config/firewall/ > set zone public interface e1
113+ admin@infix:/config/firewall/ > set zone public service ssh
114+ admin@infix:/config/firewall/ > set zone containers action accept
115+ admin@infix:/config/firewall/ > set zone containers interface veth0a
116+ admin@infix:/config/firewall/ > set policy container-access ingress containers
117+ admin@infix:/config/firewall/ > set policy container-access egress public
118+ admin@infix:/config/firewall/ > set policy container-access action accept
119+ admin@infix:/config/firewall/ > set policy container-access masquerade true
120+ admin@infix:/config/firewall/ > leave
121+ ```
122+
123+ If the container runs a service you want reachable from the WAN, add a
124+ port-forward rule to the public zone. Here we forward TCP port 8080 on
125+ the WAN to port 80 in the container:
126+
127+ ``` console
128+ admin@infix:/ > configure
129+ admin@infix:/config/ > edit firewall
130+ admin@infix:/config/firewall/ > set zone public port-forward 8080 proto tcp to addr 192.168.0.2 port 80
131+ admin@infix:/config/firewall/ > leave
132+ ```
133+
82134## The Result
83135
84136We should now have a running container.
85137
86138``` console
87139admin@infix:/ > show container
88- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
89- 1cd99db1f518 ghcr.io/kernelkit/curios:edge 16 hours ago Up 6 seconds system
140+ CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
141+ 1cd99db1f518 ghcr.io/kernelkit/curios:latest 16 hours ago Up 6 seconds system
90142```
91143
92144We can enter the container using:
@@ -104,7 +156,7 @@ lo Link encap:Local Loopback
104156 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
105157
106158eth0 Link encap:Ethernet HWaddr D2:A3:70:0D:50:00
107- inet addr:192.168.0.2 Bcast:192.168.0.255 Mask:255.255.255.0
159+ inet addr:192.168.0.2 Bcast:192.168.0.3 Mask:255.255.255.252
108160 inet6 addr: fe80::d0a3:70ff:fe0d:5000/64 Scope:Link
109161 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
110162 RX packets:63 errors:0 dropped:9 overruns:0 frame:0
@@ -137,3 +189,4 @@ Take care! 🧡
137189[ 5 ] : https://wiki.nftables.org/wiki-nftables/index.php/Main_Page
138190[ 6 ] : https://kernelkit.org/infix/latest/virtual/
139191[ 7 ] : https://github.com/kernelkit/infix/releases/tag/latest
192+ [ 8 ] : /posts/zone-based-firewall/
0 commit comments