宿舍网络部署

  1. 1. 0.准备工作
  2. 2. 1.固件编译
    1. 2.1. 1.1安装Ubuntu24虚拟机
    2. 2.2. 1.2编译
      1. 2.2.1. 1.2.1安装编译所需的依赖
      2. 2.2.2. 1.2.2克隆源代码
      3. 2.2.3. 1.2.3安装额外的包依赖
      4. 2.2.4. 1.2.4更新并连接依赖
      5. 2.2.5. 1.2.5更改内核MD5标识的生成为官方的
      6. 2.2.6. 1.2.6更改编译配置
      7. 2.2.7. 1.2.7编译
  3. 3. 2.刷机
    1. 3.1. 2.1解锁
    2. 3.2. 2.2刷入系统
  4. 4. 3.配置
    1. 4.1. 3.0基本配置
    2. 4.2. 3.1mentohust配置
      1. 4.2.1. 3.1.1将账号和密码保存到配置文件
    3. 4.3. 3.2 iptable or nftable config
    4. 4.4. 3.3 ipv6配置
    5. 4.5. 3.4多播&负载均衡

0.准备工作

  • 能刷openwrt的路由器
  • openwrt固件

1.固件编译

1.1安装Ubuntu24虚拟机

安装open-vm-tools

Ubuntu、Debian 及相关操作系统

  1. 请确保已更新软件包索引:

    1
    sudo apt-get update
  2. 如果虚拟机具有 GUI(X11 等),请安装或升级 open-vm-tools-desktop

    1
    sudo apt-get install open-vm-tools-desktop
  3. 否则,请使用以下命令安装open-vm-tools

    1
    sudo apt-get install open-vm-tools

解决open-vm-tools无法拖拽复制的问题(ง •_•)ง

1
sudo vim /etc/gdm3/custom.conf

删掉#WaylandEnable=false的井号。

1
sudo systemctl restart gdm3

1.2编译

1.2.1安装编译所需的依赖

1
2
3
4
5
6
7
8
9
10
sudo apt update -y
sudo apt full-upgrade -y
sudo apt install -y ack antlr3 asciidoc autoconf automake autopoint binutils bison build-essential \
bzip2 ccache clang cmake cpio curl device-tree-compiler ecj fastjar flex gawk gettext gcc-multilib \
g++-multilib git gnutls-dev gperf haveged help2man intltool lib32gcc-s1 libc6-dev-i386 libelf-dev \
libglib2.0-dev libgmp3-dev libltdl-dev libmpc-dev libmpfr-dev libncurses-dev libpython3-dev \
libreadline-dev libssl-dev libtool libyaml-dev libz-dev lld llvm lrzsz mkisofs msmtp nano \
ninja-build p7zip p7zip-full patch pkgconf python3 python3-pip python3-ply python3-docutils \
python3-pyelftools qemu-utils re2c rsync scons squashfs-tools subversion swig texinfo uglifyjs \
upx-ucl unzip vim wget xmlto xxd zlib1g-dev

1.2.2克隆源代码

1
2
git clone -b openwrt-23.05 --single-branch --filter=blob:none https://github.com/immortalwrt/immortalwrt
git checkout v23.05.4

openwrt-23.05可以换成你要的分支

1.2.3安装额外的包依赖

可选安装rkp-ipid 注意:内核模块

1
git clone https://github.com/CHN-beta/rkp-ipid.git package/rkp-ipid

1.2.4更新并连接依赖

1
2
3
cd immortalwrt/
./scripts/feeds update -a
./scripts/feeds install -a

1.2.5更改内核MD5标识的生成为官方的

不改后面软件包安装不上>︿<

1、在immortalwrt根目录,创建并编写文件 vermagic ,内容为immortalwrt 23.05.4发行版的MD5

#23.05.1

767811e1a3cb446a9ba35ce4ca74d41f

#23.05.4

0d97712e7ae9f801dbbca6dd348a30dc

具体可以在这里查看 web

