Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision | |||
| virtualization:lxd:docker-firewall-conflict [2026/09/28 02:50] – removed - external edit (Unknown date) 127.0.0.1 | virtualization:lxd:docker-firewall-conflict [2026/09/28 02:50] (current) – ↷ Page moved and renamed from self:lxd-docker-firewall-conflict to virtualization:lxd:docker-firewall-conflict ilyasa | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== LXD / Incus ↔ Docker — Konflik Firewall ====== | ||
| + | |||
| + | ===== Permasalahan ===== | ||
| + | Ketika Docker dan LXD/Incus berjalan bersama di satu host, **Docker akan mengatur policy chain iptables `FORWARD` | ||
| + | menjadi `DROP`** dan hanya meng-ACCEPT trafik untuk bridge miliknya sendiri. Paket forward dari bridge incus/lxd | ||
| + | (`lxdbr0`) tidak cocok dengan rule apapun sehingga jatuh ke policy DROP tadi, sehingga **container/ | ||
| + | kehilangan akses internet keluar (outbound)** — walaupun host itu sendiri baik-baik saja dan bridge LXD sudah | ||
| + | punya `ipv4.nat=true`. Solusinya adalah meng-ACCEPT bridge LXD di dalam chain `DOCKER-USER` milik Docker, lalu | ||
| + | membuatnya persistent (bertahan setelah reboot). | ||
| + | |||
| + | <WRAP center round important 60%> | ||
| + | PENTING: Ini **bukan** masalah NAT, DNS, atau konfigurasi LXD. `ipv4.nat=true` dan `net.ipv4.ip_forward=1` | ||
| + | pada bridge sudah benar — paket di-drop pada hook `FORWARD` sebelum proses NAT sempat berjalan. Jangan buang | ||
| + | waktu mengutak-atik ulang bridge, DNS, atau `lxd init`. | ||
| + | </ | ||
| + | |||
| + | ===== Diagnosa ===== | ||
| + | |||
| + | * Di dalam container Inucs/LXD, `apt update` / `apt-get` / `curl` **timeout** pada IPv4 (`connection timed out`, `Failed to fetch`) dan/atau langsung muncul `Network is unreachable` pada IPv6. | ||
| + | * Request yang **sama persis berhasil dijalankan dari host.** | ||
| + | * Build image `packer-lxd` error di provisioner shell pertama pada `apt update` -> `Failed to fetch ... Could not connect ... connection timed out`. | ||
| + | * Masalah muncul tepat setelah **Docker diinstall** di host LXD tersebut (atau setelah upgrade Docker yang menerapkan ulang rule-nya). | ||
| + | ===== Pemeriksaan ===== | ||
| + | |||
| + | ==== 1. Test Connectivity dari VM / Container ==== | ||
| + | |||
| + | Lakukan pengujian konektivitas dari VM atau container yang mengalami masalah. | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | Hasil pengujian menunjukkan VM/ | ||
| + | gateway dan jaringan luar. | ||
| + | |||
| + | ==== 2. Pemeriksaan Firewall | ||
| + | |||
| + | Periksa policy `FORWARD`: | ||
| + | |||
| + | <code bash> | ||
| + | sudo iptables -S FORWARD | ||
| + | </ | ||
| + | |||
| + | Periksa chain Docker: | ||
| + | |||
| + | <code bash> | ||
| + | sudo iptables -S DOCKER-USER | ||
| + | </ | ||
| + | |||
| + | Pemeriksaan NAT: | ||
| + | <code bash> | ||
| + | iptables -t nat -L POSTROUTING -n -v | ||
| + | </ | ||
| + | |||
| + | Pastikan IP forwarding aktif: | ||
| + | |||
| + | <code bash> | ||
| + | sysctl net.ipv4.ip_forward | ||
| + | </ | ||
| + | |||
| + | |||
| + | {{ : | ||
| + | |||
| + | * Firewall forward | ||
| + | * Sementara traffic dari network LXD/Incus `10.14.3.0/ | ||
| + | * dan juga status | ||
| + | ===== Penyebab ===== | ||
| + | Firewall Docker menggunakan policy **FORWARD DROP** pada host. | ||
| + | |||
| + | Traffic dari `incusbr0` kemudian tidak mendapatkan rule `ACCEPT` yang memungkinkan traffic masuk dan keluar melalui bridge Incus. | ||
| + | |||
| + | Akibatnya: | ||
| + | |||
| + | < | ||
| + | Incus Container | ||
| + | 10.14.3.x | ||
| + | | | ||
| + | v | ||
| + | incusbr0 | ||
| + | 10.14.3.1 | ||
| + | | | ||
| + | X | ||
| + | Docker Firewall / FORWARD DROP | ||
| + | | | ||
| + | X | ||
| + | 8.8.8.8 / Internet | ||
| + | </ | ||
| + | ===== Solusi ===== | ||
| + | |||
| + | Tambahkan rule `ACCEPT` pada chain `DOCKER-USER`. | ||
| + | |||
| + | Untuk LXD: | ||
| + | |||
| + | <code bash> | ||
| + | sudo iptables -I DOCKER-USER -i lxdbr0 -j ACCEPT | ||
| + | sudo iptables -I DOCKER-USER -o lxdbr0 -j ACCEPT | ||
| + | </ | ||
| + | |||
| + | Untuk Incus: | ||
| + | |||
| + | <code bash> | ||
| + | sudo iptables -I DOCKER-USER -i incusbr0 -j ACCEPT | ||
| + | sudo iptables -I DOCKER-USER -o incusbr0 -j ACCEPT | ||
| + | </ | ||
| + | |||
| + | Sesuaikan nama bridge dengan konfigurasi yang digunakan. | ||
| + | |||
| + | Periksa kembali rule: | ||
| + | |||
| + | <code bash> | ||
| + | sudo iptables -S DOCKER-USER | ||
| + | </ | ||
| + | |||
| + | Now it should be bertambah 2 rules: | ||
| + | <code bash> | ||
| + | -N DOCKER-USER | ||
| + | -A DOCKER-USER -o incusbr0 -j ACCEPT | ||
| + | -A DOCKER-USER -i incusbr0 -j ACCEPT | ||
| + | </ | ||
| + | ===== Verifikasi ===== | ||
| + | |||
| + | Setelah rule diterapkan, lakukan kembali test connectivity dari VM/ | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | Kemudian lakukan pengujian akses Internet: | ||
| + | |||
| + | <code bash> | ||
| + | curl -4I https:// | ||
| + | </ | ||
| + | |||
| + | Jika menggunakan Debian/ | ||
| + | |||
| + | <code bash> | ||
| + | apt update | ||
| + | </ | ||
| + | |||
| + | Test: | ||
| + | <code bash> | ||
| + | root@sandbox-cloud: | ||
| + | HTTP/2 200 | ||
| + | server: Apache | ||
| + | x-content-type-options: | ||
| + | x-frame-options: | ||
| + | referrer-policy: | ||
| + | x-xss-protection: | ||
| + | permissions-policy: | ||
| + | last-modified: | ||
| + | etag: " | ||
| + | x-clacks-overhead: | ||
| + | content-type: | ||
| + | backend: 4qpvL1tJyeV1P6Tmf0Lj8g--F_static_backend | ||
| + | accept-ranges: | ||
| + | date: Sun, 27 Sep 2026 19:36:15 GMT | ||
| + | via: 1.1 varnish | ||
| + | age: 49 | ||
| + | x-served-by: | ||
| + | x-cache: HIT | ||
| + | x-cache-hits: | ||
| + | x-timer: S1790537776.879989, | ||
| + | vary: Accept-Encoding | ||
| + | content-length: | ||
| + | |||
| + | root@sandbox-cloud: | ||
| + | Hit:1 http:// | ||
| + | Hit:2 http:// | ||
| + | Get:3 http:// | ||
| + | Get:4 http:// | ||
| + | Get:5 http:// | ||
| + | Fetched 468 kB in 0s (1179 kB/s) | ||
| + | All packages are up to date. | ||
| + | root@sandbox-cloud: | ||
| + | </ | ||
| + | |||
| + | ===== Persistensi Konfigurasi ===== | ||
| + | |||
| + | Rule `iptables` yang dibuat secara manual dapat hilang setelah reboot. | ||
| + | |||
| + | Buat systemd service: | ||
| + | |||
| + | <code bash> | ||
| + | / | ||
| + | </ | ||
| + | |||
| + | <code ini> | ||
| + | [Unit] | ||
| + | Description=Allow LXD/Incus bridge through Docker firewall | ||
| + | After=docker.service | ||
| + | Wants=docker.service | ||
| + | |||
| + | [Service] | ||
| + | Type=oneshot | ||
| + | RemainAfterExit=yes | ||
| + | |||
| + | ExecStart=/ | ||
| + | ExecStart=/ | ||
| + | |||
| + | [Install] | ||
| + | WantedBy=multi-user.target | ||
| + | </ | ||
| + | |||
| + | Untuk Incus, ganti `lxdbr0` dengan nama bridge Incus yang digunakan. | ||
| + | |||
| + | Aktifkan service: | ||
| + | |||
| + | <code bash> | ||
| + | sudo systemctl daemon-reload | ||
| + | sudo systemctl enable --now lxd-docker-forward.service | ||
| + | </ | ||
| + | |||