# Ubuntu – Web server on local network

networkingwebserver

I have problem accessing (one of my) web server from my local network.

I have a (Ubuntu) computer that that acts as router, web server etc. That works well, I can access the web server both externally and from the internal network. I can also access computers on the internal network via ssh from the outside (re-direction with iptables).

Now I have another web server on the internal network. I have made some routing paths with iptables. If I in the browser type some.webadress.com:40080 it should go to the “internal” web server.

This works:

• Access the internal web server with the domain name (+port) from an
external network
• Access the internal web server with the internal IP number (+port)
from the internal network

This does not work:

• Access the internal web server with the domain name (+port) from the internal network

I'm pretty sure that the routing part works ok. The question is if I have to have a DNS or is it something that I should add/change in my /etc/hosts file?

EDIT:
Some clarification. The device/webserver that I'm having problem to reach is a webswitch. The webswitch is a device that makes it possible to control a number of high-voltage relays (e.g. car heater, external lights etc.) via the web/phone app. The problem arises when a smartphone is used. If I'm on the 3G net, I use some.webadress.com:40080 (note that I use port translation) and if I'm on the home-wifi I must use 192.168.0.101:8080. What I want to use is some.webadress.com:40080 regardless if I'm on the local net or an external net.

(The better half in the family is not that interested in technical stuff so having to swift addresses is actually an issue 🙂

Other machines in your network will reach the web server without passing your router; it's in the same local network. You should be able to access your web server from the internal network directly using its IP address, e.g. http://192.168.0.101:8080. I assume that you don't do port translation and your web server runs on the same port on the machine as you configured your router to forward it from.

If that works, then you'll only have to tell your machines to talk to 192.168.0.101 when resolving the name some.webadress.com. This is something you should be able to configure on your local DNS server (might be running on your router). You should also make sure your machines in the local network are always using this local DNS server.

For example, if you would set up a DNS server in Ubuntu using dnsmasq, it will load the /etc/hosts file on this machine by default, so putting a line

192.168.0.101     some.webadress.com


would be sufficient.

Alternatively, edit the /etc/hosts file on all machines to overrule the answer from DNS. That's a lot harder to maintain, especially when it's about a larger number of machines.