LXC containers in ubuntu 12.04 works great, but have serious problem: static ip address, set by lxc config file, and resolvable domain name accross private network does not automatically work together. Editing /etc/hosts on host machine does not make any effect.
Of course we can set up additional dns server or use existing one in our real network, but it can be inapplicable or overkill for small network or developer machine.
This problem can be solved by editing startup script /etc/init/lxc-net.conf. Here are the steps, that allow you to easily setup dns resolving:
Of course we can set up additional dns server or use existing one in our real network, but it can be inapplicable or overkill for small network or developer machine.
This problem can be solved by editing startup script /etc/init/lxc-net.conf. Here are the steps, that allow you to easily setup dns resolving:
- Create somewhere in the system file similiar to /etc/hosts and fill it with ip addresses and dns names for your containers. /var/lib/lxc/hosts should be a good a place, and I suppose you select it in further steps
- As root, open file /etc/init/lxc-net.conf with your favorite text editor and find line where dnsmasq is started. It is look like this:
dnsmasq -u lxc-dnsmasq --strict-order... - In the end of this line right before || cleanup add --addn-hosts=/var/lib/lxc/hosts.
- As a result all line would look like:
dnsmasq -u lxc-dnsmasq --strict-order --bind-interfaces --pid-file=${varrun}/dnsmasq.pid --conf-file= --listen-address ${LXC_ADDR} --dhcp-range ${LXC_DHCP_RANGE} --dhcp-lease-max=${LXC_DHCP_MAX} --dhcp-no-override --except-interface=lo --interface=${LXC_BRIDGE} --dhcp-option=119,${LXC_DOMAIN_SEARCH} --dhcp-option=6,${LXC_DNS_SERVER} --addn-hosts=/var/lib/lxc/hosts || cleanup - Start and stop service lxc-net
- sudo service lxc-net stop; sudo service lxc-net start
If some of your containers get ip address via dhcp and you want them to resolve your static containers too, ensure that your LXC_DNS_SERVER variable point to your machine with lxc, but not to your real network dns server. You can also edit it in /etc/init/lxc-net, but you should better set it in /etc/default/lxc
This solution has one lack: we editing a system file that can be potentially updated during lxc package update, and you'll have to merge your modification with package changes.
This solution has one lack: we editing a system file that can be potentially updated during lxc package update, and you'll have to merge your modification with package changes.
Перевод бы...
ОтветитьУдалитьСделано
Удалитьhttp://blog.dnpavlov.com/2014/02/dns-lxc.html