{"id":1946,"date":"2020-03-22T16:12:47","date_gmt":"2020-03-22T16:12:47","guid":{"rendered":"http:\/\/mclements.net\/blogWP\/?p=1946"},"modified":"2020-03-26T15:30:24","modified_gmt":"2020-03-26T15:30:24","slug":"ubuntu-16-and-slow-network","status":"publish","type":"post","link":"http:\/\/mclements.net\/blogWP\/index.php\/2020\/03\/22\/ubuntu-16-and-slow-network\/","title":{"rendered":"Ubuntu 18 and Slow Network"},"content":{"rendered":"<p>Recently my Ubuntu 18 laptop had intermittent very slow internet\/network. After checking the usual causes (router, WiFi, etc.), I found this <a href=\"https:\/\/itsfoss.com\/speed-up-slow-wifi-connection-ubuntu\/\">helpful article<\/a>. Turns out what fixed it was one of those suggestions.<\/p>\n<p>Edit this file:<\/p>\n<pre>sudo vi \/etc\/nsswitch.conf<\/pre>\n<p>Then change the line that says:<\/p>\n<pre class=\"wp-block-preformatted\">hosts: \u00a0 \u00a0 \u00a0 \u00a0 \u00a0files mdns4_minimal [NOTFOUND=return] dns mdns<\/pre>\n<p>To this:<\/p>\n<pre class=\"wp-block-preformatted\">hosts: \u00a0 \u00a0 \u00a0 \u00a0 \u00a0files dns mdns4_minimal [NOTFOUND=return] mdns<\/pre>\n<p>So, in hindsight, it seems to have been a DNS problem.<\/p>\n<p><strong>Update 1<\/strong><\/p>\n<p>While this seemed to fix the problem temporarily, network problems started again. After an hour or two of reading about the issue, I made another change. I learned that Ubuntu 18 changed the way network is configured, using a new service called &#8220;netplan&#8221;. The <strong>\/etc\/netplan<\/strong> directory should have config files, but mine was empty! I don&#8217;t know how it got emptied; I certainly didn&#8217;t do it. But I needed to create a default config file. I created a file called <strong>01-netcfg.yaml<\/strong>:<\/p>\n<pre>network:\r\n  version: 2\r\n  renderer: networkd\r\n#  ethernets:\r\n#    wlan0:\r\n#      dhcp4: true\r\n#      nameservers:\r\n#        addresses: [192.168.1.1]<\/pre>\n<p>After some experimentation I commented out the last few lines. This tells Ubuntu that the network manager service will control network. Then I configured it in the network WiFi GUI, enabling DHCP wasn&#8217;t enough; I also added my home router (192.168.1.1) to the DNS list.<\/p>\n<p>Networking (more specifically, DNS resolution) was still slow and occasionally intermittent. Finally, I had to flush the DNS cache:<\/p>\n<pre>sudo systemd-resolve --flush-caches<\/pre>\n<p>Now, everything seems to be working again.<\/p>\n<p><strong>Update 2<\/strong><\/p>\n<p>This too only fixed things temporarily. I still was getting intermittent network problems &#8211; but only on WiFi, not when wired. It looks like Ubuntu 18&#8217;s new &#8220;netplan&#8221; was conflicting with the &#8220;networking&#8221; service. I configured netplan and stopped the networking service. That is:<\/p>\n<p>In the <strong>\/etc\/netplan<\/strong> directory, I had this file named <strong>10-netcfg.yaml<\/strong>, which tells the system that the desktop Network Manager app will control network setup:<\/p>\n<pre>network:\r\nversion: 2\r\nrenderer: NetworkManager<\/pre>\n<p>I created additional files AFTER the ones that are there, so they override this. These files look like this:<\/p>\n<p>20-wlan0.yaml<\/p>\n<pre># Enable this only if you don't want to use the desktop GUI\r\nnetwork:\r\n  ethernets:\r\n    wlan0:\r\n      addresses: []\r\n      dhcp4: true\r\n      optional: true\r\n  version: 2<\/pre>\n<p>30-eth0.yaml<\/p>\n<pre># Enable this only if you don't want to use the desktop GUI\r\nnetwork:\r\n  ethernets:\r\n    wlan0:\r\n      addresses: []\r\n      dhcp4: true\r\n      optional: true\r\n  version: 2<\/pre>\n<p>Because they sort after the first file, they override it. Next, run this command:<\/p>\n<pre>mclement@clements6:~$ sudo netplan --debug generate\r\nDEBUG:command generate: running ['\/lib\/netplan\/generate']\r\n** (generate:27016): DEBUG: 09:12:23.854: Processing input file \/etc\/netplan\/10-netcfg.yaml..\r\n** (generate:27016): DEBUG: 09:12:23.854: starting new processing pass\r\n** (generate:27016): DEBUG: 09:12:23.854: Processing input file \/etc\/netplan\/20-wlan0.yaml..\r\n** (generate:27016): DEBUG: 09:12:23.854: starting new processing pass\r\n** (generate:27016): DEBUG: 09:12:23.854: Processing input file \/etc\/netplan\/30-eth0.yaml..\r\n** (generate:27016): DEBUG: 09:12:23.854: starting new processing pass\r\n** (generate:27016): DEBUG: 09:12:23.854: wlan0: setting default backend to 2\r\n** (generate:27016): DEBUG: 09:12:23.854: Configuration is valid\r\n** (generate:27016): DEBUG: 09:12:23.854: eth0: setting default backend to 2\r\n** (generate:27016): DEBUG: 09:12:23.854: Configuration is valid\r\n** (generate:27016): DEBUG: 09:12:23.855: Generating output files..\r\n** (generate:27016): DEBUG: 09:12:23.855: networkd: definition wlan0 is not for us (backend 2)\r\n** (generate:27016): DEBUG: 09:12:23.855: networkd: definition eth0 is not for us (backend 2)<\/pre>\n<p>Note the last 2 lines, which is &#8220;networkd&#8221; saying it won&#8217;t be managing these network connections.<\/p>\n<p>Next, apply this configuration<\/p>\n<pre>mclement@clements6:~$ sudo netplan apply<\/pre>\n<p>Now, disable the system networking service<\/p>\n<pre>sudo service networking stop<\/pre>\n<p>At this point, my WiFi networking started working again, and was not slow anymore.<\/p>\n<p><strong>Update 3<\/strong><\/p>\n<p>Sigh&#8230; this again was only a temporary fix. Even after all of the above, network was still slow! Then I remembered that I was using 5 GHz WiFi, which has different frequencies\/channels in different regions, so requires the device to know what country it is in. So I changed one more thing. Edit the file <strong>\/etc\/default\/crda<\/strong> and set my country code. That is, the file originally looked like this:<\/p>\n<pre># Set REGDOMAIN to a ISO\/IEC 3166-1 alpha2 country code so that iw(8) may set\r\n# the initial regulatory domain setting for IEEE 802.11 devices which operate\r\n# on this system.\r\n#\r\n# Governments assert the right to regulate usage of radio spectrum within\r\n# their respective territories so make sure you select a ISO\/IEC 3166-1 alpha2\r\n# country code suitable for your location or you may infringe on local\r\n# legislature. See `\/usr\/share\/zoneinfo\/zone.tab' for a table of timezone\r\n# descriptions containing ISO\/IEC 3166-1 alpha2 country codes.\r\n\r\nREGDOMAIN=<\/pre>\n<p>Note that REGDOMAIN was not set. I changed that last line to this:<\/p>\n<pre>REGDOMAIN=US<\/pre>\n<p>Since &#8220;US&#8221; is the code for my country.<\/p>\n<p>What is interesting, is that I tested and 2.4 GHz WiFi worked fine all along. It was only 5 GHz WiFi that was intermittently broken. This would be consistent with not having the region set.<\/p>\n<p>Given all this, I reverted the netplan changes above, so the desktop NetworkManager controls my networking.<\/p>\n<p><strong>Update 4<\/strong><\/p>\n<p>Again, this still didn&#8217;t fix the problem. However, the problem may have been the channel I was using on 5 GHz. <a href=\"https:\/\/bbs.archlinux.org\/viewtopic.php?id=183618\">This thread<\/a> was helpful. Channel 149 was listed by &#8220;iw list&#8221;, but not by &#8220;iwlist chan&#8221;. I changed the router to use channel 48, which appears in both lists, and it is now working.<\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<p>There&#8217;s a lot here, some of which wasn&#8217;t necessary. In summary, the fix was:<\/p>\n<p>Configure <strong>\/etc\/netplan<\/strong> to tell the desktop Network Manager GUI to manage network connections. This is the default Ubuntu desktop setup.<\/p>\n<p>Set <strong>\/etc\/default\/crda<\/strong> to set the system country code (needed for 5 GHz).<\/p>\n<p>Run <strong>iw list<\/strong> and <strong>iwlist chan<\/strong> to see which 5 GHz channels the WiFi card supports.<\/p>\n<p>Configure my router to use one of these 5 GHz channels.<\/p>\n<p>BANG! It&#8217;s still working overnight, fast and reliable. Problem solved.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently my Ubuntu 18 laptop had intermittent very slow internet\/network. After checking the usual causes (router, WiFi, etc.), I found this helpful article. Turns out what fixed it was one of those suggestions. Edit this file: sudo vi \/etc\/nsswitch.conf Then change the line that says: hosts: \u00a0 \u00a0 \u00a0 \u00a0 \u00a0files mdns4_minimal [NOTFOUND=return] dns mdns &hellip; <a href=\"http:\/\/mclements.net\/blogWP\/index.php\/2020\/03\/22\/ubuntu-16-and-slow-network\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Ubuntu 18 and Slow Network<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-1946","post","type-post","status-publish","format-standard","hentry","category-tech"],"_links":{"self":[{"href":"http:\/\/mclements.net\/blogWP\/index.php\/wp-json\/wp\/v2\/posts\/1946","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/mclements.net\/blogWP\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/mclements.net\/blogWP\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/mclements.net\/blogWP\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/mclements.net\/blogWP\/index.php\/wp-json\/wp\/v2\/comments?post=1946"}],"version-history":[{"count":9,"href":"http:\/\/mclements.net\/blogWP\/index.php\/wp-json\/wp\/v2\/posts\/1946\/revisions"}],"predecessor-version":[{"id":1955,"href":"http:\/\/mclements.net\/blogWP\/index.php\/wp-json\/wp\/v2\/posts\/1946\/revisions\/1955"}],"wp:attachment":[{"href":"http:\/\/mclements.net\/blogWP\/index.php\/wp-json\/wp\/v2\/media?parent=1946"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/mclements.net\/blogWP\/index.php\/wp-json\/wp\/v2\/categories?post=1946"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/mclements.net\/blogWP\/index.php\/wp-json\/wp\/v2\/tags?post=1946"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}