Skip to Content
  • +31 653-919-302
Cafayate.Net
  • 0
  • 0
  • Sign in
  • Nederlands English (US) Español (AR)
  • Contact Us
  • Home
  • Blog
  • Jobs
  • Contact us
Cafayate.Net
  • 0
  • 0
    • Home
    • Blog
    • Jobs
    • Contact us
  • +31 653-919-302
  • Nederlands English (US) Español (AR)
  • Sign in
  • Contact Us

DNS resolution for LXC in Ubuntu 14.04

  • All Blogs
  • Tech Blog
  • DNS resolution for LXC in Ubuntu 14.04
  • March 5, 2021 by
    Administrator

    Working with LXC (Linux containers) in Ubuntu is very easy but by default you need to know the IP address of new containers to connect to services (ssh, database, webserver, etc.) running on them.

    With some minor configuration you can connect to your containers using a domain name like that

    $ sudo lxc-create --name container1
    $ sudo lxc-start --name container1 --daemon
    $ ssh ubuntu@container1.lxc

    In Ubuntu 14.04 Trusty Tahr, lxc-create use by default the Ubuntu template and it will create a user called ubuntu, to change it take a look at the template options with lxc-create -t ubuntu -h.

    To set up the internal DNS resolution on your machine, you must edit /etc/default/lxc-net and uncomment the line

    LXC_DOMAIN="lxc"

    Also you need to create the file /etc/NetworkManager/dnsmasq.d/lxc.conf with the following content

    server=/lxc/10.0.3.1

    This will redirect DNS queries for *.lxc hosts to the dnsmasq instance running on 10.0.3.1 that manage DHCP and DNS for containers.

    After that restart networking related services

    $ sudo service lxc-net stop
    $ sudo service lxc-net start
    $ sudo service network-manager restart

    For the lxc-net service you can’t use the restart command, you must use the stop/startcommands to reload the configuration.

    If you had some containers running, do not forget to restart them

    $ sudo lxc-stop --name container1
    $ sudo lxc-start --name container1 --daemon

    Finally to check that everything works you can use, for example, the ping command and you must see something like this

    $ ping -c 3 container1.lxc
    PING container1.lxc (10.0.3.8) 56(84) bytes of data.
    64 bytes from 10.0.3.8: icmp_seq=1 ttl=64 time=0.072 ms
    64 bytes from 10.0.3.8: icmp_seq=2 ttl=64 time=0.125 ms
    64 bytes from 10.0.3.8: icmp_seq=3 ttl=64 time=0.113 ms
    
    --- psql.lxc ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 2000ms
    rtt min/avg/max/mdev = 0.072/0.103/0.125/0.024 ms
    
    in Tech Blog
    Linux: Turn On TCP SYN Cookie Protection

    Designed for companies

    We are a team of passionate people whose goal is to improve everyone's life through disruptive products. We build great products to solve your business problems. Our products are designed for small to medium size companies willing to optimize their performance.

    Get in touch

    Plantexel
    Pedernera
    Salta Capital 
    Argenina

    • +31 653-919-302
    • [email protected]
    Follow us
    Copyright © Plantexel
    Nederlands | English (US) | Español (AR)