软路由 | 自编译OpenWrt官方最新固件
说明: 之前陆陆续续使用过不少基于 OpenWrt 编译的固件都差强人意,不是插件太多了就是少了自己需要的插件。而抽屉里又发现了自己吃灰良久的树莓派4B,突发奇想不如通过自行定制插件编译固件作为软路由使用,也才有了今天的文章,当然各位老板可以根据自己的设备选择相应的编译固件如X86。

编译环境准备
系统准备
#本次编译使用的系统为ubuntu 20.04 (推荐系统)
网络准备
#因编译过程中需要下载大量的文件,部分文件需要梯子上网。
创建普通用户
#不能使用 root 用户进行编译,所以要先准备一个普通账户。
更新本地环境
sudo apt update

sudo apt upgrade -y

安装依赖ubuntu 20.04
sudo apt-get -y install build-essential asciidoc binutils bzip2 gawk gettext git libncurses5-dev libz-dev patch python3 python2.7 unzip zlib1g-dev lib32gcc1 libc6-dev-i386 subversion flex uglifyjs git-core gcc-multilib p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev xmlto qemu-utils upx libelf-dev autoconf automake libtool autopoint device-tree-compiler g++-multilib antlr3 gperf wget curl swig rsync


开始编译
克隆源代码至本地
git clone https://github.com/openwrt/openwrt.git openwrt_pi

查看克隆的源码
#切换到当前用户的家目录的openwrt_pi目录
cd ~/openwrt_pi/
#查看克隆下来的openwrt源码文件
~/openwrt_pi$ ls

更新安装软件仓库的源码到本地
./scripts/feeds update -a && ./scripts/feeds install -a

调整系统组件(详细配置可以查看下文的make menuconfig说明)
make menuconfig

#根具自己的定制需求,运行 make menuconfig 命令配置目标架构完成后,进入 LUCI --> Applications 选择需要的插件,进入 LUCI --> Themes 选择喜欢的主题皮肤,编译即可。
选择平台
Target System (x86) --->
Subtarget (x86_64) --->
Target Profile (Generic x86/64) --->
#无特殊需求,可以参考Target Images 勾选
[*] squashfs (NEW)
[*] Build GRUB images (Linux x86 or x86_64 host only) (NEW)
[*] GZip images (NEW)
自定义固件大小
(32) Kernel partition size (in MB) (NEW)
(400) Root filesystem partition size (in MB) (NEW)
#如果因为勾选基于 EXT4 文件系统编译固件而造成编译报错,建议调高 Root filesystem partition size
下载编译所需要的包
#因每个人网络原因下载时间不经相同
make download -j8 V=s

编译固件
# -j1:单线程编译
make -j1 V=s
#最大线程编译,第一次编译不建议使用,很大几率失败
#make -j$(nproc)

#单线程编译可提高编译成功率,但过程非常漫长(大约3-4小时左右),也完全取决于机器的性能。编译完成后固件输出路径: /openwrt/bin/targets/ 之下。


menuconfig说明
常用插件列表
#在调整 OpenWrt 系统组件时:[*] 表示编译软件包并加入到固件;[M] 表示编译软件包但不加入固件;[ ] 则表示不对软件包进行任何设置。
## 插件类
LuCI ---> Applications ---> luci-app-adbyby-plus #去广告
LuCI ---> Applications ---> luci-app-arpbind #IP/MAC绑定
LuCI ---> Applications ---> luci-app-autoreboot #高级重启
LuCI ---> Applications ---> luci-app-aliddns #阿里DDNS客户端
LuCI ---> Applications ---> luci-app-ddns #动态域名 DNS
LuCI ---> Applications ---> luci-app-filetransfer #文件传输
LuCI ---> Applications ---> luci-app-firewall #添加防火墙
LuCI ---> Applications ---> luci-app-frpc #内网穿透 Frp
LuCI ---> Applications ---> luci-app-mwan3 #MWAN负载均衡
LuCI ---> Applications ---> luci-app-nlbwmon #网络带宽监视器
LuCI ---> Applications ---> luci-app-ramfree #释放内存
LuCI ---> Applications ---> luci-app-samba #网络共享(Samba)
LuCI ---> Applications ---> luci-app-sqm #流量智能队列管理(QOS)
LuCI ---> Applications ---> luci-app-openclash #你懂的那只猫
LuCI ---> Applications ---> luci-app-dnsfilter #广告过滤
LuCI ---> Applications ---> luci-app-passwall #不敢解释
LuCI ---> Applications ---> luci-app-mtwifi #闭源Wi-Fi驱动
LuCI ---> Applications ---> luci-app-eqos #根据IP控制网速
LuCI ---> Applications ---> luci-app-syncdial #薛定谔的多拨应用
LuCI ---> Applications ---> luci-app-zerotier #虚拟局域网
LuCI ---> Applications ---> luci-app-jd-dailybonus #京东签到自动领豆
LuCI ---> Applications ---> luci-app-oaf #应用过滤神器
LuCI ---> Applications ---> luci-app-watchcat #断网检测功能与定时重启
LuCI ---> Applications ---> luci-app-wol #WOL网络唤醒
LuCI ---> Applications ---> luci-app-wrtbwmon #实时流量监测
LuCI ---> Applications ---> luci-app-upnp #通用即插即用UPnP(端口自动转发)
LuCI ---> Applications ---> luci-app-argon-config #Argon主题设置
常用主题类
LuCI ---> Themes ---> luci-theme-argon
网络相关
Network ---> IP Addresses and Names ---> ddns-scripts_cloudflare.com-v4
Network ---> IP Addresses and Names ---> bind-dig
Network ---> Routing and Rediction ---> ip-full
Network ---> File Transfer ---> curl
Network ---> File Transfer ---> wget-ssl
Network ---> iperf3
Network ---> ipset
Network ---> socat #多功能的网络工具
Base system --> dnsmasq-full #DNS缓存和DHCP服务(dnsmasq-full和dnsmasq二者不可共存)
工具类
Utilities --> acpid #电源管理接口(适用于x86平台)
Utilities --> Editors --> nano #Nano 编辑器
Utilities --> Shells --> bash #命令解释程序
Utilities --> disc --> fdisk #MBR分区工具
Utilities --> disc --> gdisk #GBT分区工具
Utilities --> disc --> lsblk #列出磁盘设备及分区查看工具
Utilities --> Filesystem --> resize2fs #调整文件系统大小
Utilities --> Filesystem --> e2fsprogs #Ext2(及Ext3/4)文件系统工具
IPv6
Extra packages ---> ipv6helper (勾选此项即可,下面几项自动勾选)
Network ---> odhcp6c
Network ---> odhcpd-ipv6only
LuCI ---> Protocols ---> luci-proto-ipv6
LuCI ---> Protocols ---> luci-proto-ppp