使用 Armbian 与 NanoPi R4S 做网关

使用 NanoPi R4S 与 Armbian 系统做网关

下载与刷写 armbian

下载地址:https://www.armbian.com/nanopi-r4s/

映像写入工具推荐使用 Etcher,SD 卡至少 8GB 起步,这里选择基于 Debian 打造的镜像。

软件源

主软件源:

https://mirrors.bfsu.edu.cn/help/debian/

armbian特有的源无需替换,它会选择最好的镜像服务器进行下载。

原来的软件源配置记得做好备份。

配置网络

通过 ip a 命令来查看系统当前有哪些网卡,然后挑选一个作为 LAN 口,一个作为 WAN 口。

LAN

选择 enp1s0 作为 LAN 口:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
### 文件位于 /etc/systemd/network/20-enp1s0.network
[Match]
Name=enp1s0

[Network]
Address=192.168.20.1/24
DHCPServer=true
DHCP=ipv6
IPMasquerade=true
IPv6AcceptRA=yes
IPv6SendRA=yes
DHCPv6PrefixDelegation=yes
DNS=2400:3200::1
DNS=2400:3200:baba::1

[DHCPServer]
EmitDNS=yes
DNS=223.5.5.5
DNS=223.6.6.6

[IPv6PrefixDelegation]
EmitDNS=yes

如果你的网络没有 IPv6,那么建议你注释掉有关于 IPv6 的设置。

WAN

示例一 PPPoE 拨号

要使用 PPPoE 拨号,你首先需要安装 pppoeconfpppoe 这两个包,然后通过 pppoeconf 命令来完成拨号配置。

如果 PPPoE 拨号通过 DHCPv6 下发 IPv6 地址与前缀,那么你还需要增加一个配置文件:

1
2
3
4
5
6
7
8
9
### 文件位于 /etc/systemd/network/60-ppp0.network
[Match]
Name=ppp0

[Network]
DHCP=ipv6

[DHCP]
ForceDHCPv6PDOtherInformation=yes

示例二 DHCP

1
2
3
4
5
6
7
8
9
### 文件位于 /etc/systemd/network/20-eth1.network
[Match]
Name=eth1

[Network]
DHCP=yes

[DHCP]
ForceDHCPv6PDOtherInformation=yes

转发设置

IPv4 转发

1
2
### 文件位于 /etc/sysctl.d/10-ipv4.conf
net.ipv4.ip_forward=1

IPv6 转发与通告

1
2
3
4
5
6
7
8
9
10
11
12
13
### 文件位于 /etc/sysctl.d/10-ipv6.conf
# 开启 ipv6 转发
net.ipv6.conf.all.forwarding=1
# 接受路由通告
net.ipv6.conf.all.accept_ra=2
net.ipv6.conf.default.accept_ra=2
## net.ipv6.conf.eth1.accept_ra=2
## net.ipv6.conf.enp1s0.accept_ra=2
# IPv6 使用临时地址
net.ipv6.conf.all.use_tempaddr = 2
net.ipv6.conf.default.use_tempaddr = 2
## net.ipv6.conf.eth1.use_tempaddr = 2
## net.ipv6.conf.enp1s0.use_tempaddr = 2

应用配置

关闭 Network Manager 服务:

1
sudo systemctl disable NetworkManager

启用 systemd-networkd:

1
sudo systemctl enable systemd-networkd

systemd-networkd 的 DHCP 服务器会自动下发 DNS 给下级设备,但是 NanoPi R4S 自身可能没有 DNS。作为一个替代,你可以启用 systemd-resolved 服务:

1
2
sudo ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
sudo systemctl enable systemd-resolved --now

你也可以直接修改 /etc/resolv.conf ,自己设定 DNS 服务器。

重启系统:

1
sudo reboot