Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


Is there a way to do a static route toward a DNS address instead of a IP Address ? How ?

For example:

share|improve this question
Can you elaborate on why you think you need this? Perhaps there is a better way. – Zoredache May 23 '10 at 20:17
since the name will always resolve to an IP address I don't see the point putting a FQDN in the command. You can't, but even if you could I still don't see the point. Tell us what you are trying to accomplish and we (the community) can give you some ideas. – user288188 May 10 '15 at 8:17

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.


route add mask

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.

share|improve this answer
Even with the issue about DNS changing, it would be great to use a host name in the route add command. When I use the syntax in your example on Windows 8, I consistently get The route addition failed: The parameter is incorrect. – zacharydl Dec 16 '14 at 20:14

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


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 <gateway ip address>

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!

share|improve this answer

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.

share|improve this answer

Is there a way to do a static route toward a DNS address instead of a IP Address ? How ?

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.