4

I have set up a DNS server for local use in a LAN. This server can resolve IP addresses, so when I ping mypc.company I get a successful reply from the IP address 192.168.1.34.

Problem

I have deployed an app(myApp) on a Tomcat application server on a machine (192.168.1.34). I can access this through these URLs:

http://mypc.company:8080/myApp 
http://192.168.1.34:8080/myApp

Question

Is there any way to set up a domain name (or any technique) so that when I navigate to www.myApp.com , which will take me directly to http://192.168.1.34:8080/myApp?

Kaleb
  • 151

3 Answers3

2

Yes you can and it's quite simple

You have a real domain that you are paying for:
Log into our control panel on your domain hosting website and access DNS. Manage forwarding and setup a Subdomain, with masking.

Domain
company

Subdomain   Forward to                      Type
myApp       http://company.com:8080/myApp   Forward with Masking 

You are creating a DNS definition that will have the defined call myApp.company.com and it will forward automatically to http://company:8080/myApp. The masking comes to play where the definition stays hidden (masked) in the URL, otherwise the user will ask for myApp.company.com but when you page loads it will see https://company:8080/myApp which isn't what you want.

You don't have a domain.
You are doing everything on your localhost.

Modify your local DNS file: LINK

dir: C:\Windows\System32\drivers\etc
file: host

In order to modify this file you will have to have administrative privileges. In the properties of this file you can change the priveleges in order to modify this "read only" file.

Then just change this line: 127.0.0.1 localhost
to something like this:        127.0.0.1 greatapp.mytestlocal.com

A localhost is the ip address of: 127.0.0.1, a unique ip designed specifically for localhost.

ejbytes
  • 2,050
2

Yes and no. You can register a domain and have it point to RFC1918 space (eg addresses starting 192.168.x.x). What you can't do is use DNS or domain name registration to change ports, so you can't have a request on the LAN be directed from port 80 to port 8080 using DNS or domain registration - you would need to intercept that request on the server or router between the server and client to map the port.

Alternatively you could set up another web service on port 80 which redirects to port 8080 for the main query to answer - if you are trying to have both internal and external reachability that may be the simplest answer.

davidgo
  • 73,366
0

Redirecting app.example.com (which is really http://app.example.com:80/) to http://192.168.1.2:12345/some/path isn’t possible using DNS only. The problem is evident: While you could make app.example.com resolve to 192.168.1.2, the service you want to redirect to isn’t listening on port 80 or even the root path (/).

So we need something to listen on port 80 and redirect users to the correct port and path. In theory, any web server could do this. I won’t delve into name-based virtual hosts here, but they may be necessary when redirecting for multiple services.

A regular web server could serve this HTML file to redirect users:

<html>
<head>
  <title>Redirecting...</title>
  <meta http-equiv="refresh" content="0; url=http://app.example.com:12345/some/path">
</head>
<body>
  <h1>Redirecting...</h1>
</body>
</html>

A more sophisticated setup could perform the redirect using HTTP headers, ie. on Apache:

Redirect permanent / http://app.example.com:12345/some/path

The web server doesn’t have to run on the same machine. It can redirect to any valid URL.

user219095
  • 65,551