Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Solved] Can't start dnsmasq when libvirt is running
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
solamour
l33t
l33t


Joined: 21 Dec 2004
Posts: 726
Location: San Diego, CA

PostPosted: Tue Sep 24, 2024 4:26 am    Post subject: [Solved] Can't start dnsmasq when libvirt is running Reply with quote

My system has 2 network interfaces; enp1s0 is for connecting to the outside world and enp2s0 (whose IP is 192.168.1.254/24) is for the local network. I use dnsmasq to give dynamic IPs (192.168.1.100 ~ 192.168.1.200) to the local network machines. I also set up iptables with NAT, so that the local network machines can access the outside world.

Code:
                       +----------+             +----- machine1
Internet        enp1s0 |          | enp2s0      |
-----------------------+  gentoo  +-------------+----- machine2
                       |          |             |
                       +----------+             +----- machine3


When I run libvirt for QEMU/KVM, dnsmasq gives me the following error message.
Code:
# rc-service dnsmasq start
 * Starting dnsmasq ...

dnsmasq: failed to bind DHCP server socket: Address already in use
 * start-stop-daemon: failed to start `/usr/sbin/dnsmasq'
 * Failed to start dnsmasq                                                [ !! ]
 * ERROR: dnsmasq failed to start


I see "6382/dnsmasq" is already listening to port 53 (possibly by libvirt).

Code:
# netstat -plnt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN      4041/Xvnc
tcp        0      0 192.168.100.254:53      0.0.0.0:*               LISTEN      6382/dnsmasq   <--
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2284/sshd: /usr/sbi
tcp6       0      0 :::5901                 :::*                    LISTEN      4041/Xvnc
tcp6       0      0 :::22                   :::*                    LISTEN      2284/sshd: /usr/sbi

# ps aux | grep [d]nsmasq
nobody    6382  0.0  0.0   2816  1536 ?        S    16:36   0:00 /bin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/network.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root      6383  0.0  0.0   2816  1280 ?        S    16:36   0:00 /bin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/network.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper


Is there a way to let libvirt hand out the IPs (192.168.100.100 ~ 192.168.100.200) to the virtual machines only, and I still get to manage the local network machines with dnsmasq?
__
sol


Last edited by solamour on Wed Sep 25, 2024 6:17 pm; edited 1 time in total
Back to top
View user's profile Send private message
solamour
l33t
l33t


Joined: 21 Dec 2004
Posts: 726
Location: San Diego, CA

PostPosted: Wed Sep 25, 2024 6:16 pm    Post subject: Reply with quote

I couldn't figure out a way to run both libvirt's dnsmasq and my own dnsmasq at the same time, because libvirt always starts dnsmasq whenever it starts a virtual network, regardless of the type of the virtual network (i.e. NAT, Routed, Open, Isolated, etc.).

What did work was to just not add any libvirt virtual network; instead, create a network bridge of the host's local network interface and let all virtual machines connect to the network bridge.

Code:
[/etc/conf.d/net]

config_enp2s0="null"
bridge_br0="enp2s0"
config_br0="192.168.1.254 netmask 255.255.255.0 brd 192.168.1.255"
bridge_forward_delay_br0=0
bridge_hello_time_br0=1000


Code:
[/etc/dnsmasq.conf]

interface=br0
dhcp-range=br0,192.168.1.100,192.168.1.200,1h


All virtual machines AND the local network machines get their IPs from the same pool (192.168.1.100 ~ 192.168.1.200), which is OK with me. Thanks everyone for sharing suggestions.
__
sol
Back to top
View user's profile Send private message
solamour
l33t
l33t


Joined: 21 Dec 2004
Posts: 726
Location: San Diego, CA

PostPosted: Sat Sep 28, 2024 7:21 pm    Post subject: Reply with quote

I found a way to run libvirt's virtual network and the host's dnsmasq at the same time.
Code:
[/etc/dnsmasq.conf]
bind-interfaces
...


In short, the host's dnsmasq will bind only to the interface that are specified in "/etc/dnsmasq.conf", excluding libvirt's virtual network.

I ended up just letting the virtual machines use the host's network bridge, but perhaps there might be others who might find the virtual network meets their needs better.
__
sol
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum