I need to add a static route on a windows server toward a web server with a service; I need to add a static route with this command on a Windows command prompt:
ROUTE ADD -p IPADREESS GATEWAYIP
Is there a way to do a static route toward a DNS address instead of a IP Address ? How ?
For example:
ROUTE ADD -p DNSServer GATEWAYIP
The syntax of the
route add
command isWhere destination is either an IP address or host name for the network or host.
Example:
See this Microsoft article: To add a static IP route
You have to keep in mind that the entry will be resolved to an IP address, so if the DNS for the host name changes, there will still be the original IP address in the routing table.
This is more of a workaround that I use. You can use this batch script. Just add it in task scheduler to run every time your PC starts. This will get the IP of your domain name and add route.
Don't use the -p option, otherwise the route will be permanent. If your domain IP keeps changing at regular intervals then use task scheduler to run this script at those intervals. Hope this helps!
No, not on the network layer. You could perhaps achieve your goal using something like a proxy. You could also emulate the behavior using a script but it would likely be fallible.
To be clear, my point was that you cannot dynamically route based on hostname. I am not contesting what splattne said.
No, but perhaps what you want could be achieved with a local override in /etc/hosts.
Example 1
One example of when this was useful from my experience:
I have a busy reverse proxy (on the "new" network), which fronts a number of sources. To get to one of those sources, the traffic would have to go through the old network which is desirable to avoid. However, if we added another interface (on the new network) to that backend host, we could make the traffic go through the new network. So in this particular case I just put an override on the reverse-proxies /etc/hosts that pointed to the new IP on the backend server.
(For Windows, just change C:\Windows\System32\drivers\etc\hosts)
Example 2
Another example, this time with a browser proxy.
I was recently deploying a major upgrade to our website, and wanted to have people test things exactly as they would be (ie. same URLs as would be used post go-live).
So in this case I set up a browser/forward proxy (squid) on a new machine and altered its /etc/hosts to point to the new-world IPs, while leaving DNS to remain with the old-world IPs (until go-live). The effect was that if they configured their browser to use this proxy, it would go to the new-world website, otherwise they went to the old-world website. I also set up a PAC (Proxy Auto Configuration) file that had a set of rules to say which URLs should use the proxy, and anything else should go direct. Worked reasonably well.