用途:处理 Linux 网络任务,包括用 Netplan 配置 IP、用 UFW 或 Nftables 管理防火墙、设置 DNS、配置 Wireguard 或 Tailscale VPN,以及在 System76 等系统上做实例间路由。适用场景为 Ubuntu/Debian 服务器搭建、用防火墙保护应用、通过 VPN 建立安全远程访问、排查容器环境 DNS 问题,或优化数据中心与边缘设备间的路由。
主要能力:用 Netplan YAML 配置静态/动态 IP;用 UFW 管理简单规则或用 Nftables 做高级包过滤;用 systemd-resolved 或编辑 /etc/resolv.conf 处理 DNS;用 wg-quick 搭建 Wireguard 点对点隧道,或用 Tailscale 做带密钥认证的自动网状网络;在 System76 硬件上通过 OSPF 或静态路由实现多设备通信。
使用方式:命令通常需 sudo。脚本中先检查 NetworkManager 或 systemd-networkd 是否运行,敏感数据用环境变量,如 export TAILSCALE_API_KEY=$SERVICE_API_KEY。任务按顺序执行:先校验配置文件,再应用更改,最后用诊断工具验证。自动化时用 bash 脚本并加 set -e 做错误检查。
常用命令:Netplan 编辑 /etc/netplan/01-netcfg.yaml 后运行 sudo netplan apply;UFW 用 sudo ufw enable、sudo ufw allow 22/tcp、sudo ufw status verbose;Nftables 用 sudo nft -f /etc/nftables.conf;DNS 可编辑 /etc/resolv.conf 或使用 systemd-resolve --set-dns=8.8.8.8 eth0;Wireguard 用 wg genkey | tee privatekey | wg pubkey > publickey 生成密钥,配置 /etc/wireguard/wg0.conf 后 sudo wg-quick up wg0;Tailscale 用 tailscale up --authkey $TAILSCALE_API_KEY;路由用 sudo ip route add 192.168.1.0/24 via 10.0.0.1。
集成与限制:可与 Ansible 模块、systemd 服务集成;Netplan 需停用 NetworkManager。错误处理包括用 yamllint 校验 YAML、用 ss -tuln 查端口冲突、用 wg show 和 journalctl 排查 VPN、用 ip route show 诊断路由。资料未提供具体收费、价格或平台支持范围。