我有两个网络接口,eno1 和 eth0。我希望它们都使用 DHCP 获取 IP 地址。我希望 eno1 用作所有设备的默认路由。我唯一想使用 eth0 的情况是在 curl 命令中指定接口时。
我创建了两个配置文件:
root:/etc/systemd/network$ ls -la
total 16
drwxr-xr-x 2 root root 4096 Oct 20 10:50 .
drwxr-xr-x 6 root root 4096 Oct 20 10:51 ..
-rw-r--r-- 1 root root 59 Oct 20 09:54 10-eno1.network
-rw-r--r-- 1 root root 59 Oct 20 10:41 20-eth0.network
root:/etc/systemd/network$ cat 10-eno1.network
[Match]
Name=eno1
[Network]
DHCP=yes
[Route]
Metric=100
root:/etc/systemd/network$ cat 20-eth0.network
[Match]
Name=eth0
[Network]
DHCP=yes
[Route]
Metric=4000
我尝试过重新启动并调整指标,但它们似乎没有效果。
root:/etc/systemd/network$ systemctl status systemd-networkd
● systemd-networkd.service - Network Configuration
Loaded: loaded (/usr/lib/systemd/system/systemd-networkd.service; enabled; preset: enabled)
Active: active (running) since Sun 2024-10-20 10:51:59 UTC; 12min ago
TriggeredBy: ● systemd-networkd.socket
Docs: man:systemd-networkd.service(8)
man:org.freedesktop.network1(5)
Main PID: 24821 (systemd-network)
Status: "Processing requests..."
Tasks: 1 (limit: 76956)
FD Store: 0 (limit: 512)
Memory: 1.7M (peak: 2.1M)
CPU: 32ms
CGroup: /system.slice/systemd-networkd.service
└─24821 /usr/lib/systemd/systemd-networkd
Oct 20 10:51:59 systemd-networkd[24821]: eth0: Link UP
Oct 20 10:51:59 systemd-networkd[24821]: eth0: Gained carrier
Oct 20 10:51:59 systemd-networkd[24821]: eno1: Gained IPv6LL
Oct 20 10:51:59 systemd-networkd[24821]: eth0: Gained IPv6LL
Oct 20 10:51:59 systemd-networkd[24821]: Enumeration completed
Oct 20 10:51:59 systemd[1]: Started systemd-networkd.service - Network Configuration.
Oct 20 10:51:59 systemd-networkd[24821]: eno1: Configuring with /etc/systemd/network/10-eno1.network.
Oct 20 10:51:59 systemd-networkd[24821]: eth0: Configuring with /etc/systemd/network/20-eth0.network.
Oct 20 10:51:59 systemd-networkd[24821]: eno1: DHCPv4 address 192.168.0.2/24, gateway 192.168.0.1 acquired from 192.168.0.1
Oct 20 10:51:59 systemd-networkd[24821]: eth0: DHCPv4 address 192.168.0.99/24, gateway 192.168.0.1 acquired from 192.168.0.1
root:/etc/systemd/network$ ip route show
default via 192.168.0.1 dev eno1 proto dhcp src 192.168.0.2 metric 1024
default via 192.168.0.1 dev eth0 proto dhcp src 192.168.0.99 metric 1024
128.138.140.44 via 192.168.0.1 dev eno1 proto dhcp src 192.168.0.2 metric 1024
128.138.140.44 via 192.168.0.1 dev eth0 proto dhcp src 192.168.0.99 metric 1024
192.168.0.0/24 dev eno1 proto kernel scope link src 192.168.0.2 metric 1024
192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.99 metric 1024
192.168.0.1 dev eno1 proto dhcp scope link src 192.168.0.2 metric 1024
192.168.0.1 dev eth0 proto dhcp scope link src 192.168.0.99 metric 1024