5

Is there something like /etc/hosts file for SRV records? I would like my Alpine Linux server to find the value of _xmpp-server._tcp SRV record locally.

Saxtheowl
  • 1,112
  • 5
  • 8
Navid777
  • 153
  • 4

1 Answers1

3

Linux does not have a built in method for that, you should look into dnsmasq and setup a lightweight DNS resolver, first install it

apk add dnsmasq

then we create a configuration file for example here /etc/dnsmasq.conf

put this inside

# Use the following DNS servers as the upstream servers
server=8.8.8.8
server=8.8.4.4

# Define your local SRV record
srv-host=_xmpp-server._tcp.example.com,server.example.com,5269,0,5

# Replace "example.com" with your domain and "server.example.com" with your server's hostname

then we start it

rc-service dnsmasq start
rc-update add dnsmasq

and now you can configure your server to use our DNS resolver, add this at the top of /etc/resolv.conf

nameserver 127.0.0.1
Saxtheowl
  • 1,112
  • 5
  • 8
  • Note that on modern distros, `/etc/resolv.conf` is often managed by NetworkManager or systemd which means changes will be overwritten on the next reboot/network change. – Ginnungagap Apr 09 '23 at 16:14
  • @Ginnungagap Though you can generally override that in turn (or just make your changes and mark the file immutable, though things may complain vociferously about this in your log files). – Austin Hemmelgarn Apr 09 '23 at 22:15
  • @Ginnungagap: You could...configure the NetworkManager or systemd-networkd connection profiles to use 127.0.0.1 as the DNS server? – user1686 Apr 10 '23 at 06:00
  • Yes I was just warning against editing `/etc/resolv.conf` directly. I'm not saying it's unfeasible, just that the current will likely work temporarily only. – Ginnungagap Apr 10 '23 at 08:18