5

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?

3

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
      dhcp4: no
      dhcp6: no
      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
| improve this answer | |
  • since the netplan config is in /etc/netplan/50-cloud-init.yaml it is likely this is a cloud image which has no NetworkManager installed. – slangasek Oct 25 '18 at 5:20
  • 1
    Why do you must reboot? Is there any other way? – Nimitack Dec 17 '18 at 9:19
  • @Nimitack technically, the sudo netplan -debug generate and sudo netplan apply commands should do it, but I've seen cases where it didn't, and a reboot will actually start with the netplan configuration you've set, and you can confirm that it's working as expected. – heynnema Dec 17 '18 at 13:29
  • 1
    I see this issue on vmware machine and on virtual box.. when I install ubuntu 18.04... I really need this to NOT reboot.. I couldn't find anything about this on the web.. this is pretty basic stuff, static IP. I don't understand why to reset it.. it's not hardware or so..., Linux is all about NOT rebooting right? – Nimitack Dec 18 '18 at 12:48
  • 1
    @Nimitack I'm confused. I indicated that a reboot is not mandatory, however, it MAY be required if the sudo netplan apply doesn't do it. – heynnema Dec 18 '18 at 14:30
0

Hi I have experienced the same issue working with ubuntu 18.04 .The config file aplies the changes good for dhcp interfaces and for static ip´s I had to do first as a root (or whith sudo if not) this steps

  1. ip link set enp0s(x) down
  2. ip addr add x.x.x.x/x.x.x.x dev enp0s(x).
  3. ip link set enp0s(x) up
  4. and then configure the same interface with same values at /etc/netplan/*.yaml

I think the steps are in this order but I´m not sure, but of course you must up and down the interface and config the interface with both ip addr and the netplan config file. After some attemps that worked for me and after reboot everything continues working, I didn´t lose any config value

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.