> For the complete documentation index, see [llms.txt](https://handbook.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://handbook.bsdcn.org/di-18-zhang-oci-rong-qi/18.17.-gu-zhang-pai-chu.md).

# 18.17.故障排除

## 18.17.1. 软件包升级与挂载的文件

Podman 使用 [mount\_nullfs(8)](https://man.freebsd.org/cgi/man.cgi?query=mount_nullfs\&sektion=8\&format=html) 将 **/etc/resolv.conf** 和 **/etc/hosts** 挂载到容器中。在 [pkg(8)](https://man.freebsd.org/cgi/man.cgi?query=pkg\&sektion=8\&format=html) 操作期间，这些挂载可能导致错误，并出现类似 `Cross-device link` 的消息：

```sh
pkg: Fail to rename /etc/.pkgtemp.hosts.VeIDrHM0sKN5 -> /etc/hosts:Cross-device link
```

要避免此问题，请使用 `--no-hosts` 与 `--dns` 选项：

```sh
# podman run --no-hosts --dns 1.1.1.1 -it --rm \
    ghcr.io/freebsd/freebsd-runtime:15.1 /bin/sh
```

## 18.17.2. 检查网络

从 **/usr/local/etc/containers/pf.conf.sample** 中的防火墙规则开始。在容器内逐步测试连通性：

```sh
# podman run --no-hosts --dns 1.1.1.1 \
    --env ASSUME_ALWAYS_YES=1 \
    -it --rm \
    ghcr.io/freebsd/freebsd-runtime:15.1 \
    /bin/sh

# route show 1.1.1.1
   route to: 1.1.1.1
destination: default
    gateway: 10.88.0.1
  interface: eth0

# ping -c 3 10.88.0.1
PING 10.88.0.1 (10.88.0.1): 56 data bytes
64 bytes from 10.88.0.1: icmp_seq=0 ttl=64 time=0.083 ms
...

# ping -c 3 1.1.1.1
PING 1.1.1.1 (1.1.1.1): 56 data bytes
64 bytes from 1.1.1.1: icmp_seq=0 ttl=60 time=0.920 ms
...

# fetch -v http://1.1.1.1/
...

# pkg -dd bootstrap -r FreeBSD
```

如果 [ping(8)](https://man.freebsd.org/cgi/man.cgi?query=ping\&sektion=8\&format=html) 失败，请检查防火墙规则是否阻止了 ICMP。如果 [fetch(1)](https://man.freebsd.org/cgi/man.cgi?query=fetch\&sektion=1\&format=html) 失败，请检查防火墙规则是否阻止了端口 80 和 443 上的 TCP。如果 [pkg(8)](https://man.freebsd.org/cgi/man.cgi?query=pkg\&sektion=8\&format=html) 失败而 ICMP 和 TCP 正常，则可能是分片或 MTU 问题。将 `set reassemble yes no-df` 添加到 **/etc/pf.conf** 并重启防火墙。

要调试被阻止的数据包，请在 **/etc/pf.conf** 的所有 block 规则上启用 `log`，并在 [pflog(4)](https://man.freebsd.org/cgi/man.cgi?query=pflog\&sektion=4\&format=html) 设备上使用 [tcpdump(1)](https://man.freebsd.org/cgi/man.cgi?query=tcpdump\&sektion=1\&format=html)：

```sh
# service pflog onerestart
# tcpdump -vvveni pflog0 icmp or net 10.88.0.0/16
```

## 18.17.3. MTU 一致性

确保主网络接口、容器网桥和容器自身的 MTU 值保持一致。MTU 值不匹配可能导致数据包分片和连接故障。

下例中，`vtnet0` 的 MTU 为 9000，而网桥和容器的 MTU 为 1500。一般应调整内部布局以与外部网络保持一致：

```sh
# ifconfig vtnet0 mtu 9000
# ifconfig cni-podman0 mtu 9000
```

在容器内：

```sh
# ifconfig eth0 mtu 9000
```
