1

I have a NAS working under my LAN network. Let's say 192.168.1.5
I have a custom domain name such as mynas.com linked to my fixed IP address , routed to this IP.

Now, I want to setup my devices (iPhones, etc.) to my NAS using one and single URL/IP.

Normally I would enter my custom domain name. But when I'm at home, I don't want my traffic to go through internet when it's available under the LAN network.

How can I setup a system which routes my traffic only in local when I'm at home, and by internet when I'm away?

Thank you,

2 Answers 2

1

If your router supports it, you could configure DNS entries on the router that map to the local IP address.

I've done this in DD-WRT by configuring the addn-hosts option under the DNSMasq settings.

DD-WRT Services Screenshot

The /jffs/etc/config/dns.txt file it references contains entries like:

192.168.1.1 router
192.168.1.2 switch
192.168.1.3 nas

Which would be expanded to router.domain.com, switch.domain.com, and nas.domain.com and then mapped to your local IP address(es) when you're on your local network using your router's DNS. This means the initial DNS query goes to your router, but all traffic after that is strictly between your client and server without going through the router.

When you're away from home the internet DNS servers would resolve nas.domain.com to your public IP address.

0

I think you do not have to do anything at all, you can use your public IP/domain from inside your home network too.

Your router will see that the packet is destined for itself and via the port forward you probably already have the packets get routed to the NAS (while staying in your network all the time).

Edit: the only disadvantage of this vs. using 192.168.1.5 is that the packets always go through the gateway (i.e. your router).

2
  • This confirms what I suspected without being sure. I'll have a look at the in/out stats of my router to be sure. Thanks for the help.
    – alex
    Sep 22, 2016 at 10:26
  • Sidenote: If the user is using NAT (very likely) then the router will need to understand hairpin-NAT. If it does not then this will not work.
    – Hennes
    Oct 3, 2016 at 15:44

You must log in to answer this question.

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