26 March, 2016

Connect to your server in your LAN via your WAN url: an openWRT solution.

So, I run my own ownCloud. Figures, right?

Can't reach the server from the LAN

Of course, I sync files on my desktop between my laptop and phone. The desktop client is setup with the IP address of the server in my living room. But my phone and laptop, configured to connect to my public, DynDNS URL (so they work when I'm traveling), can't connect from the home network. Triple-uncool. I like my photos from my phone to by auto-uploaded when I connect to wifi at home; and more importantly my laptop should sync when I get home from travel!

Danimo blamed my router - a Cisco (Linksys) E4200. That was (once upon a time) an expensive, high-end router. Sadly, having been abandoned by its manufacturer, it has become an expensive, high-end liability. I can't even log into the administration interface, browsers tell me that the connection is insecure. There are more issues, like the slow WLAN-LAN transfer speeds I experienced and I'm not even talking about security here. Linus once eloquently expressed his feelings towards NVIDIA, a resentment I now feel towards CISCO.

openWRT to the rescue

I learned my lesson. No router not able to run an open source firmware will get in my house. While I don't feel any need whatsoever to fiddle with things that do their job, Linksys screwed up here: they left me on broken software long before I had any need for new hardware.

After some digging, I learned that TP-Link has been (mostly inadvertently) a decent citizen for OpenWRT fans. So, even if they'd abandon their router like Linksys/Cisco did, there was a future. I bought a TP-Link Archer C7. Affordable and it can run OpenWRT.

After setting it up initially, things worked. For a day. After that, no amount of fiddling could make it work again. Magic. Today I gave up on the original firmware and installed OpenWRT. It was easy - as easy as upgrading to a new TP-Link firmware: download the openWRT firmware, go to the upgrade interface, select it, hit start. A while later you ca visit the web interface. Which is a tad more complicated, but not much - and noticeably more capable. It didn't take me any longer than on the original firmware to set up my wifi and guest networks.

How to make it work

But it didn't solve the problem. I had to resort to a web search and found a neat trick, which I'm happy to share (assuming 192.168.1.11 is your server on your LAN):
  • Log into your router over ssh
  • Add to your /etc/dnsmasq.conf file the following: address=/example.com/192.168.1.11
  • Add to your /etc/hosts file: 192.168.1.111 example.com
A few minutes later, things will work.

Essentially, the DNS provider in OpenWRT will provide your local server address to local clients... It thus breaks when you use another DNS than the one provided by the router via DHCP.

I'd be happy to hear from other and/or better solutions. Heck, this might only work for a day or might be horrible or maybe I changed something else which made it work. What do I know...

No comments:

Post a Comment

Say something smart and be polite please!