Different DNS servers between Internal and External network

I need to change my external access DNS server and keep the default gateway on my internal access I can´t access local devices using hostname but I can using local IP

here is my /etc/systemd/resolved.conf:

[Resolve]
DNS= 208.67.222.222
FallbackDNS= 208.67.222.220

You need a DNS server, or you can just edit /etc/hosts and include your hostname/IPs pairs there.

Can you be more clear with what you are trying to do? I don’t understand the problem you are trying to solve.

I have some smb shares and computers with dynamic IPs so I normally use hostnames for access and itś not practical to use the /etc/hosts

when ever I use different DNS from the automatically attributed I can´t access devices by their hostnames but I can by their IPs and smb does not work at all

Here, I’m using DHCP registration directly into the DNS…
https://wiki.samba.org/index.php/Configure_DHCP_to_update_DNS_records

It creates an A entry and also a PTR as soon as the dhcp client gets an IP…

DHCP logs
Apr 27 16:13:01 rpi3 dhcpd[631]: DHCPREQUEST for 192.168.255.254 (192.168.255.250) from f0:2f:74:d0:24:94 via eth0
Apr 27 16:13:01 rpi3 dhcpd[631]: DHCPACK on 192.168.255.254 to f0:2f:74:d0:24:94 via eth0
Apr 27 16:13:01 rpi3 dhcpd[631]: Commit: IP: 192.168.255.254 DHCID: f0:2f:74:d0:24:94 Name: eos
Apr 27 16:13:01 rpi3 dhcpd[631]: execute_statement argv[0] = /usr/local/bin/dhcp-dyndns.sh
Apr 27 16:13:01 rpi3 dhcpd[631]: execute_statement argv[1] = add
Apr 27 16:13:01 rpi3 dhcpd[631]: execute_statement argv[2] = 192.168.255.254
Apr 27 16:13:01 rpi3 dhcpd[631]: execute_statement argv[3] = f0:2f:74:d0:24:94
Apr 27 16:13:01 rpi3 dhcpd[631]: execute_statement argv[4] = eos
Apr 27 16:13:02 rpi3 root: Correct 'A' record exists, not updating.
Apr 27 16:13:03 rpi3 root: Correct 'PTR' record exists, not updating.
Apr 27 16:13:03 rpi3 dhcpd[631]: DHCPREQUEST for 192.168.255.254 (192.168.255.250) from f0:2f:74:d0:24:94 via 192.168.255.249
Apr 27 16:13:03 rpi3 dhcpd[631]: DHCPACK on 192.168.255.254 to f0:2f:74:d0:24:94 via 192.168.255.249
Apr 27 16:13:03 rpi3 dhcpd[631]: Commit: IP: 192.168.255.254 DHCID: f0:2f:74:d0:24:94 Name: eos
Apr 27 16:13:03 rpi3 dhcpd[631]: execute_statement argv[0] = /usr/local/bin/dhcp-dyndns.sh
Apr 27 16:13:03 rpi3 dhcpd[631]: execute_statement argv[1] = add
Apr 27 16:13:03 rpi3 dhcpd[631]: execute_statement argv[2] = 192.168.255.254
Apr 27 16:13:03 rpi3 dhcpd[631]: execute_statement argv[3] = f0:2f:74:d0:24:94
Apr 27 16:13:03 rpi3 dhcpd[631]: execute_statement argv[4] = eos
Apr 27 16:13:05 rpi3 root: Correct 'A' record exists, not updating.
Apr 27 16:13:06 rpi3 root: Correct 'PTR' record exists, not updating.
Apr 27 16:13:06 rpi3 dhcpd[631]: DHCPREQUEST for 192.168.255.254 (192.168.255.250) from f0:2f:74:d0:24:94 via eth0
Apr 27 16:13:06 rpi3 dhcpd[631]: DHCPACK on 192.168.255.254 to f0:2f:74:d0:24:94 via eth0
Apr 27 16:13:06 rpi3 dhcpd[631]: Commit: IP: 192.168.255.254 DHCID: f0:2f:74:d0:24:94 Name: eos
Apr 27 16:13:06 rpi3 dhcpd[631]: execute_statement argv[0] = /usr/local/bin/dhcp-dyndns.sh
Apr 27 16:13:06 rpi3 dhcpd[631]: execute_statement argv[1] = add
Apr 27 16:13:06 rpi3 dhcpd[631]: execute_statement argv[2] = 192.168.255.254
Apr 27 16:13:06 rpi3 dhcpd[631]: execute_statement argv[3] = f0:2f:74:d0:24:94
Apr 27 16:13:06 rpi3 dhcpd[631]: execute_statement argv[4] = eos
Apr 27 16:13:07 rpi3 root: Correct 'A' record exists, not updating.
Apr 27 16:13:09 rpi3 root: Correct 'PTR' record exists, not updating.
Apr 27 16:13:09 rpi3 dhcpd[631]: DHCPREQUEST for 192.168.255.254 (192.168.255.250) from f0:2f:74:d0:24:94 via 192.168.255.249
Apr 27 16:13:09 rpi3 dhcpd[631]: DHCPACK on 192.168.255.254 to f0:2f:74:d0:24:94 via 192.168.255.249

