No DNS with Ubuntu and Android Hotspot Solution

So on occasion, I rely on my wife’s Macbook Pro as I lack a laptop. Before you judge, understand that it’s dual-booting OS X and Ubuntu MATE 16.04. For obvious reasons, I use the latter.

At home, I’m able to connect to my home wifi network without any issues at all. Pure 802.11n goodness, zero issues whatsoever. Recently, I needed to borrow the laptop for a trip away from the house. I would be relying heavily on the hotspot functionality of my Android phone. Now, my wife does this frequently on OS X, so surely this won’t be a problem for my distro of choice, right? Well, not exactly.

As it turns out, I was able to connect without any issues whatsoever. DNS, however, was not cooperating. After messing with it for a bit, I did some ping tests and determined that the problem was with the DNS settings. No biggie, I’ll just add Google or OpenDNS to the network-manager configuration. After adding it to the network-manager GUI, I rebooted and tried again. Instead of the satisfaction of a seeing webpages load, I was instead doled out an extra helping of “nope.”

Then it hit me – I needed to check my /etc/resolv.conf.

Since using a wifi dongle loaded pages fine using my Android hotspot from my desktop PC, I suspected that the /etc/resolv.confmight be the culprit on the Macbook Pro. After running a cat /etc/resolv.confon both my PC and my wife’s Mac running Ubuntu MATE, I spotted the problem.

My main PC’s /etc/resolv.confwas set to:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.1.1
search home

My wife’s Macbook however, was trying to connect to to the IP for the router instead of 127.0.1.1. Clearly, this isn’t helpful if you’re connecting to an Android hotspot instead. So I did what needed to be done.

sudo echo "nameserver 127.0.1.1" > /etc/resolv.conf

For those not familiar with networking terms, 127.0.1.1 refers to the localhost. If you want a better explanation, you’ll find one here.

Pro Tip: If 127.0.1.1 still doesn’t work for you, use 8.8.8.8 (Google DNS) instead. It’s a dirty hack, but it works.

Now some might suggest that you simply restart networking services. I would suggest going a step further and rebooting the computer exhibiting the symptoms I described above. Odds are good this will fix any DNS issues you’re experiencing.

Note: I do not have dnsmaq installed on any of the computers described in this article. If the above fix doesn’t work for you, odds are you may be using dnsmaq. Goto your package manager and do a search for it to see if you’re running with it. What you do with it, however, is up to you.

NVIDIA Linux Video Game Tearing Fix

Video Tearing

Today’s quick tip should help you to deal with a common NVIDIA video issue that plagues many of us. Some things to consider before going forward include:

1) You’re using X11 and NOT Wayland.

2) This addresses horizontal video game tearing that affects many Linux gamers using NVIDIA cards with the current proprietary video drivers.

3) This assumes you have used sudo nvidia-settings to create and save your own xorg.conf file. Doing this will allow you to make proposed changes (to be mentioned shortly) a permanent part of your video card configuration.

The first step is to see if my suggested tweak will work for you. Do this by pasting this into a terminal window.

nvidia-settings --assign CurrentMetaMode="nvidia-auto-select +0+0 { ForceCompositionPipeline = On }"

What this does is set up a single monitor to use the Composition Pipeline option. You’ll notice that we didn’t use sudo. The reason why is because we’re merely testing this for errors at the user level. If the screen flickers, you start a game and tearing is fixed – then we can make this permanent.

If the game you’re testing shows no signs of horizontal tearing, then it sounds like this fix has worked for you. Now let’s make the changes permanent. You’ll need to run this from a terminal.

sudo nvidia-settings
  • Once the application opens, click on Xserver Display Configuration.
  • Advanced button at the bottom. Verify that Force Composition Pipeline is checked.
  • Click Save to Configuration File. Browse to /etc/X11/ and save the file as xorg.conf
  • Save to X Configuration File, then Quit.

If a xorg.conf file already exists, I recommend backing it up before overwriting it.

Reboot to make sure the settings are good. It’s also worthwhile to paste this in a terminal before rebooting to verify the settings stuck to the xorg.conf file.

