3

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
  • 141
  • 1
  • 1
  • 5
  • You could look into adding the "www." reference to your `hosts` file on your LAN computers. – Kinnectus Jun 09 '16 at 09:57
  • 2
    Possible duplicate of [I have a domain name that I want to redirect to my local server. How do I do this?](http://superuser.com/questions/559623/i-have-a-domain-name-that-i-want-to-redirect-to-my-local-server-how-do-i-do-thi) – Kinnectus Jun 09 '16 at 09:59
  • @Big Chris: they are very different question.on the other question it's all about adjusting domain name for a personal use only. but what i want is this domain to be accessed through out LAN machine. – Kaleb Jun 09 '16 at 10:29
  • They're not different questions at all... your hosts file can be used to redirect your chosen domain name to the desired domain name. the hosts file is always read and used first, if a match is found. If you have a Windows Server then you can configure it use forwarders so requests for your www. domain can be forwarded to the desired domain. – Kinnectus Jun 09 '16 at 10:45
  • @Big Chris: I think that domain you forward your request to must only be ip number.But as i stated on my question i want to forward it to specific url not ip. – Kaleb Jun 09 '16 at 11:10
  • DNS names represent addresses, not addresses plus ports. You say "I have tried creating a website and redirecting to the given URL in Windows Server IIS, but had no luck." This sounds entirely possible, but "I had no luck" doesn't tell us anything. Perhaps make your question about that instead.. – Ƭᴇcʜιᴇ007 Jun 13 '16 at 12:48
  • Possible duplicate of [Direct domain to IP and port?](http://superuser.com/questions/742195/direct-domain-to-ip-and-port) – Ƭᴇcʜιᴇ007 Jun 13 '16 at 12:49
  • The question is still unclear. Especially noting what BigChris has offered as a solution and the OP's response. I think this needs to be re-examined and the question modified for explicit inputs and outputs with no ambiguous nor alias names. – ejbytes Jun 16 '16 at 02:59
  • Are we asking "can I set an A record to a private IP range" ? – Journeyman Geek Jun 16 '16 at 03:11

3 Answers3

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
  • 68,623
  • 13
  • 106
  • 163
1

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,014
  • 3
  • 13
  • 25
  • The OP is speaking about his private LAN. No mention of any domain hosting. – Ƭᴇcʜιᴇ007 Jun 13 '16 at 12:51
  • @Ƭᴇcʜιᴇ007 It was somewhat unclear. If you think you understand the question really well you should consider editing the OP's question. I re-read and re-examined the OP's question and it's not 80% clear still. But I redefined my answer to meet some of the ambiguities. But still no response from the OP so....? – ejbytes Jun 16 '16 at 02:52
  • Might also want to do that for ::1 – Hennes Jun 16 '16 at 06:00
  • This might work but the only problem is I can't go on every machine and modify the local DNS file. – Kaleb Jun 16 '16 at 06:03
  • Of course. You'd only have to change the DNS/host file on the server. Unless you're running a Linux server then it would be a different file. You're talking about accessing the server's web page. I think you're confusing yourself. – ejbytes Jun 17 '16 at 12:27
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.

Daniel B
  • 60,360
  • 9
  • 122
  • 163