ubuntu

I have configured a few VPNs on my Ubuntu notebook. Some of them are OpenVPN, and in fact they are fairly easy to configure.
However, sometimes I receive this error:

I wasn’t able to exactly identify the situation when this happens – it seems to be related to networking, and it happens more often when I log into my desktop with WI-FI connection, OpenVPN daemon starts, then I plug an ethernet cable.

SHORT ANSWER

A quick solution is simply to log out and log in again. It is simple but I don’t like it very much.

Other than that everything regarding VPNs on Ubuntu Desktop seems to be a bit of a mess. In the long answer you can find some more details regarding OpenVPN.

LONG ANSWER

In Internet you can find a lot of guides on how to set up an OpenVPN on Ubuntu Desktop. One simple and effective is Ubuntu’s Official: Help Ubuntu – OpenVPN. Anyway, most of the times everything is reduced to

to install a service, or

to install an extension to the Network Manager GUI.

However, the GUI option has some limitation – for example, you can only connect to one VPN at the time. If you have more than one VPN (and you can handle all routing problems with overlapping networks that can occur), you have to go with the service. To go with the service, you have to put all your OpenVPN configuration files, with extension .conf, in folder /etc/openvpn . Then (if your configuration files are correct, if your connection is ok, and a billion other ifs) if you restart openvpn service, you should see something like this:

That means that your VPNs are up and running.

However, if you have password authentication, for some reason, even if you have your credentials in a file connected to the configuration file, sometimes the service will hang, simply because the VPN restarts and it is waiting in background for a password. So, you have to restart the service.

But the agent of the first error it’s not this service. They are two completely different things. I think that this agent is something GUI related, for I meet this error only on the network manager GUI, and not with the service – which keeps running. However, it could just be that the service it’s still using WI-FI connection.

Unfortunately I have no real explanation for this and no real solution; just a quick workaround. It is a fairly complicated matter, which would require a lot of debug for a very simple task, and I don’t think it is worth the time.

Sed Tips And Tricks

by Michele Brusoni on

This post is just a “Long Answer”. It’s the sequel of this simpler post on a sed problem I had: BigBrus’ Corner – Sed Disable Regex . Here are some tips and curiosity I found.

sed -i ‘s/http://127.0.0.1:8080/webinterface/http://192.168.50.13:9091/my/web/interface/g’ /home/bigbrus_corner/test_sed


Let me explain field per field the above sed command:

  • sed : – well, obviously it’s sed
  •  -i   : means “in-place”, which means “replace in the source file”. Default sed behaviour is to output on stdout – which will probably be on the screen – leaving the file unchanged.
  • the next part is between two single quotes ( ‘  ‘ ) . sed does not need them to run, but it’s a good habit to use, for single quotes tells bash not to interpret what’s between them. In this way you will only have to handle sed syntax and special characters. If you want bash to use substitution, you should probably use double quotes ( ” ” ).
  • s : means substitution; it’s the function you want to execute and it’s absolutely the most common. For more functions, read this: Sed Manual – Other commands .
  • / : just after s there’s the delimiter character. By convention it’s / , for there are many other tools that use the same concept and the same character. sed anyway uses the first character after s as delimiter, so you can really use any character.
  • http://127.0.0.1:8080/webinterface : the text you want to be replaced. It needs to be properly escaped
  • / : another delimiter
  • http://192.168.50.13:9091/my/web/interface : the text to put in place. It needs to be properly escaped
  • / : another delimiter
  • g : it means global. sed will replace all occurrence in the text, not just the first. For more options of the function s, read this: Sed Manual – The “s” Command
  • /home/bigbrus_corner/test_sed : the file you want to edit.