cat /etc/X11/xorg.conf

If you see something similar to this in the Section “Screen” area, you’re all set:

Option "metamodes" "nvidia-auto-select +0+0 {ForceCompositionPipeline=On}"

The nvidia-auto-select section may be different. However if the CompositionPipeline section is the same as above, you’re good to go.

Other tweaks and considerations

If you’re still seeing tearing, odds are good you’re using GNOME, KDE or something similar. Try installing XFCE, LXDE, or MATE. I run all my gaming on a MATE desktop and this tweak works great.

Remember – you’re making tweaks to your display server. So it’s your responsibility to backup your configuration before making permanent changes. That said, if you use the userland test mentioned above, you will be able to test this without screwing up anything. Just reboot and everything is reset to normal. The key is to only use the sudo nvidia-settings after a successful tweak test. Good luck!

Ubuntu Server Security Updates Only

upgrade-ubuntu-security

Today’s quick tip is actually a lesser-known way of keeping up your security updates, but doing so without the very buggy unattended-upgrades package for Ubuntu server. Here’s a lesser known way to patch your system that’s less buggy. You’re experiences may vary.

When running updates in an attended state, such as using apt or running the updater, you’ll notice you are prompted to upgrade everything. However, you’ll also notice that in the updates settings that the default is to install security updates automatically. This is awesome…but what about on Ubuntu server – remember, unattended-upgrades doesn’t always work well on all systems.

On my Ubuntu-powered Pi2 for example, unattended-upgrades is a bust. Thankfully, there is a CLI work-around that will allow you to apt upgrade just security updates without unattended-upgrades and without updating everything.

To use apt to manually (or you could script this) install security updates only, try the following:

sudo cp /etc/apt/sources.list /etc/apt/security.sources.list

This creates a special list that, once edited, will be used for security updates only, while leaving sources.list untouched. In security.sources.list, make sure you comment out everything except the security repo. So you’ll make it look something like this:

#deb http://ports.ubuntu.com/ xenial main restricted universe multiverse
#deb-src http://ports.ubuntu.com/ xenial main restricted universe multiverse

#deb http://ports.ubuntu.com/ xenial-updates main restricted universe multiverse
#deb-src http://ports.ubuntu.com/ xenial-updates main restricted universe multiverse

deb http://ports.ubuntu.com/ xenial-security main restricted universe multiverse
deb-src http://ports.ubuntu.com/ xenial-security main restricted universe multiverse

#deb http://ports.ubuntu.com/ xenial-backports main restricted universe multiverse
#deb-src http://ports.ubuntu.com/ xenial-backports main restricted universe multiverse

Once you’ve changed the security.sources.list file to look like it does above, then you’re ready to take this for a test drive.

sudo apt update && sudo apt-get upgrade -o Dir::Etc::SourceList=/etc/apt/security.sources.list

The above command will run the usual upgrade command, but it ensures you’re only using the security.sources.list file. There are two things cool about this.

First, you can still run your apt update && apt upgrade like always to upgrade everything. Secondly, you can script this technique out fairly easily to include options like an automatic reboot if you want. Again, this is assuming you’re dealing with non-GUI situations. I found it to be awesome for my Rasp Pi2.

Write Your Own CPU Meter in Bash

Here’s a fun little project that is a pretty good combination of array use and pattern manipulation.

Screenshot of Bash CPU Meter
Bash CPU Meter
#!/bin/bash
function get_mhz() {
   while read line; do
      if [[ $line =~ cpu\ MHz ]]; then
         local hunks=(${line})
         local ahz=(${hunks[3]})
         local bars=$(( (${ahz%%.*} * (${COLUMNS} - 12) )/3500))
         printf "%s:%${bars}s\n" $ahz '=' | tr ' ' '=' 
      fi  
   done < /proc/cpuinfo
}
while [[ 1 = 1 ]]; do
   stty_line=(`stty size`)
   COLUMNS=${stty_line[1]}
   get_mhz | sort -rn 
   echo ""
   sleep 1
done

I could go on and on about it, but I’d rather you just ask me questions.