{"id":4316,"date":"2022-02-11T02:46:12","date_gmt":"2022-02-11T09:46:12","guid":{"rendered":"http:\/\/www.sheer.us\/weblogs\/?p=4316"},"modified":"2022-02-11T02:46:44","modified_gmt":"2022-02-11T09:46:44","slug":"setting-a-static-ip-on-ubuntu-20-04-with-cloud-init","status":"publish","type":"post","link":"http:\/\/www.sheer.us\/weblogs\/it\/setting-a-static-ip-on-ubuntu-20-04-with-cloud-init","title":{"rendered":"Setting a static IP on ubuntu 20.04 with cloud-init"},"content":{"rendered":"<p>So, it took me numerous tries, digging, and beating of head against curtin and the like, but I have finally figured out how to set a static IP on a host using cloud-init.<\/p>\n<p>Mind you, I am not talking about setting a static iP for while the installer is running. That&#8217;s easy, and well documented. I&#8217;m talking about the next time it boots. <\/p>\n<p>The solution requires two bits. They&#8217;re pretty straightforward, and both go in the cloud-init file<\/p>\n<p>Bit one goes at the end of the autoinstall section, and deletes the default configuration and writes a permanent one instead. <I>Note that the filesystem is mounted as \/target<\/I><br \/>\n<PRE><br \/>\n  late-commands:<br \/>\n  &#8211; rm \/target\/etc\/cloud\/cloud.cfg.d\/50-curtin-networking.cfg<br \/>\n  &#8211; mv \/tmp\/00-installer-config.yaml \/target\/etc\/netplan<br \/>\n<\/PRE><\/p>\n<p>Bit two actually writes out the \/tmp\/00-installer-config.yaml that late-commands will be editing<\/p>\n<p><PRE><br \/>\nwrite_files:<br \/>\n  &#8211; path: \/tmp\/00-installer-config.yaml<br \/>\n    owner: root:root<br \/>\n    permissions: &#8220;0644&#8221;<br \/>\n    content: |<br \/>\n      network:<br \/>\n        version: 2<br \/>\n        ethernets:<br \/>\n          ens160:<br \/>\n            critical: true<br \/>\n            dhcp-identifier: mac<br \/>\n            dhcp4: true<br \/>\n          ens192:<br \/>\n            dhcp4: no<br \/>\n            addresses:<br \/>\n            &#8211; {ipaddr}\/16<br \/>\n            gateway4: 172.16.1.1<br \/>\n            nameservers:<br \/>\n              addresses:<br \/>\n              &#8211; 172.16.5.6<br \/>\n              search:<br \/>\n              &#8211; search.domain<br \/>\n<\/PRE><\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, it took me numerous tries, digging, and beating of head against curtin and the like, but I have finally figured out how to set a static IP on a host using cloud-init. Mind you, I am not talking about setting a static iP for while the installer is running. That&#8217;s easy, and well documented. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32,11],"tags":[],"_links":{"self":[{"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/posts\/4316"}],"collection":[{"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/comments?post=4316"}],"version-history":[{"count":2,"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/posts\/4316\/revisions"}],"predecessor-version":[{"id":4318,"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/posts\/4316\/revisions\/4318"}],"wp:attachment":[{"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/media?parent=4316"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/categories?post=4316"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/tags?post=4316"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}