2、去到root/include/kernel-defaults.mk 更改编译规则,(不用mkhash md5生成,而直接拷贝根目录下的vermagic文件到linux_dir/.vermagic

grep '=[ym]' $(LINUX_DIR)/.config.set | LC_ALL=C sort | mkhash md5 > $(LINUX_DIR)/.vermagic

改为\# grep '=[ym]' $(LINUX_DIR)/.config.set | LC_ALL=C

3、修改package/kernel/linux/Makefile

STAMP_BUILT:=$(STAMP_BUILT)_$(shell $(SCRIPT_DIR)/kconfig.pl $(LINUX_DIR)/.config | mkhash md5)
改为
#STAMP_BUILT:=$(STAMP_BUILT)_$(shell $(SCRIPT_DIR)/kconfig.pl $(LINUX_DIR)/.config | mkhash md5) STAMP_BUILT:=$(STAMP_BUILT)_$(shell cat $(LINUX_DIR)/.vermagic)

1.2.6更改编译配置

1
make menuconfig

勾选所需的包,记得勾选mentohust(锐捷认证脚本)

1.2.7编译

1
2
3
4
5
6
#make kernel
make kernel_menuconfig -j$(nproc) V=cs

#make rom
make download -j$(nproc) V=cs
make -j$(nproc) V=cs

2.刷机

2.1解锁

使用xiaomi-cr6606解锁工具解锁路由器

2.2刷入系统

  1. 按住reset键并接通电源线
  2. 用网线将路由器的lan口与电脑连接
  3. 打开浏览器192.168.1.1
  4. 刷机

3.配置

3.0基本配置

  1. 登录web界面并修改默认密码,默认密码password

  2. 修改ntp服务

    1
    2
    3
    4
    5
    6
    #NTP服务器
    作为 NTP 服务器提供服务
    ntp.aliyun.com
    time1.cloud.tencent.com
    time.ustc.edu.cn
    cn.pool.ntp.org

3.1mentohust配置

连接ssh

3.1.1将账号和密码保存到配置文件

注意:-u和-p后不用加空格(#°Д°)

1
sudo mentohust -uUsername -pPassword -w

更多参数参考mentohust -h

3.2 iptable or nftable config

iptable
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 通过 iptables 修改 TTL 值
iptables -t mangle -A POSTROUTING -j TTL --ttl-set 64

#防火墙:Dns劫持
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 53
iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 53

# 防 IPID 检测 编译了 rkp-ipid才能用
iptables -t mangle -N IPID_MOD
iptables -t mangle -A FORWARD -j IPID_MOD
iptables -t mangle -A OUTPUT -j IPID_MOD
iptables -t mangle -A IPID_MOD -d 0.0.0.0/8 -j RETURN
iptables -t mangle -A IPID_MOD -d 127.0.0.0/8 -j RETURN
iptables -t mangle -A IPID_MOD -d 10.0.0.0/8 -j RETURN
#iptables -t mangle -A IPID_MOD -d 172.16.0.0/12 -j RETURN
iptables -t mangle -A IPID_MOD -d 192.168.0.0/16 -j RETURN
iptables -t mangle -A IPID_MOD -d 255.0.0.0/8 -j RETURN
iptables -t mangle -A IPID_MOD -j MARK --set-xmark 0x10/0x10

# 防时钟偏移检测
iptables -t nat -N ntp_force_local
iptables -t nat -I PREROUTING -p udp --dport 123 -j ntp_force_local
iptables -t nat -A ntp_force_local -d 0.0.0.0/8 -j RETURN
iptables -t nat -A ntp_force_local -d 127.0.0.0/8 -j RETURN
iptables -t nat -A ntp_force_local -d 192.168.0.0/16 -j RETURN
iptables -t nat -A ntp_force_local -s 192.168.0.0/16 -j DNAT --to-destination 192.168.1.1

nftable
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
nft add table ip mangle
nft add chain ip mangle postrouting { type filter hook postrouting priority 0 \; }
nft add rule ip mangle postrouting ttl set 64

nft add table ip nat
nft add chain ip nat prerouting { type nat hook prerouting priority 0 \; }
nft add rule ip nat prerouting udp dport 53 redirect to :53
nft add rule ip nat prerouting tcp dport 53 redirect to :53

nft add table ip mangle
nft add chain ip mangle forward { type filter hook forward priority 0 \; }
nft add chain ip mangle output { type route hook output priority 0 \; }
nft add chain ip mangle IPID_MOD

# 创建跳转链并增加返回规则
nft add rule ip mangle forward jump IPID_MOD
nft add rule ip mangle output jump IPID_MOD
nft add rule ip mangle IPID_MOD ip daddr 0.0.0.0/8 return
nft add rule ip mangle IPID_MOD ip daddr 127.0.0.0/8 return
nft add rule ip mangle IPID_MOD ip daddr 10.0.0.0/8 return
# nft add rule ip mangle IPID_MOD ip daddr 172.16.0.0/12 return
nft add rule ip mangle IPID_MOD ip daddr 192.168.0.0/16 return
nft add rule ip mangle IPID_MOD ip daddr 255.0.0.0/8 return
nft add rule ip mangle IPID_MOD meta mark set 0x10

nft add table ip nat
nft add chain ip nat ntp_force_local
nft add chain ip nat prerouting { type nat hook prerouting priority 0 \; }

# 将 NTP 流量重定向到本地
nft add rule ip nat prerouting udp dport 123 jump ntp_force_local
nft add rule ip nat ntp_force_local ip daddr 0.0.0.0/8 return
nft add rule ip nat ntp_force_local ip daddr 127.0.0.0/8 return
nft add rule ip nat ntp_force_local ip daddr 192.168.0.0/16 return
nft add rule ip nat ntp_force_local ip saddr 192.168.0.0/16 dnat to 192.168.1.1

3.3 ipv6配置

首先科普一下 分配到的三种ipv6

  1. /64前缀 ,有前缀委托PD
  2. /64前缀,无前缀委托
  3. /128 最坏的情况

这里只拿到了/64 但是没有pd不能下发委托。

配置ipv6中继模式

1
vim /etc/conf/dhcp
1
2
3
4
5
6
7
8
9
10
11
12
13
config dhcp 'lan'
#...etc ipv4 conf
option ra 'relay'
option ndp 'relay'

config dhcp 'wan6'
#配置wan6接口,协议dhcpv6
option ignore '1'
#忽略dhcp服务 wan不需要 ipv6也不用dhcp来分配
option ra 'relay'
option ndp 'relay'
option master '1'
#开启ra ndp 转发模式,并设置为主接口

剩下的第一种配置服务器模式就可以了,

第三种的话不能给内网的每一个设备分配v6地址需要进行nat66转换 这ipv6还有什么用..ヾ(≧へ≦)〃

3.4多播&负载均衡

咕咕咕 这里实在是太复杂了,有人看再更吧 ༼ つ ◕_◕ ༽つ
目前已经实现了多线多播,配和fallblack+tun实现晚上不断网。