# \[SOLVED\] OpenVPN Static Host resolve issue

**URL:** <https://forum.openwrt.org/t/solved-openvpn-static-host-resolve-issue/60609>\
**Category:** Network and Wireless Configuration\
**Created:** [April 14, 2020, 6:18pm UTC](https://forum.openwrt.org/t/solved-openvpn-static-host-resolve-issue/60609 "2020-04-14T18:18:07Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![sklerotraficon](https://forum.openwrt.org/user_avatar/forum.openwrt.org/sklerotraficon/32/3007_2.png) [@sklerotraficon](https://forum.openwrt.org/u/sklerotraficon)\
**Post date:** [April 14, 2020, 6:18pm UTC](https://forum.openwrt.org/t/solved-openvpn-static-host-resolve-issue/60609/1 "2020-04-14T18:18:07Z")

</div>

Hello Forum,  
I set up my OpenVPN connection and it's working well so far.

Except:  
I set up a static hostname to ip (myhostname.lan -\> 192.168.x.y) assignment in Network-\>DHCP and DNS-\>Static Entries.

Only when connected via OpenVPN, the hostname is not resolved to the IP (the IP itself of course is working fine).

What could possibly be the reason for this?

Thank you for your assistance!

Andreas

---

<div class="post-metadata">

**Author:** ![psherman](https://forum.openwrt.org/letter_avatar/psherman/32/6_449c533f586939b6e5f246632a46421f.png) [@psherman](https://forum.openwrt.org/u/psherman)\
**Post date:** [April 14, 2020, 7:06pm UTC](https://forum.openwrt.org/t/solved-openvpn-static-host-resolve-issue/60609/2 "2020-04-14T19:06:40Z")

</div>

It is likely that the dns is being overridden from local to a dns server specified in the OpenVPN configuration (or pushed by the server).

---

<div class="post-metadata">

**Author:** ![sklerotraficon](https://forum.openwrt.org/user_avatar/forum.openwrt.org/sklerotraficon/32/3007_2.png) [@sklerotraficon](https://forum.openwrt.org/u/sklerotraficon)\
**Post date:** [April 14, 2020, 7:35pm UTC](https://forum.openwrt.org/t/solved-openvpn-static-host-resolve-issue/60609/3 "2020-04-14T19:35:42Z")

</div>

Indeed, the dns config is pushed in the openvpn config:

```
list push 'redirect-gateway def1'
list push 'block-outside-dns'
list push 'dhcp-option DNS [router_ip]'
list push 'route 192.168.[x].0 255.255.255.0'

```

and dnsmasq is configured:

```
option domainneeded '1'
option localise_queries '1'
option rebind_protection '1'
option rebind_localhost '1'
option local '/lan/'
option domain 'lan'
option expandhosts '1'
option authoritative '1'
option readethers '1'
option leasefile '/tmp/dhcp.leases'
option resolvfile '/tmp/resolv.conf.auto'
option confdir '/tmp/dnsmasq.d'
option logqueries '1'
option localservice '1'

```

But how can the dns be configured correctly to resolve also local hostnames ?

Thanks for an insight!

---

<div class="post-metadata">

**Author:** ![trendy](https://forum.openwrt.org/user_avatar/forum.openwrt.org/trendy/32/8800_2.png) [@trendy](https://forum.openwrt.org/u/trendy)\
**Post date:** [April 14, 2020, 10:45pm UTC](https://forum.openwrt.org/t/solved-openvpn-static-host-resolve-issue/60609/4 "2020-04-14T22:45:27Z")

</div>

First of all if you want to configure a hostname you need to do it under Network/Hostnames and not as a static DHCP lease.  
Post the following with VPN enabled:

```
uci export dhcp; ls -l /etc/resolv.* /tmp/resolv.*; head -n -0 /etc/resolv.* /tmp/resolv.* ;\
nslookup myhostname.lan

```

Finally the 192.168.X.Y is private address space and you don't need to cover the octets for security.

---

<div class="post-metadata">

**Author:** ![sklerotraficon](https://forum.openwrt.org/user_avatar/forum.openwrt.org/sklerotraficon/32/3007_2.png) [@sklerotraficon](https://forum.openwrt.org/u/sklerotraficon)\
**Post date:** [April 14, 2020, 11:08pm UTC](https://forum.openwrt.org/t/solved-openvpn-static-host-resolve-issue/60609/5 "2020-04-14T23:08:32Z")

</div>

Hi trendy,

thanks for the hint on the config of the hostname, I already fixed that.

This is the output:

```
root@OpenWrt:~# uci export dhcp; ls -l /etc/resolv.* /tmp/resolv.*; head -n -0
/etc/resolv.* /tmp/resolv.* ;\
> nslookup myhostname.lan
package dhcp

config dnsmasq
        option domainneeded '1'
        option localise_queries '1'
        option rebind_protection '1'
        option rebind_localhost '1'
        option local '/lan/'
        option domain 'lan'
        option expandhosts '1'
        option authoritative '1'
        option readethers '1'
        option leasefile '/tmp/dhcp.leases'
        option resolvfile '/tmp/resolv.conf.auto'
        option confdir '/tmp/dnsmasq.d'
        option logqueries '1'
        option localservice '1'

config dhcp 'lan'
        option interface 'lan'
        option start '100'
        option limit '150'
        option leasetime '12h'
        option dhcpv6 'server'
        option ra 'server'
        option ra_management '1'

config dhcp 'wan'
        option interface 'wan'
        option ignore '1'

config odhcpd 'odhcpd'
        option maindhcp '0'
        option leasefile '/tmp/hosts/odhcpd'
        option leasetrigger '/usr/sbin/odhcpd-update'
        option loglevel '4'

config domain
        option name 'myhostname.lan'
        option ip '192.168.2.211'

lrwxrwxrwx 1 root root 16 Feb 27 22:05 /etc/resolv.conf -> /tmp/resolv.conf
-rw-r--r-- 1 root root 32 Apr 15 00:58 /tmp/resolv.conf
-rw-r--r-- 1 root root 151 Apr 14 22:47 /tmp/resolv.conf.auto
==> /etc/resolv.conf <==
search lan
nameserver 127.0.0.1

==> /tmp/resolv.conf <==
search lan
nameserver 127.0.0.1

==> /tmp/resolv.conf.auto <==
# Interface wan
nameserver [nameserver_1_ipv4]
nameserver [nameserver_2_ipv4]
# Interface wan6
nameserver [nameserver_1_ipv6]
nameserver [nameserver_2_ipv6]
Server: 127.0.0.1
Address: 127.0.0.1#53

Name: myhostname.lan
Address 1: 192.168.2.211
*** Can't find myhostname.lan: No answer

```

_Note: replaced nameserver IPs and myhostname.lan_

Thank your for taking a look at it!

---

<div class="post-metadata">

**Author:** ![trendy](https://forum.openwrt.org/user_avatar/forum.openwrt.org/trendy/32/8800_2.png) [@trendy](https://forum.openwrt.org/u/trendy)\
**Post date:** [April 14, 2020, 11:13pm UTC](https://forum.openwrt.org/t/solved-openvpn-static-host-resolve-issue/60609/6 "2020-04-14T23:13:56Z")

</div>

Works fine!

---

<div class="post-metadata">

**Author:** ![sklerotraficon](https://forum.openwrt.org/user_avatar/forum.openwrt.org/sklerotraficon/32/3007_2.png) [@sklerotraficon](https://forum.openwrt.org/u/sklerotraficon)\
**Post date:** [April 14, 2020, 11:16pm UTC](https://forum.openwrt.org/t/solved-openvpn-static-host-resolve-issue/60609/7 "2020-04-14T23:16:16Z")

</div>

Hi Trendy,  
well the openvpn client (Android) cannot find myhostname.lan ... with the corresponding IP (192.168.2.211) this works just fine...so something is still not right.

---

<div class="post-metadata">

**Author:** ![trendy](https://forum.openwrt.org/user_avatar/forum.openwrt.org/trendy/32/8800_2.png) [@trendy](https://forum.openwrt.org/u/trendy)\
**Post date:** [April 14, 2020, 11:20pm UTC](https://forum.openwrt.org/t/solved-openvpn-static-host-resolve-issue/60609/8 "2020-04-14T23:20:53Z")

</div>

Either you are not pushing the DNS to the client or the client is not using this DNS to resolve the hostname.  
Run a tcpdump to verify that:  
`tcpdump -i any -vvvn host 192.168.x.y and udp port 53`  
where 192.168.x.y the IP of the Android

---

<div class="post-metadata">

**Author:** ![sklerotraficon](https://forum.openwrt.org/user_avatar/forum.openwrt.org/sklerotraficon/32/3007_2.png) [@sklerotraficon](https://forum.openwrt.org/u/sklerotraficon)\
**Post date:** [April 14, 2020, 11:28pm UTC](https://forum.openwrt.org/t/solved-openvpn-static-host-resolve-issue/60609/9 "2020-04-14T23:28:56Z")

</div>

> [@trendy](#):
>
> tcpdump -i any -vvvn host 192.168.x.y and udp port 53

```plaintext
 10.8.0.6.44939 > 192.168.2.253.53: [udp sum ok] 29964+ A? myhostname.lan. (28)
 10.8.0.6.17888 > 192.168.2.253.53: [udp sum ok] 8160+ A? myhostname.lan. (28)
 10.8.0.6.1100 > 192.168.2.253.53: [udp sum ok] 49168+ A? myhostname.lan. (28)
 10.8.0.6.4515 > 192.168.2.253.53: [udp sum ok] 22233+ A? myhostname.lan. (28)
 10.8.0.6.15175 > 192.168.2.253.53: [udp sum ok] 64249+ A? myhostname.lan. (28)
 10.8.0.6.3345 > 192.168.2.253.53: [udp sum ok] 23876+ A? myhostname.lan. (28)

```

Note: Regular dns resolving on the Android work just fine, just the \*.lan names are not resolved when connected with OpenVPN...

---

<div class="post-metadata">

**Author:** ![trendy](https://forum.openwrt.org/user_avatar/forum.openwrt.org/trendy/32/8800_2.png) [@trendy](https://forum.openwrt.org/u/trendy)\
**Post date:** [April 14, 2020, 11:33pm UTC](https://forum.openwrt.org/t/solved-openvpn-static-host-resolve-issue/60609/10 "2020-04-14T23:33:54Z")

</div>

You need to disable the `localservice` option in dns configuration to allow dnsmasq to respond to hosts outside of the server.

---

<div class="post-metadata">

**Author:** ![sklerotraficon](https://forum.openwrt.org/user_avatar/forum.openwrt.org/sklerotraficon/32/3007_2.png) [@sklerotraficon](https://forum.openwrt.org/u/sklerotraficon)\
**Post date:** [April 14, 2020, 11:35pm UTC](https://forum.openwrt.org/t/solved-openvpn-static-host-resolve-issue/60609/11 "2020-04-14T23:35:52Z")

</div>

Hi trendy,

so you mean the following change in /etc/config/dhcp:

> config dnsmasq  
> ...  
> option localservice '0'

---

<div class="post-metadata">

**Author:** ![sklerotraficon](https://forum.openwrt.org/user_avatar/forum.openwrt.org/sklerotraficon/32/3007_2.png) [@sklerotraficon](https://forum.openwrt.org/u/sklerotraficon)\
**Post date:** [April 14, 2020, 11:38pm UTC](https://forum.openwrt.org/t/solved-openvpn-static-host-resolve-issue/60609/12 "2020-04-14T23:38:29Z")

</div>

Hi trendy,

that was it!!!

Thank you very much!

---

<div class="post-metadata">

**Author:** ![trendy](https://forum.openwrt.org/user_avatar/forum.openwrt.org/trendy/32/8800_2.png) [@trendy](https://forum.openwrt.org/u/trendy)\
**Post date:** [April 14, 2020, 11:38pm UTC](https://forum.openwrt.org/t/solved-openvpn-static-host-resolve-issue/60609/13 "2020-04-14T23:38:53Z")

</div>

If the problem is solved, feel free to [mark the topic accordingly](https://forum.openwrt.org/t/how-to-mark-a-topic-as-solved/40174).

---

<div class="post-metadata">

**Author:** ![system](https://forum.openwrt.org/uploads/default/original/3X/7/4/740520c71f00039bbf001045c682f0ecb25e905a.png) [@system](https://forum.openwrt.org/u/system)\
**Post date:** [April 24, 2020, 11:38pm UTC](https://forum.openwrt.org/t/solved-openvpn-static-host-resolve-issue/60609/14 "2020-04-24T23:38:57Z")

</div>

Closed on April 24, 2020, 11:38pm UTC

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
