0

By default cloud-init generates the following inside 50-cloud-init.yaml

network:
    version: 2
    ethernets:
        eth0:
            addresses:
            - 145.239.202.202/32
            - 2001:41d0:800:226f::3/128
            gateway4: 51.89.172.254
            gateway6: 2001:41d0:800:22ff:ff:ff:ff:ff
            match:
                macaddress: 02:00:00:ff:3b:ea
            nameservers:
                addresses:
                - 213.186.33.99
                search: []
            set-name: eth0

However I need to add routes: to the file to get the network working (OVH)

50-cloud-init.yaml :

network:
    version: 2
    ethernets:
        eth0:
            addresses:
            - 145.239.202.202/32
            - 2001:41d0:800:226f::3/128
            gateway4: 51.89.172.254
            gateway6: 2001:41d0:800:22ff:ff:ff:ff:ff
            match:
                macaddress: 02:00:00:ff:3b:ea
            nameservers:
                addresses:
                - 213.186.33.99
                search: []
            set-name: eth0
            routes:
            - to: 51.89.172.254/32
              via: 0.0.0.0
              scope: link
            - to: 2001:41d0:800:22ff:ff:ff:ff:ff
              scope: link

The only difference is there is the following added at the bottom:

        routes:
        - to: 51.89.172.254/32
          via: 0.0.0.0
          scope: link
        - to: 2001:41d0:800:22ff:ff:ff:ff:ff
          scope: link

How do I modify cloud-init template so that this is added by default so that if I re-run cloud-init init it will not remove it.

  • dhcp4: no and dhcp6: no are the defaults, so you don't need to specify (and use true/false). You can't use gateway4 and gateway6 when you use routes. match/macaddress is not necessary if you only have one ethernet interface. netplan will try to merge the two files anyway, so why not make one clear file that outlines your intent? – heynnema Apr 27 at 22:02
  • I can merge them but that's not all that's going on here I need to somehow change the way 50-cloud-init.yaml sets the IP addresses and add to it. For example routes: is not added by default. – HG2020 Apr 27 at 22:40
  • Your routes are wrong anyway. Please see my answer. Report back. – heynnema Apr 27 at 23:57

Your Answer

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

Browse other questions tagged or ask your own question.