如何在Ubuntu 17.10及更高版本中使用静态IP?

我将配置从dhcp更改为静态(192.168.0.17),但仍然获得了dhcp分配(192.168.0.141)IP。 我不知道在哪里检查……有什么想法吗?

使用ifconfig

ens33: flags=4163 mtu 1500 inet 192.168.0.141 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::20c:29ff:fe87:6981 prefixlen 64 scopeid 0x20 ether 00:0c:29:87:69:81 txqueuelen 1000 (Ethernet) RX packets 43080139 bytes 55213169928 (55.2 GB) RX errors 0 dropped 1 overruns 0 frame 0 TX packets 17923871 bytes 1406116280 (1.4 GB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 1000 (Local Loopback) RX packets 56350 bytes 6166732 (6.1 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 56350 bytes 6166732 (6.1 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 

nmcli d

 DEVICE TYPE STATE CONNECTION ens33 ethernet unmanaged -- lo loopback unmanaged -- 

的/ etc /网络/接口

 # /etc/network/interfaces -- configuration file for ifup(8), ifdown(8) # Generated by debian-installer. # The loopback interface auto lo iface lo inet loopback #The primary network interface auto ens33 iface ens33 inet static address 192.168.0.17 netmask 255.255.255.0 gateway 192.168.0.1 dns-nameservers 192.168.0.1 

/etc/NetworkManager/NetworkManager.conf

 [main] plugins=ifupdown,keyfile [ifupdown] managed=false [device] wifi.scan-rand-mac-address=no 

uname -a

 Linux server 4.13.0-16-generic #19-Ubuntu SMP Wed Oct 11 18:35:14 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux 

默认情况下,网络由netplan在Ubuntu Server 17.10中处理。 我建议你编辑/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: ens33: dhcp4: no dhcp6: no addresses: [192.168.0.17/24] gateway4: 192.168.0.1 nameservers: addresses: [8.8.8.8,192.168.0.1] 

通过运行以下命令退出并保存更改:

 sudo netplan apply 

请注意并遵循间距和缩进。

/etc/network/interfaces注释掉所有ens33节。 重启。

有什么改进?