Ubuntu 22.04 上未使用 systemd-networkd 配置文件设置静态 IP

Ubuntu 22.04 上未使用 systemd-networkd 配置文件设置静态 IP

我有一台具有两个网络接口的服务器。我在 /etc/systemd/network 文件夹中对其进行了如下配置:

文件:90-eth1.network

 [Match]
 Name=eth1

 [Network]
 Address=192.168.1.28/24
 Gateway=192.168.1.7
 DNS=8.8.8.8
 DNS=8.8.4.4

文件:91-eno1.network

 [Match]
 Name=eno1

 [Network]
 Address=192.168.1.30/24
 Gateway=192.168.1.7
 DNS=8.8.8.8
 DNS=8.8.4.4

我运行了 systemctl restart systemd-networkd。运行 systemctl status systemd-networkd 显示以下内容:

 ● systemd-networkd.service - Network Configuration
      Loaded: loaded (/lib/systemd/system/systemd-networkd.service; enabled; vendor preset: enabled)
      Active: active (running) since Sat 2022-09-24 15:09:00 UTC; 45s ago
 TriggeredBy: ● systemd-networkd.socket
        Docs: man:systemd-networkd.service(8)
    Main PID: 1398 (systemd-network)
      Status: "Processing requests..."
       Tasks: 1 (limit: 18499)
      Memory: 1.4M
         CPU: 34ms
      CGroup: /system.slice/systemd-networkd.service
              └─1398 /lib/systemd/systemd-networkd

 Sep 24 15:09:00 elxn4 systemd[1]: Starting Network Configuration...
 Sep 24 15:09:00 elxn4 systemd-networkd[1398]: eth1: Link UP
 Sep 24 15:09:00 elxn4 systemd-networkd[1398]: eno1: Link UP
 Sep 24 15:09:00 elxn4 systemd-networkd[1398]: eno1: Gained carrier
 Sep 24 15:09:00 elxn4 systemd-networkd[1398]: lo: Link UP
 Sep 24 15:09:00 elxn4 systemd-networkd[1398]: lo: Gained carrier
 Sep 24 15:09:00 elxn4 systemd-networkd[1398]: eth1: Gained IPv6LL
 Sep 24 15:09:00 elxn4 systemd-networkd[1398]: eno1: Gained IPv6LL
 Sep 24 15:09:00 elxn4 systemd-networkd[1398]: Enumeration completed
 Sep 24 15:09:00 elxn4 systemd[1]: Started Network Configuration.

运行 ip addr ls 显示:

 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
        valid_lft forever preferred_lft forever
 2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
     link/ether 00:1e:67:d6:2d:c0 brd ff:ff:ff:ff:ff:ff
     altname enp2s0
     inet6 fe80::21e:67ff:fed6:2dc0/64 scope link
        valid_lft forever preferred_lft forever
 3: eth1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
     link/ether 00:1e:67:d6:2d:c1 brd ff:ff:ff:ff:ff:ff
     altname enp3s0
     inet6 fe80::21e:67ff:fed6:2dc1/64 scope link
        valid_lft forever preferred_lft forever

其中一个接口未连接到交换机,因此如预期的那样,它显示无运营商。我的问题是我无法使用上述配置分配静态 IP 地址。我能够通过运行“ip addr add 192.168.1.30 dev eno1”手动分配静态 IP,然后 ping 到同一网络上的另一台设备,因此我知道电缆、端口、交换机等没有硬件问题。

这是全新安装的 Linux。我之前用同样的方法安装过,并且分配了 IP 地址。这次我肯定漏掉了一些步骤。

相关内容