MolMoe Network 组网记录
导入
听说 DN42 之后感觉还挺有意思的,就趁着寒假捣鼓了一把,顺便修改了网络结构,通过 ZeroTier 把家里、宿舍、实验室等的网络组合在一起了,并且使用 iBGP 自动路由。学到不少计算机网络知识,受益匪浅。
感谢 Lan Tian 的博客指引方向:Clearnet DN42
申请 DN42 ASN 和 IP
DN42 使用 OpenPGP 密钥或 SSH密钥验证身份,因此您需要准备好 OpenPGP 或 SSH 密钥,并将其上传至 DN42 的 Gitea 实例,以便后续身份验证。
首先自然是要注册一个 DN42 地址了。访问DN42 Git,注册一个帐号,名称随意,但是后面最好不再更改。
下一步是将 dn42/registry clone 到本地,然后在本地新建一个名称为 你的用户名-今天日期/操作名称
(例如: mol-20220510/register
)的分支并上传:
git clone https://git.dn42.dev/dn42/registry
git checkout -b mol-20220510
git push --set-upstream origin mol-20220510/register
然后就是填写网络信息了。在 Clone 下来的仓库中新建一系列文件,文件模板可以参照同目录其他参与者,所有项名称、冒号和空格加起来均为20字符,所有文件名均为大写,建议全部使用 OpenPGP 密钥:
data/mntner/[Maintainer 名称]
帐户信息文件
mntner: [Maintainer 名称]
admin-c: [Administrator 名称]
tech-c: [Administrator 名称]
mnt-by: [Maintainer 名称]
source: DN42
auth: pgp-fingerprint [OpenPGP 指纹(如果有的话)]
auth: ssh-xxx [SSH 公钥(如果有的话)]
remarks: [注释,可以不填]
data/person/[Administrator 名称]
个人信息文件
person: [姓名或其他名称]
e-mail: [邮箱]
contact: [其它联系方式]
nic-hdl: [Administrator 名称]
mnt-by: [Maintainer 名称]
source: DN42
data/aut-num/[ASN 号码]
ASN信息文件
如果有自己的公网ASN的话可以使用,像我这种穷人只能拿一个DN42私有ASN了,比如我的是AS4242420603。
aut-num: [ASN 号码]
as-name: [AS 名称]
descr: [注释]
admin-c: [Administrator 名称]
tech-c: [Administrator 名称]
mnt-by: [Maintainer 名称]
source: DN42
data/inetnum/[IPv4 地址]
IPv4信息文件
DN42内一般申请/27的地址块就够用,/26是无需询问用途的最大地址块。我的地址为172.23.7.64/26
,那么文件名为172.23.7.64_26
。蓝天佬提到部分隧道引起的IP占用问题,因为DN42内主要使用WireGuard建立隧道,一般无需担心此问题。有一些地址被保留用作特殊用途,如172.20.0.0/24
被保留用于Anycast,只能申请/32
地址块。
inetnum: [起始IP] - [终止IP]
netname: [网络名称]
remarks: [注释]
descr: [注释]
country: [地区代码,看得懂这篇文章的一般是CN/HK/MO/TW/SG]
admin-c: [Administrator 名称]
tech-c: [Administrator 名称]
mnt-by: [Maintainer 名称]
nserver: [反向解析服务器]
nserver: [反向解析服务器]
status: ASSIGNED
cidr: [IP地址段CIDR]
source: DN42
data/route/[IPv4 地址]
IPv4路由信息
route: [IP地址段CIDR]
descr: [注释]
origin: [ASN 号码]
mnt-by: [Maintainer 名称]
source: DN42
data/inet6num/[IPv6 地址]
IPv6信息文件
DN42内一般申请/48的地址块,足够任何人使用。
inetnum: [起始IP] - [终止IP]
netname: [网络名称]
remarks: [注释]
descr: [注释]
country: [地区代码,看得懂这篇文章的一般是CN/HK/MO/TW/SG]
admin-c: [Administrator 名称]
tech-c: [Administrator 名称]
mnt-by: [Maintainer 名称]
nserver: [反向解析服务器]
nserver: [反向解析服务器]
status: ASSIGNED
cidr: [IP地址段CIDR]
source: DN42
data/route/[IPv6 地址]
IPv6路由信息
route: [IP地址段CIDR]
descr: [注释]
origin: [ASN 号码]
mnt-by: [Maintainer 名称]
source: DN42
到此为止已完成所有信息的添加,创建一份带有签名的 Commit 并提交:
git commit -S -m "提交信息"
git push
由于DN42 Git一次Pull Request只接受一个Commit,如果有Commit后修改内容的需求,请善用--amend
参数后,带-f
强制提交。
接下来回到DN42 Git,发起Pull Request等待合并。
合并成功后,由于ROA信息需要定时更新,您需要等待最长24小时方可进行Peer。DN42 官方提供的 ROA 更新时间是15分钟一次。
年轻人第一次 Peer
DN42 的目标是模拟一个真实的互联网,因此您通常要联系IX或其它设施来提供BGP接入。不过既然是DN42就不需要交钱给Cogent或是HE这样的组织,只要联系已经加入DN42的参与者,通过和ta们Peer以获得DN42路由能力。
以下是几种寻找 Peer 的方法:
- 使用 MolMoe Network 的 Autopeer Bot 和 MolMoe 进行全自动 Peer AutoPeer Bot 源代码
- 和已知有 Autopeer 服务的用户 Peer
- 使用 PingFinder 搜寻最近的 Peer
- 去非官方 DN42 群组找人 Peer
您可以找多个用户一起Peer,避免单线断开引起失联。
系统设置
在开始配置之前,您需要做好以下准备工作:
- 安装Linux;
- 关闭您节点上的任何傻瓜防火墙设施,例如
UFW
; - 安装 WireGuard 和 Bird2,并确保已有
wg-quick
快速配置工具。新手建议使用这对隧道和BGP程序,老鸟随意。
启用 Linux 的内核数据包转发功能,禁用 rp_filter
严格模式:
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
echo "net.ipv6.conf.default.forwarding=1" >> /etc/sysctl.conf
echo "net.ipv6.conf.all.forwarding=1" >> /etc/sysctl.conf
echo "net.ipv4.conf.default.rp_filter=0" >> /etc/sysctl.conf
echo "net.ipv4.conf.all.rp_filter=0" >> /etc/sysctl.conf
sysctl -p
配置 Bird
根据经验,您应该先建立和外界的Peer再打扫内部的网络,便于调试,少走弯路。PingFinder 和群里的 Ping Bot 可以帮助您调试网络。
如果您的发行版的 bird.conf
位于 /etc/bird/
就再好不过了;如果不是的话,建议创建这个目录,并将/etc/bird.conf
软链过去:
mkdir /etc/bird
mv /etc/bird.conf /etc/bird/bird.conf
ln -s /etc/bird.conf /etc/bird/bird.conf
mkdir /etc/bird/peers
根据 DN42 Wiki 配置Bird,将 /etc/bird/bird.conf
中的内容替换为DN42 Wiki提供的内容即可。文件较长,详细请参考Wiki。
上文提到了ROA,ROA限制了来源路由,避免了公网中BGP配置错误造成整个网络爆炸的窘境。(虽然DN42也不是没有发生过)
输入 crontab -e
,使用 cron 每15分钟更新一次ROA信息(如果习惯使用其它定时程序可随意;可能需要systemctl enable cronie
):
*/15 * * * * curl -sfSLR -o /etc/bird/roa_dn42.conf https://dn42.burble.com/roa/dn42_roa_bird2_4.conf && curl -sfSLR -o /etc/bird/roa_dn42_v6.conf https://dn42.burble.com/roa/dn42_roa_bird2_6.conf && /usr/sbin/birdc configure 1> /dev/null
上述命令每15分钟执行一次,下载ROA信息到/etc/bird/dn42_roa_bird2_4.conf
和/etc/bird/dn42_roa_bird2_6.conf
。
运行一次birdc configure
,确认配置正确,然后就可以愉快地Peer了!
添加 Peer 信息,建立隧道和BGP
以下是文件模板:
/etc/wireguard/[给我的隧道起个名字吧].conf
[Interface]
PrivateKey = [您的私钥]
ListenPort = [您的隧道监听端口]
Table = off
PostUp = ip addr add fe80::603/64 dev %i
PostUp = ip addr add [您的DN42 IPv6地址]/128 dev %i
PostUp = ip addr add [我的DN42 IPv4地址] peer [您的DN42 IPv4地址] dev %i
PostUp = sysctl -w net.ipv6.conf.%i.autoconf=0
[Peer]
PublicKey = [我的公钥]
Endpoint = [我的endpoint]:[您从bot获得的endpoint端口号]
AllowedIPs = 10.0.0.0/8, 172.20.0.0/14, 172.31.0.0/16, fd00::/8, fe80::/64
/etc/bird/peers/[给我的BGP Peer起个名字吧].conf(启用Multiprotocol)
protocol bgp [BGP Peer名称] from dnpeers {
neighbor fe80::603 % '[隧道名]' as 4242420603;
direct;
};
/etc/bird/peers/[给我的BGP Peer起个名字吧].conf(未启用Multiprotocol)
protocol bgp [BGP Peer名称]_v4 from dnpeers {
neighbor [我的DN42 IPv4地址] as 4242420603;
direct;
ipv6 {
import none;
export none;
};
};
protocol bgp [BGP Peer名称]_v6 from dnpeers {
neighbor fe80::603 % '[隧道名]' as 4242420603;
direct;
ipv4 {
import none;
export none;
};
};
添加完文件后,执行以下命令启用隧道和配置Bird:
cd /etc/wireguard
wg-quick up [隧道名]
birdc configure
使用以下命令检查隧道和BGP是否配置成功:
wg show
birdc s p
若 WireGuard 有双向数据传输、Bird BGP显示Established
,则恭喜您有了第一条Peer!
打理内网
「未完待续」