Browsed by
Tag: tip

Setting up VPN on ubuntu 19.10 and getting DNS to work correctly

Setting up VPN on ubuntu 19.10 and getting DNS to work correctly

A bit late to post this? May be. But it is still relevant, so here goes. We shall see how to setup openvpn client on Ubuntu versions greater than 18.10 (or was it 18.04?) It certainly matters for 19.10 though!

A few things changed back then that caused issues in openvpn connection and DNS resolution. There was a fix found, and package released bundling the scripts so that normal users like us can install and enable those scripts. This solved the CLI problem. But I personally, do not like the idea of having to run a sudo command every time I need to use VPN and keep a terminal running. I like the flexibility Network Manager gives and also the fact that it nicely indicates with an icon if I am connected to VPN or not.

But to achieve this setup, a few steps are required:

  • Download your ovpn config file. This might require you to login to your OpenVpn server and download the ‘autologin’ config file.
  • Run this command: apt install openvpn-systemd-resolved. This will install the packages / scripts required to handle DNS resolution on VPN.
  • modify your ovpn file, add these lines before ca certs and after setenv:
    script-security 2
    up /etc/openvpn/update-systemd-resolved
    down /etc/openvpn/update-systemd-resolved
    down-pre
  • At the end of the file, after all certs and everything, add: dhcp-option DOMAIN-ROUTE .
    (note the “dot” in the command above.)
  • Connect to vpn using command: sudo openvpn --config <path to modified config file>

We have now achieved the basic setup, you can stop here. Just open terminal when you need to connect to VPN and run the above command; press Ctrl+C to disconnect from VPN. To integrate with Network Manager, follow through next steps:

  • We now need to import this file into Network Manager and use Network Manager UI to connect/disconnect from VPN.
  • Install sudo apt install network-manager-openvpn-gnome. Even if you are running KDE, the same command works.
  • Next, run this command to import the config file: sudo nmcli connection import type openvpn <modified config file>
  • This should bring a new network in your Network Manager Settings UI, under VPN header. The name of the connection will be same as the name of the file.
  • If this is a work VPN, which means you will need to use this VPN for connecting to work machines only, and rest of the traffic should go outside of VPN. To enable this, go to IPV4 settings, and select ‘Use this VPN for resources on this network only’. On most work VPNs, if you do not enable this, you will lose ability to use anything other than vpn servers, even google wont work.
  • Now the next, tricky part. This sets us up for most of the things, but in my experience DNS servers still do not resolve properly. To enable DNS resolution via Network Manager, in IPV4 settings of the VPN network add “~.” (without quotes) as search domain. In my experience, without the ~. as search domains, the DNS resolution did not work.

This is it. The benefit is a built in, native, visual representation of VPN connectivity right on your System Tray!

AWS Cloudwatch Log Scroller

AWS Cloudwatch Log Scroller

This is a quick tip about a quick solution to a regular small problem! AWS CloudWatch logs are great, but the search feature on those logs is not. The search only lists the lines that are exact match to your search term. Usually you would want to see a few lines above or below the match as well! Not all logs are single line, unless you spend efforts in ensuring that there are no newlines in the content being logged out. And so, every so often you have resort to ‘scrolling’ through the logs.

The logs load dynamically on scroll of the mouse wheel, and it is tedious (read ‘irritating’) to keep spinning the mouse wheel to scroll through those logs, especially the ECS container logs. So here is a little script which does that for you. Run this in your browser console and specify it the number of times it should run, and done. It does the scroll action, waits for the page to load (fixed) and scrolls again till it has scrolled for the times you specified.

You can also stop the scroll in between by calling clearTimeout on the timer.

Here it is:

Disclaimer: This is still not the best solution for long running tasks / huge log files, you are limited by the load times anyway. This only takes the need for manually scrolling through logs where you would have otherwise done so. For larger logs, it is probably best to export them.

Mute Mic With Keyboard Shortcut On Ubuntu Or Linux Mint

Mute Mic With Keyboard Shortcut On Ubuntu Or Linux Mint

Here is a quick tip for all the automation buffs like me. Turn your mic on and off with just a keyboard combo.

I do all my work remotely. Which is also to say I have a lot of conference calls. And like you, I hate it when people do not mute their phones / mic on laptops when not speaking! (cue in the obligatory meme about not putting your phone on mute during a call!)

I always wished for a hotkey of some sort to mute / un-mute myself during a call. So here is a way to do it.

  1. Use a Linux machine. (This in itself is a great tip! 😉 ) These steps in particular are for an Ubuntu / Linux Mint machine.
  2. Put the following snippet in a bash script file and add it to path. You can also define it as a bash alias and load it from your custom bash profile, but then assigning it a shortcut may not be that easy.
  3. Set a keyboard shortcut to trigger this script. I use Meta+M for this.

Here are the two variants of the script for that:

This script toggles mic state, shows a nice (transient) notification of the changed state, with an intuitive icon! It should also replace previous notification quickly, but somehow it does not seem to work yet.

(cue in the meme about speaking on mute! ;))

Update for fellow KDE users

KDE, the amazing DE that has some of the best customizations already have a configurable action to mute mic, it just does not have a default shortcut.

Just go to System Settings –> Shortcuts –> Global Shortcuts –> Audio Volume. Choose option “Mute Microphone” and set the “Global Alternate” to your shortcut of choice! Done! No script needed!