[lxc-users] Centos: how to specify static ip address to container

Mingjiang Shi mrjewes at gmail.com
Fri Feb 14 03:06:54 UTC 2014


Hi Michael,
Thanks for answering my question. There was no such
file /var/lib/libvirt/dnsmasq/default.conf, so I created one.  However, it
still doesn't work after killing the existing dnsmasq and restarted the
libvirtd.

================
[root at devmachine dnsmasq]# ls -l /var/lib/libvirt/dnsmasq/default.conf
-rw-r--r-- 1 root root 21245 Feb 14 10:33
/var/lib/libvirt/dnsmasq/default.conf

# added one line trying to assign 192.168.122.200 to container c1
[root at devmachine dnsmasq]# tail -1 /var/lib/libvirt/dnsmasq/default.conf
dhcp-host=c1,192.168.122.200

# kill existing dnsmasq
[root at devmachine dnsmasq]# ps -ef | grep dns
nobody   29325     1  0 10:37 ?        00:00:00 /usr/sbin/dnsmasq
--strict-order --local=// --domain-needed
--pid-file=/var/run/libvirt/network/default.pid --conf-file=
--except-interface lo --bind-interfaces --listen-address 192.168.122.1
--dhcp-range 192.168.122.2,192.168.122.254
--dhcp-leasefile=/var/lib/libvirt/dnsmasq/default.leases
--dhcp-lease-max=253 --dhcp-no-override
--dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
--addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts

[root at devmachine dnsmasq]# kill -9 29325
[root at devmachine dnsmasq]# !ps
ps -ef | grep dns
root     30695 34063  0 11:02 pts/3    00:00:00 grep dns

# restart libvirtd
[root at devmachine dnsmasq]# service libvirtd restart
Stopping libvirtd daemon:                                  [  OK  ]
Starting libvirtd daemon:                                  [  OK  ]

# still no conf-file is given to dnsmasq
[root at devmachine dnsmasq]# !ps
ps -ef | grep dns
nobody   30782     1  0 11:03 ?        00:00:00 /usr/sbin/dnsmasq
--strict-order --local=// --domain-needed
--pid-file=/var/run/libvirt/network/default.pid --conf-file=
--except-interface lo --bind-interfaces --listen-address 192.168.122.1
--dhcp-range 192.168.122.2,192.168.122.254
--dhcp-leasefile=/var/lib/libvirt/dnsmasq/default.leases
--dhcp-lease-max=253 --dhcp-no-override
--dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
--addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
root     30829 34063  0 11:03 pts/3    00:00:00 grep dns
================



On Fri, Feb 14, 2014 at 1:33 AM, Michael H. Warfield <mhw at wittsend.com>wrote:

> On Thu, 2014-02-13 at 16:23 +0800, Mingjiang Shi wrote:
> > Hello,
> > I run lxc container on centos and want to my container to start with a
> > static IP address.
> >
> >
> > After some investigation, I figured out that the dnsmasq is started by
> > libvirtd to provide DNS and DHCP service to the container. However, I
> > cannot figure out how to reserve ip address for a specific host in the
> > dnsmasq config file.
> >
> >
> > Meanwhile, in the ps out, it looks like no config file is given when
> > start the dnsmasq daemon, which doesn't sound right.
>
> No, that doesn't sound right.  Are you sure there isn't a dnsmasq config
> file in /var/lib/libvirt/dnsmasq/default.conf ?  I take it that it's
> ignoring the default config file /etc/dnsmasq.conf options.
>
> According to the doco, dnsmasq does support static address assignments,
> so it's just a matter of getting to the correct conf file.  That may be
> a libvirt configuation setting there.
> >
> > nobody   12531     1  0 Feb12 ?        00:00:01 /usr/sbin/dnsmasq
> > --strict-order --local=// --domain-needed
> > --pid-file=/var/run/libvirt/network/default.pid --conf-file=
> > --except-interface lo --bind-interfaces --listen-address 192.168.122.1
> > --dhcp-range 192.168.122.2,192.168.122.254
> > --dhcp-leasefile=/var/lib/libvirt/dnsmasq/default.leases
> > --dhcp-lease-max=253 --dhcp-no-override
> > --dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
> > --addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
> >
> >
> >
> > As a workaround, I configured a static ip address in the container
> > like how we configure an ip address to a standard Linux box. However,
> > I want to know how to config dnsmasq to give static ip address to a
> > specific container because I may run lots of containers. Appreciate
> > any response and idea. Thanks!
> >
> >
> > --
> > Thanks
> > -Mingjiang
> >
> > --
> > This message has been scanned for viruses and
> > dangerous content by MailScanner, and is
> > believed to be clean.
> > _______________________________________________
> > lxc-users mailing list
> > lxc-users at lists.linuxcontainers.org
> > http://lists.linuxcontainers.org/listinfo/lxc-users
>
> --
> Michael H. Warfield (AI4NB) | (770) 978-7061 |  mhw at WittsEnd.com
>    /\/\|=mhw=|\/\/          | (678) 463-0932 |
> http://www.wittsend.com/mhw/
>    NIC whois: MHW9          | An optimist believes we live in the best of
> all
>  PGP Key: 0x674627FF        | possible worlds.  A pessimist is sure of it!
>
>
> _______________________________________________
> lxc-users mailing list
> lxc-users at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-users
>



-- 
Thanks
-Mingjiang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20140214/a8ef1b21/attachment.html>


More information about the lxc-users mailing list