Search code examples
dnsnatowncloudloopback

Running DNS Server to circumvent NAT-Loopback issue


First I want to say that I probably read everything that there is on the internet regarding the problem.

And the problem is that I can not access my owncloud over doc.selfhost.eu if I am in the same network. But I can access it from inside the network over its internal IP (192.168.2.200) and from outside the network over doc.selfhost.eu.

My setup: A home server running Linux Mint 17.2 Cinnamon which is supposed to be for media and to run owncloud.

The server is connected to a Speedport 723v which doesn't support NAT Loopback. Ports 80 and 443 are forwarded and for dynamic DNS I have an account on selfhost.de which I entered in the router settings.

On my Windows 7 machine (which I'm trying to access the server from) I entered 192.168.2.200 (the servers internal IP) as DNS.

In Mint I disabled network manager (in fact I removed it) and I am now using interfaces.

Not a solution would be to change the hosts files of all the clients (on unrooted androids this isn't even possible).

Questions:

  1. What would I have to change to access my owncloud from the internal network over the external IP?

  2. Is it possible to not configure the clients at all? Meaning no entering the servers DNS or changing hosts in the clients for it to work properly. In the following you can see all the files I fiddled around with and which I think might be relevant.

/etc/network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.2.200
netmask 255.255.255.0
gateway 192.168.2.1
dns-nameservers doc.selfhost.eu 8.8.8.8

/etc/resolv.conf

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.0.1

In /etc/dnsmasq.conf this is the only thing I added:

listen-address=127.0.0.1
listen-address=192.168.2.200
address=/doc.selfhost.eu/192.168.2.200

/etc/dnsmasq.d/doc.selfhost.eu (read somewhere to create this)

address=/doc.selfhost.eu/192.168.2.200

/etc/hosts

127.0.0.1       localhost
127.0.1.1       doc-desktop
192.168.2.200   doc.selfhost.eu

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Owncloud settings in /var/www/owncloud/config/config.php

'trusted_domains' =>
  array (
0 => '192.168.2.200',
1 => 'doc.selfhost.eu',
  );

Apache configuration In /etc/apache2/apache2.conf everything is pretty standard. I only added:

ServerName doc-desktop

/etc/apache2/sites-enabled/owncloud.conf. No changes in sites-available, no linking.

<VirtualHost 192.168.2.200:80>

#### Redirect to port 443 ###
RewriteEngine on
ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
#### End of Redirection configuration ###

DocumentRoot /var/www/owncloud/
<Directory /var/www/owncloud>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
</Directory>

</VirtualHost>

<VirtualHost 192.168.2.200:443>
####Configuration for SSL #####
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key
#### End of SSL Configuration ####
Header always set Strict-Transport-Security "max-age=15768000; includeSubDomains; preload"
DocumentRoot /var/www/owncloud/
<Directory /var/www/owncloud>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
</Directory>
</VirtualHost>

In case it comes up. from server:

dig doc.selfhost.eu

; <<>> DiG 9.9.5-3ubuntu0.5-Ubuntu <<>> doc.selfhost.eu
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 49046
;; flags: qr aa rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;doc.selfhost.eu.          IN      A

;; ANSWER SECTION:
doc.selfhost.eu.   0       IN      A       192.168.2.200

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Mon Oct 26 02:35:15 CET 2015
;; MSG SIZE  rcvd: 54

From client inside network (with cygwin):

dig doc.selfhost.eu

; <<>> DiG 9.10.3 <<>> doc.selfhost.eu
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29482
;; flags: qr aa rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;doc.selfhost.eu.          IN      A

;; ANSWER SECTION:
doc.selfhost.eu.   0       IN      A       192.168.2.200

;; Query time: 31 msec
;; SERVER: 192.168.2.200#53(192.168.2.200)
;; WHEN: Mon Oct 26 02:37:32     2015
;; MSG SIZE  rcvd: 54

I hope this is everything. Thanks.


Solution

  • ... which doesn't support NAT Loopback. .... What would I have to change to access my owncloud from the internal network over the external IP?

    If you insist of using the external IP address from inside then you have to replace the router against a model which supports NAT Loopback (NAT hairpinning or NAT reflection or whatever you call it). There is no way around because connection with the external IP address will go through the router.

    Is it possible to not configure the clients at all? Meaning no entering the servers DNS or changing hosts in the clients for it to work properly. ..

    You might try to run your own DNS server and tell the clients via DHCP to use this DNS server. This DNS server then could provide the internal IP of your home server. I doubt that this can be done on the router itself but you could probably run DNS and DHCP on your home server and disable DHCP on the router.

    For specific question on how to set up DNS and DHCP please head over to superuser.com or serverfault.com since this is off-topic here.