Ubuntu 17.10不接受静态IP

我的Ubuntu服务器不接受我的静态IP分配。 相反,我一直在获得DHCP租约。 未安装网络管理器。 下面是cat / etc / network / interfaces的输出

# The primary network interface auto eth0 iface eth0 inet static address 192.168.1.128 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.1 dns-nameservers 192.168.1.120 192.168.1.125 dns-domain mynetwork.local dns-search mynetwork.local 

输出ip addr

问题:

  1. 为什么Ubuntu不接受静态IP分配? Interfaces文件似乎被忽略了。

  2. 什么是允许分配DHCP租约?

包ifup下来,因此不再使用/etc/network/interfaces 。 Ubuntu 17.10服务器使用netplan包,它配置systemd-networkd。

确保使用配置文件/etc/network/interfaces的默认内容

 # /etc/network/interfaces -- configuration file for ifup(8), ifdown(8) # Generated by debian-installer. # The loopback interface auto lo iface lo inet loopback 

并为静态IPV4地址创建此netplan配置文件(适用于我):/ /etc/netplan/01-netcfg.yaml

 # This file describes the network interfaces available on your system # For more information, see netplan(5). network: version: 2 renderer: networkd ethernets: ens3: dhcp4: no dhcp6: no addresses: [192.168.0.97/24] gateway4: 192.168.0.1 nameservers: addresses: [8.8.8.8,8.8.4.4] 

确保使用正确的网络接口名称(本例中为“ ens3 ”)。

确保为网络环境使用正确的DNS服务器(名称服务器 – >地址)。

创建此文件后,以root身份运行以下命令以测试和激活配置:

 sudo netplan --debug generate sudo netplan apply