wiki.allensmith.net

Personal "Rough Notes & Useful Links

User Tools

Site Tools


kb:linux:lxcdnsinstall

14.04 LTS (desktop) Linux: Install Lxc with DNS

Please Note: This document uses both the Command Shell and the Root Command Shell. That is why when Terminal Commands are given below, the command prompt that is expected (ending either in $ or #) is at the beginning of each line − so do not copy & paste that 1st character.

This is what I use on a Mint 17 Xfce Web Development Workstation, that will use local DNS support for .lxc Container Names.

For Ubuntu 14.04 LTS based Linux, I use lts14 as the LVM Volume Group, with the following Volumes:
/dev/mapper/lts14-root … / ← the file system root directory
/dev/mapper/lts14-home … /home ← the user home directories
/dev/mapper/lts14-swap … swap area

Additional LVM Volume(s) created in this document assume lts14 has the necessary free or unused space to do that.

Optional Step: Create Separate LVM Volumes for Lxc

The default setup for Lxc (Linux Containers) will use one directory for the the Containers (each container in its own sub-directory), and a separate directory for the Container Snapshots. So I deliberately create a separate LVM volume for each (the containers & the snapshots), to make it easier to move and backup my Lxc systems.
First Time (only) … creation of Lxc volumes:
$ sudo lvcreate -L 100G -n lxc lts14
$ sudo lvcreate -L 100G -n lxcsnap lts14
$ sudo mkfs -t ext4 /dev/mapper/lts14-lxc
$ sudo mkfs -t ext4 /dev/mapper/lts14-lxcsnap
  • $ sudo mkdir /var/lib/lxc
    $ sudo mkdir /var/lib/lxcsnaps
    $ sudo nano /etc/fstab    # add the following lines to this file
    /dev/mapper/lts14-lxc         /var/lib/lxc   ext4   defaults   0       2
    /dev/mapper/lts14-lxcsnap     /var/lib/lxcsnaps     ext4    defaults   0       2

RESTART SYSTEM

Install Lxc & Create Ubuntu LTS Servers

Install Lxc Packages

  • install lxc and the supporting packages required to use this effectively
    $ sudo apt-get install lxc lxctl lxc-templates debootstrap yum cloud-utils qemu-user-static
  • debootstrap ← needed for templates that download .deb files to install – such as the ubuntu template
  • yum ← needed by .rpm base linux distributions – Oracle Linux is the example used below.
  • cloud-utils ← needed to install the ubuntu-cloud template
  • qemu-user-static ← to run containers of non-native architectures – eg. ARM (-a armhf)

Create some Ubuntu LTS Servers

Note: I try to pick a username that indicates what version of Linux the container is running. (In the below, lts14 for Ubuntu 14.04LTS, and lts12 for Ubuntu 12.04LTS.) Replace [password] in the below command lines with a password of your choice. (For the Ubuntu template, the default username & password is ubuntu & ubuntu.)
  • to create a starting Ubuntu 14.04.1 server, 12.04.5 server & Oracle Linux 6.5 server, run the follwing:
    $ sudo su
    # lxc-create -n ubuntu14lts -t ubuntu -- -a amd64 -r trusty --user lts14 --password [password]
    # lxc-create -n ubuntu12lts -t ubuntu -- -a amd64 -r precise --user lts12 --password [password]
    # lxc-create -n oracle -t oracle     # an RPM base Linux Distro/Container
    # exit
Once the server of each distribution and release is created and fully configured, that will then be cloned to create each of the Linux systems that will be used– to do development work, and to work out how to do things.

Install & Configure Local .lxc DNS Resolution

  • to use .lxc domain names for the contianers
    $ sudo apt-get install dnsmasq
Lxc creates an additional configuration file for dnsmasq … so it makes sense to add the configuration needed for (local) .lxc domains to the end of that file.
  • $ sudo nano /etc/dnsmasq.d-available/lxc     # add the following @ bottom of this file
    # Add the IP address for .lxc DNS resolution here.
    server=/lxc/10.0.3.1
  • $ sudo nano /etc/default/lxc-net

    … In this file, remove the leading # to UNCOMMENT the following line ⇒ LXC_DOMAIN=“lxc”

Ubuntu Documentation -- Dnsmasq
“Note that the package “dnsmasq” interferes with Network Manager which can use “dnsmasq-base” to provide DHCP services when sharing an internet connection.”

DNS in Ubuntu 12.04 → Using [dnsmasq-base] as local resolver by default on desktop installations
“The big advantage is that if you connect to a VPN, instead of having all your DNS traffic be routed through the VPN like in the past, you’ll instead only send DNS queries related to the subnet and domains announced by that VPN. This is especially interesting for high latency VPN links where everything would be slowed down in the past.”

The use of Network Manager & dnsmasq together is fine only when using a simple set-up. Therefore, if .lxc local DNS resolution is needed together with Internet Connection Sharing or VPN use, it could become necessary to uninstall Network Manager– then use dnsmasq, etc. to configure everything by hand.

Note: It is possible to use a Linux Container (e.g. vpn.lxc) to access a VPN network. (I'm still working through how to do that.)

Other References:

Can I install dnsmasq as well as (instead of?) dnsmasq-base?
“One thing that made things work better in this particular case was adding
clear-on-reload
to /etc/dnsmasq.d/clear-cache-on-network-switch (because the local DNS server at my office network resolved some fully-qualified hostnames to their internal IPs, and that would break connectivity to them when I moved outside of that LAN).”

Example of Using .lxc Container Names

  • $ sudo lxc-start -n ubuntu14lts -d     # start ubmutu14lts container in the background
    $ sudo lxc-info -n ubuntu14lts     # example output below:
    Name:           ubuntu14lts
    State:          RUNNING
    PID:            7463
    IP:             10.0.3.249
    CPU use:        2.31 seconds
    BlkIO use:      40.86 MiB
    Memory use:     27.78 MiB
    Link:           vethRFW7N4
     TX bytes:      2.15 KiB
     RX bytes:      6.29 KiB
     Total bytes:   8.44 KiB
  • $ ping ubuntu14lts.lxc     # example output below:
    PING ubuntu14lts.lxc (10.0.3.249) 56(84) bytes of data.
    64 bytes from 10.0.3.249: icmp_seq=1 ttl=64 time=0.052 ms
    64 bytes from 10.0.3.249: icmp_seq=2 ttl=64 time=0.069 ms
    64 bytes from 10.0.3.249: icmp_seq=3 ttl=64 time=0.065 ms
    64 bytes from 10.0.3.249: icmp_seq=4 ttl=64 time=0.065 ms
    64 bytes from 10.0.3.249: icmp_seq=5 ttl=64 time=0.067 ms
    64 bytes from 10.0.3.249: icmp_seq=6 ttl=64 time=0.069 ms
    64 bytes from 10.0.3.249: icmp_seq=7 ttl=64 time=0.070 ms
    64 bytes from 10.0.3.249: icmp_seq=8 ttl=64 time=0.068 ms
    64 bytes from 10.0.3.249: icmp_seq=9 ttl=64 time=0.066 ms
    ^C
    --- ubuntu14lts.lxc ping statistics ---
    9 packets transmitted, 9 received, 0% packet loss, time 7999ms
    rtt min/avg/max/mdev = 0.052/0.065/0.070/0.010 ms
  • $ sudo lxc-stop -n ubuntu14lts     # shutdown ubuntu14lts container
kb/linux/lxcdnsinstall.txt · Last modified: 2016/01/13 20:35 (external edit)