Skip to content

Commit e7977a0

Browse files
committed
update cilium nat46x64gw post
1 parent d11a3c5 commit e7977a0

File tree

5 files changed

+53
-11
lines changed

5 files changed

+53
-11
lines changed

assets/img/dev-lb-slack.png

577 KB
Loading

content/posts/cilium-nat64.md

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ In this blog post I cover how I am running [Cilium](https://cilium.io) as a stan
1818

1919
Before we get to the real meat and potatoes we need to do some prep work.
2020

21-
- Create a VM for the NAT46x64Gateway - I am using Ubuntu 22.04LTS with kernel version 5.15.0-138-generic in my setup.
21+
- Create a VM for the NAT46x64Gateway - I am using Ubuntu 24.04.03 LTS with kernel version 6.8.0-83-generic
2222
- [Install Docker](https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository) on the VM
2323
- Configure networking - A `NAT46x64Gateway` must be dual stacked as it acts as a bridge between IPv4 and IPv6 networks. Here's an example netplan config I am using.
2424

@@ -33,8 +33,8 @@ network:
3333
macaddress: "bc:24:11:ee:19:90"
3434
accept-ra: false
3535
addresses:
36-
- "192.168.2.10/24"
37-
- "2001:db8:abcd::2/64"
36+
- "192.168.64.2/24"
37+
- "2001:db8:46:64::2/64"
3838
nameservers:
3939
addresses:
4040
- "1.1.1.1"
@@ -43,25 +43,59 @@ network:
4343
- to: default
4444
via: "192.168.2.1"
4545
- to: default
46-
via: "2001:db8:abcd::1/64"
46+
via: "2001:db8:46:64::1"
4747
```
4848
4949
To get Cilium up and running as a NAT46x64Gateway simply run the Cilium container image with the following options. Notice that we're running cilium with `enabled-k8s=false`. Also pay special attention to `--devices` flag as it must match the interface name (eth0) from our netplan config above. Traffic entering/leaving this interface will be subject to translation.
5050

5151
```sh
52-
docker run --name cilium-lb -itd \
52+
docker run --name cilium-nat64 -itd \
53+
-v /sys/fs/bpf:/sys/fs/bpf \
54+
-v /lib/modules:/lib/modules \
55+
--privileged=true \
56+
--restart=always \
57+
--network=host \
58+
"quay.io/cilium/cilium:v.17.7" cilium-agent \
59+
--enable-ipv4=true \
60+
--enable-ipv6=true \
61+
--devices=eth0 \
62+
--datapath-mode=lb-only \
63+
--enable-k8s=false \
64+
--bpf-lb-mode=snat \
65+
--enable-nat46x64-gateway=true
66+
```
67+
68+
{{< alert >}}
69+
There was a [breaking change](https://github.com/cilium/cilium/commit/feaf96b4a4804b320c06e498822b777e94ccc9c3) introduced in Cilium v1.18.0 which deprecates the use of `datapath-mode=lb-only` so I reached out to the good folks in #dev-lb on Cilium community slack and the man, the myth, the legend [Daniel Borkman](http://borkmann.ch) was very kind to point me in the right direction. To be honest I wasn't expecting to get my question directly answered by the guy who co-created eBPF amongst many other things in linux networking stack (such as netkit) so it was quite a humbling feeling to say the least 😅
70+
{{< /alert >}}
71+
72+
![Alt Text](img/dev-lb-slack.png)
73+
74+
To run **Cilium v1.18.0 or above as a standalone NAT46x64Gateway**, use the following command
75+
76+
```sh
77+
docker run --name cilium-nat64 -itd \
5378
-v /sys/fs/bpf:/sys/fs/bpf \
5479
-v /lib/modules:/lib/modules \
5580
--privileged=true \
5681
--restart=always \
5782
--network=host \
58-
"quay.io/cilium/cilium:v.17.7" cilium-agent --enable-ipv4=true --enable-ipv6=true --devices=eth0 --datapath-mode=lb-only --enable-k8s=false --bpf-lb-mode=snat --enable-nat46x64-gateway=true
83+
"quay.io/cilium/cilium:stable" cilium-agent \
84+
--enable-ipv4=true \
85+
--enable-ipv6=true \
86+
--devices=eth0 \
87+
--enable-k8s=false \
88+
--bpf-lb-nat46x64=true \
89+
--enable-nat46x64-gateway=true \
90+
--enable-bpf-masquerade \
91+
--enable-node-port=true \
92+
--datapath-mode=netkit
5993
```
6094

61-
To check the status of our standalone cilium install with NAT64 enabled
95+
Let's check to see if cilium-agent successfully enabled NAT64 support or not
6296

6397
```sh
64-
root@nat64gw:~# docker exec -it cilium-lb cilium status --verbose | awk "/NAT46\/64/ {found=1} found"
98+
root@nat64gw:~# docker exec -it cilium-nat64 cilium-dbg status --verbose | awk "/NAT46\/64/ {found=1} found"
6599
NAT46/64 Support:
66100
- Services: Enabled
67101
- Gateway: Enabled
@@ -73,7 +107,6 @@ root@nat64gw:~# docker exec -it cilium-lb cilium status --verbose | awk "/NAT46\
73107
- LoadBalancer: Enabled
74108
- externalIPs: Enabled
75109
- HostPort: Disabled
76-
77110
```
78111

79112
## Test
@@ -100,7 +133,7 @@ network:
100133
- to: default
101134
via: "2001:db8:dead:beef::1"
102135
- to: "64:ff9b::/96"
103-
via: "2001:db8:abcd::2"
136+
via: "2001:db8:46:64::2/64"
104137
```
105138

106139
Few noteworthy points:
@@ -150,4 +183,13 @@ root@testvm# curl -6 -v github.com
150183
* Connection #0 to host github.com left intact
151184
```
152185

153-
Voila!🍾 our Cilium based NAT46x64Gateway is up and running!
186+
Additionally, we can also validate this on our VM that is running the Cilium container.
187+
188+
```sh
189+
root@nat64gw:~# docker exec -it cilium-lb cilium-dbg bpf nat list
190+
191+
TCP IN [64:ff9b::8c52:7104]:80 -> [192.168.64.2]:33388 XLATE_DST [2001:db8:dead:beef::2]:33388 Created=155sec ago NeedsCT=0
192+
TCP OUT [2001:db8:dead:beef::2]:33388 -> [64:ff9b::8c52:7204]:80 XLATE_SRC [192.168.64.2]:33388 Created=155sec ago NeedsCT=0
193+
```
194+
195+
Voila!🍾 this confirms our Cilium based NAT46x64Gateway is up and running!
77.5 KB
Loading
197 KB
Loading
25.9 KB
Loading

0 commit comments

Comments
 (0)