It wouldn’t be easier to just add a static IP address for the server?

That’s the problem the server was configured with a static IP, but the router provided by the ISP is not reliable so the server uses dhcp as a fallback and frequently

Besides after DNS swapping I can´t use either hostname or IP on smb Thunar simply asks for a login and after that it fails to connect

1 Like

So, if the static IP is not an option, I can’t see other option other than the one mentioned above.

However, to run the ISC DHCP server with the option mentioned there are a few requirements.

The computer has been provisioned as an AD DC and the samba, smbd and winbindd daemons are running.
Also, if you have multiple VLANs, you would need to set a DHCP relay for each VLAN pointing to the ISC DHCP server.

Edit: dhcp-dyndns.sh is hooked to my DHCP server.

Edit2: You can remove some IPs from the DHCP pool, and set a static IP directly in the NIC of the server…
This would be the easier approach.

In summary:

  • using auto DNS:

    • access external network
    • access local machines by hostname
    • access local machines by IP
    • access local SMB shares by hostname or IP
  • using custom DNS:

    • access external network
    • can´t access local machines by hostname
    • access local machines by IP
    • can´t access local SMB shares by hostname or IP

This makes sense since you are connecting directly to an external DNS server.

I am not sure why you can’t connect to smb shares by IP. That shouldn’t require DNS. Have you tried connecting via a cli tool so you can get some kind of meaningful error? Alternatively, have you looked at the logs on the server side?

I tried doing a hostname mount and got this:

$ sudo smbclient //{server}/{share} -U {user} 
Can't load /etc/samba/smb.conf - run testparm to debug it
Password for [WORKGROUP\{user}]:
do_connect: Connection to {server} failed (Error NT_STATUS_NOT_FOUND)

the IP mount worked

1 Like

But is there a way to do it

Yes there is. I run such setup - best result is to use a subdomain of a real internet facing domain name.

As far as I understand your problem you have two options:

Option 1:
You tell your dhcp server to give always the same ip addresses to your local servers. Most dhcp server have the option to do this by MAC address. With this you can manage to do name resolution with an /etc/hosts file.

Option 2:
This is how I do it. I use a tool called dnsmasq. https://wiki.archlinux.org/title/Dnsmasq

This is a dns forwarder which can forward dns requests to external and local dns servers. In my case for example, I use my Fritzbox to resolve local hostnames and the dns servers from my ISP for everything else. The local name resolution is accomplished by these 3 options in /etc/dnsmasq.conf:

domain=fritz.box
domain-needed
server=/fritz.box/192.168.1.1

Where 192.168.1.1 is the ip adress of my local dns server = fritzbox

But my primary use case for dnsmasq is performance. Because it caches dns requests it is really fast if a dns request is send multiple times.

EDIT:
my second use case for dnsmasq is dns blocking, similar to what pihole is doing.
I use the non-tracking dns filter list from here

https://raw.githubusercontent.com/notracking/hosts-blocklists/master/dnsmasq/dnsmasq.blacklist.txt

On top of that I block all facebook.com and facebook.de

1 Like