[Openwrt] 编译一个支持NAT1 Fullcone的 Openwrt 镜像

前言

Openwrt 默认是 NAT3,且内核默认不支持 NAT1。搜索了一圈,貌似除了打内核补丁没有太好的方法。 于是在 github 上搜索 openwrt + fullcone 关键字,发现了 https://github.com/mufeng05/openwrt-sonic-fullcone 这个项目,更新日期还是 2 周前,于是想试试看。 本文是记录编译过程。

环境:

Ubuntu 22.04.5 LTS (GNU/Linux 5.15.0-176-generic x86_64) 腾讯云轻量 2C/1G

过程:

  1. 按照官方建议切换到非 root 账户,并更新本地软件包列表

    su ubuntu
    sudo apt update -y
  2. 参考 openwrt 官方文档安装编译依赖, ref: https://openwrt.org/docs/guide-developer/toolchain/install-buildsystem#debianubuntu

    sudo apt install build-essential clang flex bison g++ gawk \
    gcc-multilib g++-multilib gettext git libncurses-dev libssl-dev \
    python3-distutils python3-setuptools rsync swig unzip zlib1g-dev file wget
  3. 官方仓库拉代码,选择当前最新的稳定版本 25.12

    git clone https://github.com/openwrt/openwrt.git
    cd openwrt
    git checkout v25.12.2
  4. 更新并安装所有的基础软件源 (Feeds)

    ./scripts/feeds update -a
    ./scripts/feeds install -a
  5. 一键注入 mufeng05 的 SONiC FullCone 补丁, 脚本会自动识别内核版本并打好底层补丁和 LuCI 界面

    curl -sSL https://raw.githubusercontent.com/mufeng05/openwrt-sonic-fullcone/master/add_sonic_fullcone.sh | bash
  6. [Optional] 到此为止踩了个坑,我VPS的内存太低了,需要扩展虚拟内存,否则vps爆内存会直接失联。

    sudo dd if=/dev/zero of=/swapfile bs=1M count=8192
    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    sudo swapon /swapfile
  7. 最后一步编译,起个 tmux session,等一个小时后再上去看结果。编译产物在 openwrt/bin/targets 目录。

    make menuconfig
    tmux new -s openwrt
    make -j1 V=s # 选择 1c 编译是保守行文,避免编译失败时,由于并行编译导致的错误日志不连贯。比较自信的可尝试 make -j$(nproc) V=s。
    # 查进度
    tmux capture-pane -pt openwrt

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注