Some other specifications on sed:

  • If you’d like to know, sed uses basic regular expression by default – sed Manual – Reporting Bugs – Regex syntax clashes (the first sentence of this paragraph is quite neat). Regarding which characters you should escape within a text to replace, you should know that it’s a POSIX standard and you can find them, for example, here: Wikipedia – Regular Expression basic
  • Well, I have to admit that I lied to you in the examples. It was to make more evident the difference of choosing the right separator. The fact is, “.” is a special character in POSIX regex. So, I should have escaped it. But, “.” in regex sintax means “match any single character”; incidentally, any dot in IP addresses IS “any single character”, so the string matches correctly anyway. But remember, you won’t be so lucky again! 😉
  • If you would like to use extended regular expression instead of basic ones, you must use -r | –regexp-extended flag.
  • sed with s and without options is “line-oriented”. This means that it will replace only the first occurrence per line
  • What amazed me the most, you can use sed as an interpreter to create scripts. It’s rather complicated, but just the fact you can use it it’s awesome. More informations here: Sed Manual – Example Scripts . If you want to know more on how to use interpreters in scripts, you can read this post of mine: BigBrus’ Corner – SHEBANG! (or #! )
USEFUL LINKS

Sed Disable Regex

by Michele Brusoni on

This started like a “small” post on this matter, but eventually it became a very long one, and finally decided to split the argument in two. This is about the problem I had regarding regex. You can find a “more in depth” post here:  BigBrus’ Corner – Sed Tips and Tricks . sed is a command line tool. Of course, I’m no expert of sed, I use it mostly to replace parts of configuration files in my installation scripts. It’s very useful for its ability to use regex and to replace in the same file part of lines, but in fact it is almost a programming language, with so many options to manipulate strings you won’t believe.

Anyway, the ability to use regex can become a problem when you have strings with lots of special characters. Like, for example, a password or a web address.
SIMPLE ANSWER
Well, the really simple answer is: sed cannot run without regex. There’s no parameter, no switch, nothing that can turn off regular expression matching. There may be other tools (I found something with perl, something with pure bash, a partial solution with grep and a “replace” tool, which should come installed with MySQL or something similar…), but not sed.LONG ANSWER

Anyway, most of the times, the problem isn’t with regular expression but with bash escape character – which is . Incidentally, it’s also the most used delimiter of sed (delimiter = a character chosen to separate the different fields of sed).
For example, if you have to correctly replace “http://127.0.0.1:8080/webinterface” with “http://192.168.50.13:9091/my/web/interface”, your sed command will be something like
sed -i ‘s/http://127.0.0.1:8080/webinterface/http://192.168.50.13:9091/my/web/interface/g’ /home/bigbrus_corner/test_sed
which may be fascinating to someone but in my opinion is madness in a string. By the way, this pattern is called ‘Picket Fence’.
The most beautiful option of sed is that you can set its separator to almost any character. And in the most simple way: using it. sed will simply understand.
So, the command above can become
sed -i ‘s|http://127.0.0.1:9091/webinterface|http://192.168.50.13:9091/my/web/interface|g’ /home/bigbrus_corner/test_sed
or even
sed -i ‘s#http://127.0.0.1:9091/webinterface#http://192.168.50.13:9091/my/web/interface#g’ /home/bigbrus_corner/test_sedor even

sed -i ‘sshttp://127.0.0.1:8080/webinterfaceshttp://192.168.50.13:9091/my/web/interfacesg’ /home/bigbrus_corner/test_sed
(it DOES work this last one! I couldn’t believe!! you can use s as a separator)

You can use really ANY character! You only have to put it in the right place and eventually escape any matching character in the string. This example, using i as separator, could make it clearer:sed -i ‘sihttp://127.0.0.1:8080/webinterfaceihttp://192.168.50.13:9091/my/web/interfaceig’ /home/bigbrus_corner/test_sed

Note that, having used i as a separator, I had to escape every other i in the text to have it work. Anyway, that’s the reason you usually use “strange” characters like @#!/: or similar…

So, as you can see, probably most of the times (with small portions of not too complicated text) you actually don’t need to turn off regex.
USEFUL LINKS

(I love CamelCase for titles 😉 )


In this post I’m going to explain what I mean with “Clean Installation of Ubuntu Server“, which I use as a base for testing tools and commands for this blog… and to complain aftewards! XD But this first part could also be used as a basic explanation on how to create a basic virtual machine.

So, to begin, I obviously use a virtualization tool. The one I like most, at the moment, is VMWare, for I can actually install the OS – something I really like to do for no other reason than doing it 😉 . To develop, instead, I use Vagrant, for it’s really really easy to build a development environment – and destroy it when you need to start again in a cleaner environment. Maybe I’ll write about this another time.

SHORT ANSWER
Well, maybe this is not gonna be so short, but I hope it’s gonna be mainly images. 😉
Anyway, you should download and install the latest VMWare Player (VMWare Player Download). This, the install phase, really depends on the operating system you’re on, so I’m not telling you how to do it.

Then you should download the Ubuntu ISO. I like to test for something that could be a production environment, so I stick with LTS – which are much more stable and supported – that is 12.04 or 14.04 at the moment of this writing. I strongly suggest to download the “PC (Intel x86) server install CD“; I’ll give you more informations about this in the “Long Answer” section.

These are the ISO links:
– Ubuntu 12.04 – Precise Pagnoline
– Ubuntu 14.04 – Trusty Tahr

Remember, for this kind of testing you need to download those softwares just once. Then, for a couple of years or maybe more, you’re done.

Now, let’s create the VM. Start VMWare Player (mine is version 7), then click on “Create New Virtual Machine“:

Create New Virtual Machine – Easy so far, right?

Select “I will Install the OS Later“, then click Next. That’s because otherwise VMWare player will wtry to make a default configuration without asking anything during the insal phase. But we want to have a precise configuration, so this option in our case isn’t useful.

I will install the operating system later – We don’t like default options, right?

Select “Linux“, version “Ubuntu“; then click “Next

Anyway, we know we’re installing a Ubuntu Server.

Pick a name for your VM; I like to use useful and not too long names, with a clear meaning even to people who see them for the first time, so I choose “TemplateUbuntuServer1204”. No spaces in filename – in linux it is known they may cause problems, so let’s try to avoid at least these one.

Template, something we will reuse; Ubuntu, the OS; Server, the kind of operating system; 12.04, the version. No dots, even if it shouldn’t give problems (at least in linux).

Select “Split virtual disk in multiple files” – in my case it was the default selection. Leave 20 GB as “Maximum disk size” – it should be more than enough in most cases.

This will be useful later.

Click on “Customize hardware“:

Customize hardware, we have to do something in there.

Leave Memory and CPU as they are by default (in my case 1GB and 1 Core).
Select section “New CD/DVD (SATA)“, select “Connect at power on“, click on “Use ISO image“, then “Browse“, navigate to the directory where you downloaded the Ubuntu ISO, select it and press “Open“.

Now select the right ISO.

Select section “Network Adapter“, select “Connect at power on“, then select “Bridged: Connected directly to the physical network” and enable “Replicate physical network connection state“. If I understand this correctly, this last field means that if your PC is connected or disconnected, the same will be the virtual network adapter in the virtual machine.

Bridged – we need the virtual machine to access directly to internet.

Remove “Sound Card” and “Printer” by selecting those sections and clicking on “Remove“.

The basic final configuration should look like this:

They are simply useless on most standard servers.

Click “Close“, “Finish“, and “Close” again. You should be on the basic VMWare Player interface.

Click on “Play virtual machine

PLAY!!! Finally!!!

There could be an “Hint” on the new black window, you can click on “OK” or click “Never show this hint again” and then ok if you prefer.

That’s it for this first part! I chose to divide the installation process in two parts to avoid a post too long. In the next few days I will publish the second part, that is the actual installation of Ubuntu Server 12.04 Precise Pagnoline

LONG ANSWER
This time maybe I should write something like “More in depth” instead of “Long Answer”, for this section will never be longer than the above 😉

The idea behind this test virtual machine is to have a really clean and default environment to test software installations and behaviours. It’s not fault-proof, but gives me a really solid way to reproduce and/or isolate any bug or problem I find, and if it’s related to something else I installed/did or it’s the procedure itself that returns an error.

The other idea is to have an environment as clean as possible, starting from the hardware: no sound card and printer, for these could imply drivers and software not really needed.

I chose to use a bridged network interface for NATted network card can sometimes give some problem to reach internet (needed do download software and updates), and the process to debug may invalidate the goal of a clean installation. With bridged network interfaces, instead, I never met any problem (for the moment!!!).

The choice to suggest a 32 bit Ubuntu has two main reasons. First: 64 bit softwares often are porting of their 32 bit versions, even in 2015; or may depend on something not available as 64 bit. In general I find that 64 bit programs are still less stable than 32 bit, even if I don’t know the exact reason. This means that you may incur in more compatibility problems due to system architecture and not to other things.
The second reason is that VMWare Player does not support every 64-bit CPU to virtualize 64-bit OSs (for more informations on this topic, VMWare KB1003945 – Hardware and firmware requirements for 64-bit guest operating systems). For example, my I7 is not supported, and it isn’t a special or particular CPU. As always, standards and simplifications simply doesn’t exists, there are tons of compatibility problems and exceptions even in the most used and developed software. Anyway, for the sake of portability (at least on desktop environments), I chose to use 32 bit Ubuntu. I will have enough problems just concentrating on the software I’m testing, without having to deal with compatibility or architecture problems.