0

I have been able to configure static ip for specific client in /etc/dnsmasq.conf by using "dhcp-host":

http://manpages.ubuntu.com/manpages/cosmic/en/man8/dnsmasq.8.html

I would like to use /etc/hosts instead, so I have only one place to maintain for both the DNS and the DHCP.

Thanks

2 Answers 2

2

Your "one place" is the dnsmasq.conf file.

# sticky IP address
dhcp-host=11:22:33:44,192.168.1.1,stickybox

# A record (like /etc/hosts)
host-record=namedbox,192.168.1.2
1
  • It is still useful to have same names in /etc/hosts, so that resolving will work even if dnsmasq is down.
    – sena
    Commented Oct 18, 2021 at 0:55
1

According to the manpage, dnsmasq actually reads /etc/hosts for exactly that purpose. Just remove that dhcp-host line, and add a

192.168.1.1 stickybox

line to /etc/hosts. If you want to add the MAC address as well, add

11:22:33:44:55 192.168.1.1

to /etc/ethers and enable read-ethers in dnsmasq.conf.

See http://www.thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html

2
  • 1
    It's worth nothing that this still requires a dhcp-host entry for the hostname, however it can simply be dhcp-host=stickybox, which will cause DNSMASQ to resort to /etc/hosts for the IP. See the dhcp-host section of the manpage for more information. Commented May 20, 2019 at 23:52
  • dhcp-host is not required with read-ethers, given that entries are equivalent to using dhcp-host according to the man page entry for read-ethers. This works in my experience. Adding expand-hosts to add the local domain to entries from /etc/hosts can be useful, though. Commented Nov 20, 2023 at 1:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .