我有两个网卡,想要设置系统,因此第二个是主/默认网卡。
- 第一个是 1Gb 单元及其内置。
- 第二个是 2.5gb NIC,通过 USB3 连接,我安装操作系统时没有这个,即 Raspberry Pi OS Lite 64 位Debian 版本:12(书呆子)
我想要做的就是将 2.5Gb 设置为主/默认!这可能吗?
每次我使用它进行设置时,nmtui
它都会在系统仍然打开的情况下工作,但是如果系统重新启动,我就必须重新做一遍。
这些帖子/威胁显示了我陷入的所有兔子洞以及我尝试过但最终未能解决问题的方法。 OMV 论坛-树莓派论坛-树莓派论坛
更新,我在遵循@metabaster 的逐步回复后发布了结果
sudo nano /etc/systemd/network/lo.network
[Match]
Name=lo
Type=loopback
[Network]
Address=127.0.0.1/8
sudo nano /etc/systemd/network/eth0.network
[Match]
Name=eth0
Type=ether
[Network]
DHCP=yes
[DHCPv4]
RouteMetric=100
sudo nano /etc/systemd/network/eth1.network
[Match]
Name=eth1
Type=ether
[Address]
Address=10.0.0.10/24
Broadcast=true
RouteMetric=10
[Network]
DHCP=no
DNS=1.1.1.1
[Route]
Gateway=10.0.0.1
Metric=10
ls -1 /etc/systemd/network
73-usb-net-by-mac.link
99-default.link
eth0.network
eth1.network
lo.network
sudo systemctl status networking
○ networking.service - Raise network interfaces
Loaded: loaded (/lib/systemd/system/networking.service; disabled; preset: enabled)
Active: inactive (dead)
Docs: man:interfaces(5)
sudo systemctl status systemd-networkd
● systemd-networkd.service - Network Configuration
Loaded: loaded (/lib/systemd/system/systemd-networkd.service; enabled; preset: enabled)
Active: active (running) since Sun 2024-04-28 14:24:11 CEST; 7h ago
TriggeredBy: ● systemd-networkd.socket
Docs: man:systemd-networkd.service(8)
man:org.freedesktop.network1(5)
Main PID: 314 (systemd-network)
Status: "Processing requests..."
Tasks: 1 (limit: 9255)
CPU: 90ms
CGroup: /system.slice/systemd-networkd.service
└─314 /lib/systemd/systemd-networkd
Apr 28 14:24:11 Pi5 systemd-networkd[314]: eth0: Configuring with /etc/systemd/network/eth0.network.
Apr 28 14:24:11 Pi5 systemd[1]: Started systemd-networkd.service - Network Configuration.
Apr 28 14:24:11 Pi5 systemd-networkd[314]: lo: Configuring with /etc/systemd/network/lo.network.
Apr 28 14:24:11 Pi5 systemd-networkd[314]: eth0: Link UP
Apr 28 14:24:41 Pi5 systemd-networkd[314]: eth1: found matching network '/etc/systemd/network/eth1.network', based on potentially unpredictable interface name.
Apr 28 14:24:41 Pi5 systemd-networkd[314]: eth1: Configuring with /etc/systemd/network/eth1.network.
Apr 28 14:24:41 Pi5 systemd-networkd[314]: eth1: Link UP
Apr 28 14:24:44 Pi5 systemd-networkd[314]: eth1: Gained carrier
Apr 28 14:24:44 Pi5 systemd-networkd[314]: eth1: found matching network '/etc/systemd/network/eth1.network', based on potentially unpredictable interface name.
Apr 28 14:24:46 Pi5 systemd-networkd[314]: eth1: Gained IPv6LL
ethtool eth1
Settings for eth1:
Supported ports: [ TP MII ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Half 1000baseT/Full
2500baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Supported FEC modes: Not reported
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
2500baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Advertised FEC modes: Not reported
Link partner advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Half 1000baseT/Full
Link partner advertised pause frame use: Symmetric Receive-only
Link partner advertised auto-negotiation: Yes
Link partner advertised FEC modes: Not reported
Speed: 1000Mb/s
Duplex: Full
Auto-negotiation: on
Port: MII
PHYAD: 32
Transceiver: internal
netlink error: Operation not permitted
Current message level: 0x00007fff (32767)
drv probe link timer ifdown ifup rx_err tx_err tx_queued intr tx_done rx_status pktdata hw wol
Link detected: yes
ip route show
default via 10.0.0.1 dev eth1 proto static metric 10
10.0.0.0/24 dev eth1 proto kernel scope link src 10.0.0.10 metric 10
ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host noprefixroute
valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
link/ether 2c:cf:67:2f:cf:9a brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:24:27:88:29:17 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.10/24 metric 10 brd 10.0.0.255 scope global eth1
valid_lft forever preferred_lft forever
inet6 fd75:a6e1:4b04:360:224:27ff:fe88:2917/64 scope global dynamic mngtmpaddr noprefixroute
valid_lft 1552sec preferred_lft 1552sec
inet6 fe80::224:27ff:fe88:2917/64 scope link
valid_lft forever preferred_lft forever
sudo systemctl stop NetworkManager
sudo systemctl disable NetworkManager
sudo systemctl status NetworkManager
○ NetworkManager.service - Network Manager
Loaded: loaded (/lib/systemd/system/NetworkManager.service; disabled; preset: enabled)
Active: inactive (dead)
Docs: man:NetworkManager(8)
答案1
您有 2 个NIC's
,并且希望2.5gb NIC
将第一个设为默认值,并且优先于第1Gb
一个。
除了根据cat /etc/network/interfaces
您评论中的输出之外,这只能通过systemd-networkd
这意味着networking
需要禁用该服务(如果已启用)并且systemd-networkd
应该使用该服务。
systemd-networkd
提供了一种配置接口的方法,最重要的是设置接口,metric
这将使其中一个接口成为NIC's
默认接口。
第一步是学习NIC
名字通过运行以下命令:
ip link show
此命令将列出您的NIC
姓名,单个的示例输出NIC
如下:
6: ovsbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
link/ether e6:db:3f:88:4b:48 brd ff:ff:ff:ff:ff:ff
inet 192.168.11.1/24 brd 192.168.11.255 scope global ovsbr0
valid_lft forever preferred_lft forever
inet6 fe80::e4db:3fff:fe88:4b48/64 scope link
valid_lft forever preferred_lft forever
在这个例子中ovsbr0
是NIC
名称,在您的实际输出中您应该看到多个NIC
名称,但您只关心NIC's
需要配置的 2 个名称,包括lo
NIC
环回接口并且也需要配置。
我们先来配置一下lo
接口,如下:
sudo nano /etc/systemd/network/lo.network
这将打开 nano 编辑器,将以下配置插入(复制\粘贴)到其中并使用 和CTRL+O
保存CTRL+X
:
[Match]
Name=lo
Type=loopback
[Network]
Address=127.0.0.1/8
Loopback 接口配置完毕,接下来需要配置其他 2 个接口NIC's
,每个接口的配置NIC
都存储在/etc/systemd/network
目录中。
创建的文件应该以NIC
名称和*.network
扩展名命名,就像我们在lo
上面的界面中所做的那样。
我假设您NIC's
被调用enp1
,enp2
但您请确保将这些名称替换为NIC
通过ip link show
命令获得的实际名称。
我还将假设您希望将其enp1
设为2.5gb NIC
默认值...
所以第一个的配置是:
sudo nano /etc/systemd/network/enp1.network
配置如下NIC
:
[Match]
Name=enp1
[Network]
DHCP=ipv4
[DHCPv4]
RouteMetric=10
[Route]
Metric=10
就这样,保存配置并关闭nano
编辑器,然后我们配置第二个:
sudo nano /etc/systemd/network/enp2.network
配置如下NIC
:
[Match]
Name=enp2
[Network]
DHCP=ipv4
[DHCPv4]
RouteMetric=100
[Route]
Metric=100
再次保存并关闭 Nano 编辑器。
请注意,RouteMetric
条目决定哪NIC
一个将是默认值,较低metric
意味着优先级较高!
接下来我们需要禁用networking
服务如下(如果错误,忽略它)
# Backup previous config
sudo mv /etc/network/interfaces /etc/network/interfaces.save
# Stop networking
sudo systemctl stop networking
sudo systemctl disable networking
下一步是启用systemd-networkd
服务(必须成功):
# Start systemd-networkd
sudo systemctl start systemd-networkd
sudo systemctl enable systemd-networkd
从输出中systemd-networkd
启用和禁用验证:networking
sudo systemctl status networking
sudo systemctl status systemd-networkd
最后重启系统:
systemctl reboot
重新启动后执行这些步骤后,2.5gb NIC
应默认使用。
系统已重新启动...
检查路由是否正确:
ip route show
它应该显示您的enp1
NIC 已10
为default
路由分配了指标,例如:
default via x.x.x.x dev enp1 proto static metric 10
default via x.x.x.x dev enp2 proto static metric 100
检查DHCP
工作并IP
分配:
ip addr show
应该显示已从您的路由器enp1
获得了地址。IPv4
NAT
例如:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host noprefixroute
valid_lft forever preferred_lft forever
在inet
该部分下,它显示已分配地址,如果没有inet
地址,则不起作用。