我的 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
Run Code Online (Sandbox Code Playgroud)
问题:
为什么 Ubuntu 不接受静态 IP 分配?Interfaces 文件似乎被忽略了。
什么是允许分配 DHCP 租约?
小智 25
包 ifupdown 等/etc/network/interfaces不再使用。Ubuntu 17.10 Server 使用包 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
Run Code Online (Sandbox Code Playgroud)
并为静态 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]
Run Code Online (Sandbox Code Playgroud)
确保使用正确的网络接口名称(ens3在本例中为“ ”)。
确保为您的网络环境使用正确的 DNS 服务器(名称服务器-> 地址)。
创建此文件后,以 root 身份运行以下命令以测试和激活配置:
sudo netplan --debug generate
sudo netplan apply
Run Code Online (Sandbox Code Playgroud)