{"id":80,"date":"2018-10-17T03:24:10","date_gmt":"2018-10-17T03:24:10","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/17\/have-a-plan-for-netplan\/"},"modified":"2018-10-17T03:24:10","modified_gmt":"2018-10-17T03:24:10","slug":"have-a-plan-for-netplan","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/17\/have-a-plan-for-netplan\/","title":{"rendered":"Have a Plan for Netplan"},"content":{"rendered":"<p><em>Ubuntu changed networking. Embrace the YAML.<\/em><\/p>\n<p>\nIf I&#8217;m being completely honest, I still dislike the switch from eth0,<br \/>\neth1, eth2 to names like, enp3s0, enp4s0, enp5s0. I&#8217;ve learned to accept<br \/>\nit and mutter to myself while I type in unfamiliar interface names. Then I<br \/>\ninstalled the new LTS version of Ubuntu and typed vi<br \/>\n\/etc\/network\/interfaces. Yikes. After a technological lifetime of entering<br \/>\nmy server&#8217;s IP information in a simple text file, that&#8217;s no longer how<br \/>\nthings are done. Sigh. The good news is that while figuring out Netplan for<br \/>\nboth desktop and server environments, I fixed a nagging DNS issue I&#8217;ve had<br \/>\nfor years (more on that later).\n<\/p>\n<h3>\nThe Basics of Netplan<\/h3>\n<p>\nThe old way of configuring Debian-based network interfaces was based on the<br \/>\nifupdown package. The new default is called Netplan, and<br \/>\nalthough it&#8217;s not<br \/>\nterribly difficult to use, it&#8217;s drastically different. Netplan is sort of<br \/>\nthe interface used to configure the back-end d\u00e6mons that actually<br \/>\nconfigure the interfaces. Right now, the back ends supported are<br \/>\nNetworkManager and networkd.\n<\/p>\n<p>\nIf you tell Netplan to use NetworkManager, all interface configuration<br \/>\ncontrol is handed off to the GUI interface on the desktop. The<br \/>\nNetworkManager program itself hasn&#8217;t changed; it&#8217;s the same GUI-based<br \/>\ninterface configuration system you&#8217;ve likely used for years.\n<\/p>\n<p>\nIf you tell Netplan to use networkd, systemd itself handles the interface<br \/>\nconfigurations. Configuration is still done with Netplan files, but once<br \/>\n&#8220;applied&#8221;, Netplan creates the back-end configurations systemd requires. The<br \/>\nNetplan files are vastly different from the old \/etc\/network\/interfaces<br \/>\nfile, but it uses YAML syntax, and it&#8217;s pretty easy to figure out.\n<\/p>\n<h3>\nThe Desktop and DNS<\/h3>\n<p>\nIf you install a GUI version of Ubuntu, Netplan is configured with<br \/>\nNetworkManager as the back end by default. Your system should get IP<br \/>\ninformation via DHCP or static entries you add via GUI. This is usually not<br \/>\nan issue, but I&#8217;ve had a terrible time with my split-DNS setup and<br \/>\nsystemd-resolved. I&#8217;m sure there is a magical combination of configuration<br \/>\nfiles that will make things work, but I&#8217;ve spent a lot of time, and it<br \/>\nalways behaves a little oddly. With my internal DNS server resolving domain<br \/>\nnames differently from external DNS servers (that is, split-DNS), I get random<br \/>\nlookup failures. Sometimes ping will resolve, but<br \/>\ndig will not. Sometimes<br \/>\nthe internal A record will resolve, but a CNAME will not. Sometimes I get<br \/>\nresolution from an external DNS server (from the internet), even though I<br \/>\nnever configure anything other than the internal DNS!\n<\/p>\n<p>\nI decided to disable systemd-resolved. That has the potential to break DNS<br \/>\nlookups in a VPN, but I haven&#8217;t had an issue with that. With<br \/>\nresolved<br \/>\nhandling DNS information, the \/etc\/resolv.conf file points to 127.0.0.53 as<br \/>\nthe nameserver. Disabling systemd-resolved will stop the automatic creation<br \/>\nof the file. Thankfully, NetworkManager itself can handle the creation and<br \/>\nmodification of \/etc\/resolv.conf. Once I make that change, I no longer have<br \/>\nan issue with split-DNS resolution. It&#8217;s a three-step process:\n<\/p>\n<ol>\n<li>\nDo sudo systemctl disable systemd-resolved.service.\n<\/li>\n<li>\nThen sudo rm \/etc\/resolv.conf (get rid of the symlink).\n<\/li>\n<li>\nEdit the \/etc\/NetworkManager\/NetworkManager.conf file, and in the<br \/>\n[main]<br \/>\nsection, add a line that reads DNS=default.<\/li>\n<\/ol>\n<p>\nOnce those steps are complete, NetworkManager itself will create the<br \/>\n\/etc\/resolv.conf file, and the DNS server supplied via DHCP or static entry<br \/>\nwill be used instead of a 127.0.0.53 entry. I&#8217;m not sure why the<br \/>\nresolved<br \/>\nd\u00e6mon incorrectly resolves internal addresses for me, but the above method<br \/>\nhas been foolproof, even when switching between networks with my<br \/>\nlaptop.\n<\/p>\n<h3>\nNetplan CLI Configuration<\/h3>\n<p>\nIf Ubuntu is installed in server mode, it is almost certainly configured to<br \/>\nuse networkd as the back end. To check, have a look at the<br \/>\n\/etc\/netplan\/config.yaml file. The renderer should be set to<br \/>\nnetworkd<br \/>\nin order to use the systemd-networkd back end. The file should look<br \/>\nsomething like this:<\/p>\n<p>network:<br \/>\n version: 2<br \/>\n renderer: networkd<br \/>\n ethernets:<br \/>\n enp2s0:<br \/>\n dhcp4: true<\/p>\n<p><em>Important note:<\/em> remember that with<br \/>\nYAML files, whitespace matters, so the indentation is important. It&#8217;s also<br \/>\n<em>very<\/em> important to remember that after making any changes, you need to<br \/>\nrun sudo netplan apply so the back-end configuration files are<br \/>\npopulated.<\/p>\n<p>\nThe default renderer is networkd, so it&#8217;s possible you won&#8217;t have that line<br \/>\nin your configuration file. It&#8217;s also possible your configuration file will<br \/>\nbe named something different in the \/etc\/netplan folder. All .conf files<br \/>\nare read, so it doesn&#8217;t matter what it&#8217;s called as long as it ends with<br \/>\n.conf. Static configurations are fairly simple to set up:<\/p>\n<p>network:<br \/>\n version: 2<br \/>\n renderer: networkd<br \/>\n ethernets:<br \/>\n enp2s0:<br \/>\n dhcp4: no<br \/>\n addresses:<br \/>\n &#8211; 192.168.1.10\/24<br \/>\n &#8211; 10.10.10.10\/16<br \/>\n gateway4: 192.168.1.1<br \/>\n nameservers:<br \/>\n addresses: [192.168.1.1, 8.8.8.8]<\/p>\n<p>\nNotice I&#8217;ve assigned multiple IP addresses to the interface. Netplan does<br \/>\nnot support virtual interfaces like enp3s0:0, rather multiple IP<br \/>\naddresses can be assigned to a single interface.\n<\/p>\n<p>\nUnfortunately, networkd doesn&#8217;t create an \/etc\/resolv.conf file if you<br \/>\ndisable the resolved d\u00e6mon. If you have problems with split-DNS on a<br \/>\nheadless computer, the best solution I&#8217;ve come up with is to disable<br \/>\nsystemd-resolved and then manually create an \/etc\/resolv.conf file. Since<br \/>\nheadless computers don&#8217;t usually move around as much as laptops, it&#8217;s likely<br \/>\nthe \/etc\/resolv.conf file won&#8217;t need to be changed. Still, I wish<br \/>\nnetworkd<br \/>\nhad an option to manage the resolv.conf file the same way<br \/>\nNetworkManager<br \/>\ndoes.\n<\/p>\n<h3>\nAdvanced Network Configurations<\/h3>\n<p>\nThe configuration formats are different, but it&#8217;s still possible to do more<br \/>\nadvanced network configurations with Netplan:\n<\/p>\n<p>\n<em>Bonding:<\/em><\/p>\n<p>network:<br \/>\n version: 2<br \/>\n renderer: networkd<br \/>\n bonds:<br \/>\n bond0:<br \/>\n dhcp4: yes<br \/>\n interfaces:<br \/>\n &#8211; enp2s0<br \/>\n &#8211; enp3s0<br \/>\n parameters:<br \/>\n mode: active-backup<br \/>\n primary: enp2s0<\/p>\n<p>\nThe various bonding modes (balance-rr,<br \/>\nactive-backup, balance-xor,<br \/>\nbroadcast, 802.3ad, balance-tlb and<br \/>\nbalance-alb) are supported.\n<\/p>\n<p>\n<em>Bridging:<\/em><\/p>\n<p>network:<br \/>\n version: 2<br \/>\n renderer: networkd<br \/>\n bridges:<br \/>\n br0:<br \/>\n dhcp4: yes<br \/>\n interfaces:<br \/>\n &#8211; enp4s0<br \/>\n &#8211; enp3s0<\/p>\n<p>\nBridging is even simpler to set up. This configuration creates a bridge<br \/>\ndevice using the two interfaces listed. The device (br0) gets address<br \/>\ninformation via DHCP.\n<\/p>\n<h3>\nCLI Networking Commands<\/h3>\n<p>\nIf you&#8217;re a crusty old sysadmin like me, you likely type<br \/>\nifconfig to see<br \/>\nIP information without even thinking. Unfortunately, those tools are not<br \/>\nusually installed by default. This isn&#8217;t actually the fault of Ubuntu and<br \/>\nNetplan; the old ifconfig toolset has been deprecated. If you want to use<br \/>\nthe old ifconfig tool, you can install the package:<\/p>\n<p>sudo apt install net-tools<\/p>\n<p>\nBut, if you want to do it the &#8220;correct&#8221; way, the new &#8220;ip&#8221; tool is the proper<br \/>\nway to do it. Here are some equivalents of things I commonly do with<br \/>\nifconfig:\n<\/p>\n<p>\n<em>Show network interface information.<\/em>\n<\/p>\n<p>\nOld way:<\/p>\n<p>ifconfig<\/p>\n<p>\nNew way:<\/p>\n<p>ip address show<\/p>\n<p>\n(Or you can just do ip a, which is actually less typing than<br \/>\nifconfig.)\n<\/p>\n<p>\n<em>Bring interface up.<\/em>\n<\/p>\n<p>\nOld way:<\/p>\n<p>ifconfig enp3s0 up<\/p>\n<p>\nNew way:<\/p>\n<p>ip link set enp3s0 up<\/p>\n<p>\n<em>Assign IP address.<\/em>\n<\/p>\n<p>\nOld way:<\/p>\n<p>ifconfig enp3s0 192.168.1.22<\/p>\n<p>\nNew way:<\/p>\n<p>ip address add 192.168.1.22 dev enp3s0<\/p>\n<p>\n<em>Assign complete IP information.<\/em>\n<\/p>\n<p>\nOld way:<\/p>\n<p>ifconfig enp3s0 192.168.1.22 net mask 255.255.255.0 broadcast<br \/>\n \u21aa192.168.1.255<\/p>\n<p>\nNew way:<\/p>\n<p>ip address add 192.168.1.22\/24 broadcast 192.168.1.255<br \/>\n \u21aadev enp3s0<\/p>\n<p>\n<em>Add alias interface.<\/em>\n<\/p>\n<p>\nOld way:<\/p>\n<p>ifconfig enp3s0:0 192.168.100.100\/24<\/p>\n<p>\nNew way:<\/p>\n<p>ip address add 192.168.100.100\/24 dev enp3s0 label enp3s0:0<\/p>\n<p>\n<em>Show the routing table.<\/em>\n<\/p>\n<p>\nOld way:<\/p>\n<p>route<\/p>\n<p>\nNew way:<\/p>\n<p>ip route show<\/p>\n<p>\n<em>Add route.<\/em>\n<\/p>\n<p>\nOld way:<\/p>\n<p>route add -net 192.168.55.0\/24 dev enp4s0<\/p>\n<p>\nNew way:<\/p>\n<p>ip route add 192.168.55.0\/24 dev enp4s0<\/p>\n<h3>\nOld Dogs and New Tricks<\/h3>\n<p>\nI hated Netplan when I first installed Ubuntu 18.04. In fact, on the<br \/>\nparticular server I was installing, I actually started over and installed<br \/>\n16.04 because it was &#8220;comfortable&#8221;. After a while, curiosity got the better<br \/>\nof me, and I investigated the changes. I&#8217;m still more comfortable with the<br \/>\nold \/etc\/network\/interfaces file, but I have to admit, Netplan makes a<br \/>\nlittle more sense. There is a single &#8220;front end&#8221; for configuring networks,<br \/>\nand it uses different back ends for the heavy lifting. Right now, the only<br \/>\nback ends are the GUI NetworkManager and the systemd-networkd<br \/>\nd\u00e6mon. With<br \/>\nthe modular system, however, that could change someday without the need to<br \/>\nlearn a new way of configuring interfaces. A simple change to the<br \/>\nrenderer line would send the configuration information to a new back end.\n<\/p>\n<p>\nWith regard to the new command-line networking tool (ip vs.<br \/>\nifconfig),<br \/>\nit really behaves more like other network devices (routers and so on), so that&#8217;s<br \/>\nprobably a good change as well. As technologists, we need to be ready and<br \/>\neager to learn new things. If we weren&#8217;t always trying the next best thing,<br \/>\nwe&#8217;d all be configuring Trumpet Winsock to dial in to the internet on our<br \/>\nWindows 95 machines. I&#8217;m glad I tried that new Linux thing, and while it<br \/>\nwasn&#8217;t quite as dramatic, I&#8217;m glad I tried Netplan as well!\n<\/p>\n<p> <a href=\"https:\/\/www.linuxjournal.com\/content\/have-plan-netplan\" target=\"_blank\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ubuntu changed networking. Embrace the YAML. If I&#8217;m being completely honest, I still dislike the switch from eth0, eth1, eth2 to names like, enp3s0, enp4s0, enp5s0. I&#8217;ve learned to accept it and mutter to myself while I type in unfamiliar interface names. Then I installed the new LTS version of Ubuntu and typed vi \/etc\/network\/interfaces. &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/17\/have-a-plan-for-netplan\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Have a Plan for Netplan&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-80","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/80","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=80"}],"version-history":[{"count":0,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/80\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=80"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=80"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=80"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}