Commit 2581a62
committed
fix: implement two-pronged DNS strategy for robust resolution
## DNS Strategy Overview
Run TWO DNS servers to handle all /etc/resolv.conf configurations:
1. **Namespace DNS server** (separate process in namespace):
- Binds to loopback addresses (127.0.0.53, 127.0.0.54)
- Handles queries when /etc/resolv.conf points to loopback (systemd-resolved)
- These queries never leave namespace, so DNAT doesn't apply
2. **Host DNS server** (runs in main jail process):
- Binds to host_ip:53 on host side of veth pair
- Handles queries to external nameservers (e.g., 8.8.8.8)
- DNAT redirects outbound DNS queries to this server
- Works because DNAT to localhost fails for locally-generated packets
## Changes
- dns.rs: Update namespace server to bind only to loopback addresses
- mod.rs: Add host_dns_server field, start both servers with detailed comments
- nftables.rs: Allow both host_ip and loopback DNS, redirect external queries
- main.rs: Pass host_ip to namespace DNS server process
This approach works regardless of /etc/resolv.conf configuration.1 parent 78929a3 commit 2581a62
4 files changed
Lines changed: 96 additions & 31 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
156 | 159 | | |
157 | 160 | | |
158 | 161 | | |
159 | | - | |
160 | | - | |
161 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
162 | 166 | | |
163 | 167 | | |
164 | 168 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
| |||
82 | 84 | | |
83 | 85 | | |
84 | 86 | | |
| 87 | + | |
85 | 88 | | |
86 | 89 | | |
87 | 90 | | |
| |||
362 | 365 | | |
363 | 366 | | |
364 | 367 | | |
365 | | - | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
366 | 387 | | |
367 | 388 | | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
368 | 393 | | |
| 394 | + | |
369 | 395 | | |
370 | | - | |
| 396 | + | |
371 | 397 | | |
372 | 398 | | |
373 | 399 | | |
374 | | - | |
375 | | - | |
376 | 400 | | |
377 | 401 | | |
378 | 402 | | |
| |||
382 | 406 | | |
383 | 407 | | |
384 | 408 | | |
| 409 | + | |
385 | 410 | | |
386 | 411 | | |
387 | 412 | | |
388 | 413 | | |
389 | 414 | | |
390 | 415 | | |
391 | 416 | | |
392 | | - | |
393 | | - | |
| 417 | + | |
394 | 418 | | |
395 | 419 | | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
396 | 435 | | |
397 | 436 | | |
398 | 437 | | |
399 | | - | |
| 438 | + | |
400 | 439 | | |
| 440 | + | |
401 | 441 | | |
402 | | - | |
| 442 | + | |
403 | 443 | | |
404 | 444 | | |
405 | | - | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
406 | 451 | | |
407 | 452 | | |
408 | 453 | | |
| |||
580 | 625 | | |
581 | 626 | | |
582 | 627 | | |
| 628 | + | |
583 | 629 | | |
584 | 630 | | |
585 | 631 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
133 | 135 | | |
134 | 136 | | |
135 | 137 | | |
| |||
145 | 147 | | |
146 | 148 | | |
147 | 149 | | |
148 | | - | |
149 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
150 | 157 | | |
151 | 158 | | |
152 | 159 | | |
153 | 160 | | |
154 | 161 | | |
155 | 162 | | |
156 | 163 | | |
157 | | - | |
| 164 | + | |
158 | 165 | | |
159 | 166 | | |
160 | 167 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
323 | 331 | | |
324 | 332 | | |
325 | 333 | | |
| |||
0 commit comments