为 Ubuntu mini 17.10 设置静态 IP

为 Ubuntu mini 17.10 设置静态 IP

我正在尝试为我的电脑配置具有静态 IP/网关/名称服务器的以太网。

我编辑了/etc/network/interfaces、,/etc/systemd/network/*.network/etc/netplan/*.yaml这些文件都没有提供我需要的静态 IP 结果。

还有什么?

在 Ubuntu mini 中,谁配置以太网?

ifconfig给出(在更改配置文件之前):

enp0s4: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.12  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::210:5cff:fee9:a3b1  prefixlen 64  scopeid 0x20<link>
        ether 00:10:5c:e9:a3:b1  txqueuelen 1000  (Ethernet)
        RX packets 100  bytes 18369 (18.3 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 125  bytes 16802 (16.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 50  bytes 3276 (3.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 50  bytes 3276 (3.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ps aux | grep network给出:

systemd+   237  0.0  0.8  18680  4116 ?        Ss   00:49   0:00 /lib/systemd/systemd-networkd

/etc/network/interfaces是:

# ....
# ....unrelated loopback lines
# ....
auto enp0s4
iface enp0s4 inet static
address 192.168.1.11/24
gateway 192.168.1.4
netmask 255.255.255.0
dns-nameservers 192.9.43.50 192.9.43.51

/etc/netplan/01-netcfg.yaml是:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s4:
        addresses: 192.168.1.11/24
        dhcp4: no
        gateway4: 192.168.1.4
        nameservers:
          addresses: [192.9.43.50, 192.9.43.51]

答案1

经过大量man systemd.network阅读后,我找到了以下解决方法:

将文件重命名/run/systemd/network/10-netplan-enp0s4.network为没有.network扩展名的文件。

创建/etc/systemd/network/10-netplan-enp0s4.network包含以下内容的文件:

[Match]
Name=enp0s4

[Network]
DHCP=no
DNS=192.9.43.50
DNS=192.9.43.51
Address=192.168.1.11/24
Gateway=192.168.1.4
Domain=domain.domain

相关内容