260119-Ubuntu20.04系统启动后直接加载固定路由-/etc/systemd/network/10-enp1s0.network

作用:(Ubuntu20.04系统启动后直接加载固定路由)让本机一启动就把 192.168.0.2 / .4 / .102 / .104 / .106 这 5 个地址“当成跟自己同一链路(link)上的邻居”,无需网关即可直达,ARP 解析后直接发包。

目录位置: /etc/systemd/network/10-enp1s0.network

配置完成,重启(sudo systemctl enable systemd-networkd)

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
[Match]
Name=enp1s0

[Network]
DHCP=yes

# 下面 5 行就是固定路由
[Route]
Destination=192.168.0.2/32
Scope=link

[Route]
Destination=192.168.0.4/32
Scope=link

[Route]
Destination=192.168.0.102/32
Scope=link

[Route]
Destination=192.168.0.104/32
Scope=link

[Route]
Destination=192.168.0.106/32
Scope=link