10

The 18.04 server installation process creates /etc/cloud/cloud.cfg.d/50-curtin-networking.cfg, which, in turn, seems to generate /etc/netplan/50-cloud-init.yaml. I can't seem to find exactly how 50-cloud-init.yaml gets generated from 50-curtin-networking.cfg though.

What is the recommended way to manage IP addresses on an 18.04 server? Edit 50-curtin-networking.cfg, and then run some command (?) to update 50-cloud-init.yaml? Or some other process?

Melebius
  • 11,121
  • 8
  • 50
  • 77
kartik_subbarao
  • 256
  • 3
  • 10
  • `network-config` generates `50-cloud-init.cfg`. and `cloud-init` ( http://cloudinit.readthedocs.io/en/latest/ ) triggers `network-config` ( http://cloudinit.readthedocs.io/en/latest/topics/network-config.html ). That happens on initial creation, and on restarting but only when your force it. – Rinzwind May 23 '18 at 14:00
  • I don't have any files named `50-cloud-init.cfg` -- I have `50-curtin-networking.cfg` and `50-cloud-init-yaml`. Did you mean the former? If so, how exactly do you "force" cloud-init to regenerate `50-cloud-init.yaml` from `50-curtin-networking.cfg`? – kartik_subbarao May 23 '18 at 15:18

4 Answers4

4

Make your networking changes to the /etc/cloud/cloud.cfg.d/50-curtin-networking.cfg file as if you were putting them in the yaml file.

Then do the following:

sudo cloud-init clean
sudo cloud-init init
sudo netplan apply

This will process your 50-curtin-networking.cfg file, generate the 50-cloud-init.yaml file and apply the yaml file netplan configuration.

In this way, you can write your networking config in the 50-curtin-networking.cfg file as the comments imply you should do.

A lot of the confusion between setting networking up in the 50-cloud-init.yaml file vs the 01-netcfg.yaml found in the /etc/netplan directory comes down to the installer used for Ubuntu 18.04 LTS.

The live installer uses cloud-init, whereas the alternate installer does not.

So for networking your installer choice changes how you will set up networking.

ubuntu-18.04.1-server-amd64.iso -> 01-netcfg.yaml ubuntu-18.04.1-live-server-amd64.iso -> 50-curtin-networking.cfg

JargonMan
  • 127
  • 1
  • 5
  • 3
    You don't want to call cloud-init clean unless you're setting this machine up to be a cloud image. cloud-init is designed to run the first time you boot a machine (eg when deploying a new VM). – dmuir Feb 08 '19 at 05:53
  • Yes, I ran cloud-init and it re-initialized SSH keys on my existing server. – Mitar Aug 22 '21 at 09:52
2

I assume this is an ordinary server, behind a router or switch that then connects to the internet. I'd rename the 50-cloud-init.yaml file:

sudo mv /etc/netplan/50-cloud-init.yaml  /etc/netplan/01-netcfg.yaml 

Then find out the relevant interface name:

ifconfig 

Assuming, for an example, that your relevant interface is enp0s25, edit the file:

sudo nano /etc/netplan/01-netcfg.yaml 

Amend the file to read:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s25:
      addresses: [192.168.100.40/22]
      gateway4: 192.168.100.1
      nameservers:
        addresses: [8.8.8.8,8.8.4.4]

Of course, substitute your exact details here. Spacing, indentation, etc. are crucial. Proofread carefully. Save (Ctrl+O followed by Enter) and close (Ctrl+X) the text editor.

Next:

sudo netplan apply
sudo ip link set enp0s25 down
sudo ip link set enp0s25 up

Did you get the requested IP address?

ip addr show

Can you ping?

ping -c3 8.8.8.8
ping -c3 www.ubuntu.com

If you get ping returns, you are all set.

Martin Thornton
  • 5,151
  • 11
  • 30
  • 39
chili555
  • 58,968
  • 8
  • 93
  • 129
  • It seems like you're suggesting that the text at the top of 50-cloud-init.yaml, warning against editing it manually, should be ignored :-) This may end up being the approach taken, but I'd ideally like to understand why that text is there in the first place. Presumably the designers had some workflow in mind when they created that process. And what about /etc/cloud/cloud.cfg.d/50-curtin-networking.cfg? – kartik_subbarao May 14 '18 at 21:01
  • I've renamed the question to hopefully make it clearer. – kartik_subbarao May 14 '18 at 21:16
  • Is this a cloud instance? – chili555 May 14 '18 at 21:16
  • No, it is not a cloud instance. It is a standalone server on an internal network. – kartik_subbarao May 15 '18 at 12:20
  • That's what I meant above when I said, "I assume this is an ordinary server, ..." Please check here: https://blog.printk.io/2018/04/ubuntu-18-04-lts-bionic-beaver-server-installer-differences/ I still think 01-netcfg.yaml is appropriate. – chili555 May 15 '18 at 13:03
  • I saw this post. Unfortunately, the author has the same uncertainty that I do: _While the netplan file warns that it might get overwritten, I was not able to use the cloud-init file to change the netplan network configuration… I am not 100% sure if it is safe to edit the netplan directly in the default configuration._ I'm asking here to see if someone (perhaps one of the Ubuntu developers?) has the 100% authoritative answer on this question. – kartik_subbarao May 15 '18 at 16:34
  • This answer is a good answer. Ironically the author wrote "Spacing, indentation, etc. are crucial. Proofread carefully." And there's an error in the code. The line "addresses" in the YAML needs to be indented. It is an attribute of nameservers. Thanks for the tip, though, it helped me. – Paco Hope Feb 02 '19 at 09:39
  • Ironically, @PacoHope the author, hanging his head, made a small edit. Thanks for the heads up. – chili555 Feb 03 '19 at 23:56
0

I ended up editing the /etc/systemd/resolved.conf file and removed the comment on the DNS= line and added my preferred DNS entries with a space separating entries I.E.: DNS = 8.8.8.8 8.8.4.4

0

For me in Ubuntu 19.04 cloud-init init doesn't write 50-curtin-networking.cfg to 50-cloud-init.yaml unless you ask systemctl to restart the cloud-init-local service ...

cloud-init clean
systemctl restart cloud-init-local.service
netplan apply
Master James
  • 291
  • 4
  • 11