Static route toward a DNS Address, it is possible?

Solution 1:

The syntax of the route add command is

route add destination mask subnetmask gateway metric costmetric if interface

Where destination is either an IP address or host name for the network or host.

Example:

route add webservices.example.com mask 255.255.255.255 10.11.12.13

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.

Solution 2:

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.

:: Get IP of Domain name
setlocal EnableDelayedExpansion

set myServer=your.server.com

for /f "tokens=1,2 delims=[]" %%a IN ('ping -n 1 !myServer!') DO (
 if "%%b" NEQ "" set myServerIP=%%b
)
echo ip is %myServerIP%

route add %myServerIP% mask 255.255.255.255 <gateway ip address>
EXIT

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!

Solution 3:

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.