I want to create a server that acts as a loopback to the requesting machine on a particular subdomain.
How do I reference the requesting IP to route traffic on a handful of ports back to the requesting IP?
Alternatively a clone of xip.io running on my own subdomains would work, so routing like this:
10.199.1.1.my.domain.com -> routes all traffic to 10.199.1.1
What you're asking to do is disgustingly wrong and should not be allowed anywhere near a the public internet or any production environment - you're opening up some potentially catastrophic security holes that WILL result in a problem for you at some point in the future.
As a professional it is your job to ensure that your superiors are aware of the problems in what's being implemented and help them find a solution that ISN'T bad, wrong and dangerous. Dealing with that is left as an exercise for the reader (if you want assistance with that try asking the folks over on The Workplace.
All that said, if you absolutely must implement a bad idea because your superiors are intransigent the way to do it is usually Apache's mod_rewrite - that module LOVES to do terrible things.
You can implement the
xp.io
-alike option withmod_rewrite
by capturing URLS of the forma.b.c.d.mydomain.com/xxxx
and issuing a redirect (301 or 302) tohttp://a.b.c.d/xxxx
.You could also implement automatic redirection using the
%{REMOTE_ADDR}
mod_rewrite variable to automatically fill in the IP address if you wish.These solutions are inherently fragile: For one they only work for HTTP/HTTPS traffic (if you want something else you'll need to implement a proper proxy solution). For another if the requestor is behind a NAT or proxy it will break (possibly in unpredictable or insecure ways).