Ubuntu – netplan apply does not change the IP address

netplannetworkingserver

ok, my file is located at /etc/netplan/50-cloud-init.yaml
I changed the IP address as a static IP address as following:

network:
  version: 2 

  renderer: netwokrd

  ethernets:

    dhcp4: no
    dhcp6: no
    addresses: [10.0.2.100/24]
    gateway4: 10.0.2.1
    nameservers:
       addresses: [10.0.2.100]

Then, I typed sudo netplan apply, and there was not any error message.
BUT, when I typed ifconfig, it still remail past IP address on enp0s3.
Do you guys know why this happen?

Best Answer

Netplan is fussy about how .yaml files are formatted. Don't try to "pretty-fy" them.

Is 50-cloud-init.yaml the only .yaml file in /etc/netplan?

So edit your .yaml file to look like this...

network:
  version: 2 
  renderer: networkd                   # note the correct spelling
  ethernets:
    enp0s3:                            # identify the proper interface
      addresses: [10.0.2.100/24]
      gateway4: 10.0.2.1
      nameservers:
        addresses: [10.0.2.100]        # this is probably the wrong address
        addresses: [8.8.8.8, 8.8.4.4]  # use something like this instead

then do:

sudo netplan --debug generate  # generate the config files
sudo netplan apply             # apply the new configuration
reboot                         # reboot the computer

and recheck your ifconfig output.

Note: if it was me, I'd let NetworkManager manage this interface, and set the static address information into the "Wired Connection" profile.

network:
  version: 2
  renderer: NetworkManager

then do:

sudo netplan --debug generate  # generate the config files
sudo netplan apply             # apply the new configuration
reboot                         # reboot the computer
Related Question