材料

rock5A、AX210无线网卡、小米路由器

rock5A安装系统

系统地址https://github.com/radxa-build/rock-5a/releases

这里我选择的是debian cli 版本,默认用户名和密码rock。

换源

清华源地址https://mirror.tuna.tsinghua.edu.cn/help/debian/

具体操作

无线校园网->ax210网卡->rock5A->有线网口->网线->路由器

1、首先使用ip addr查看网卡信息

```bash
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 66:66:39:b8:f4:d5 brd ff:ff:ff:ff:ff:ff
    inet 10.10.10.1/24 brd 10.10.10.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::6466:39ff:feb8:f4d5/64 scope link 
       valid_lft forever preferred_lft forever
4: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 2c:33:58:52:d0:a0 brd ff:ff:ff:ff:ff:ff
    inet 10.104.54.161/16 brd 10.104.255.255 scope global dynamic noprefixroute wlan0
       valid_lft 80213sec preferred_lft 80213sec
    inet6 fe80::1dd5:e6fe:28cf:a605/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
```

然后使用nmcli 将无线网卡wlan0连接到校园wifi

2、编辑vi /etc/network/interfaces将有线网卡设置为静态ip 10.10.10.1

image-20230919162925486

3、执行 systemctl restart networking重启网络

4、开启转发功能

vim /etc/sysctl.conf
#修改 net.ipv4.ip_forward=1 然后执行
sysctl -p

5、添加NAT规则

iptables -t nat -A POSTROUTING -j MASQUERADE

6、NAT规则持久化

apt update -y && apt install iptables-persistent
iptables-save > /etc/iptables/rules.v4

7、路由器wan设置ip 10.10.1.2 netmask为255.255.255.0即可上网

image-20230919163704333

参考文章:

https://sinchie.com/posts/ubuntu-route/

https://www.networkreverse.com/2020/06/how-to-build-linux-router-with-ubuntu.html