28

I am trying to write a program that changes the default gateway of network time by time. But it seems that there are caches on the route table in every process so that I cannot control the network behavior accurately. Can I just flush route table to that process?

For example if I executed an Iexplore.exe first, then changed the default gateway to a Korean vpn, IE still went to amercia default gateway. But if I change the default gateway first and then execute Iexplore.exe, it went to Korea.

So how can I flush the route table cache? Thanks.

jay
  • 1,032
  • 2
  • 13
  • 20

4 Answers4

53

From command prompt as admin run:

netsh interface ip delete destinationcache

Works on Win7.

exceed
  • 546
  • 5
  • 3
5

route -f causes damage. So we need to either disconnect the correct parts of the routing table or find out how to rebuild it.

DMart
  • 2,401
  • 1
  • 14
  • 19
  • If we have DHCP giving the correct routes then it's fine. I have used that and reconnected my wired and wireless networks and I'm fine. – Paul Stelian Oct 29 '18 at 10:11
  • 1
    route -f is very dangerous if your vm is in the cloud, you loose all possible access unless you restore a backup. – Anass Kartit Nov 18 '20 at 19:50
4

You can open a command prompt and do a

route print

and see your current routing table.

You can modify it by

route add    d.d.d.d mask m.m.m.m g.g.g.g 
route delete d.d.d.d mask m.m.m.m g.g.g.g 
route change d.d.d.d mask m.m.m.m g.g.g.g

these seem to work

I run a ping d.d.d.d -t change the route and it changes. (my test involved routing to a dead route and the ping stopped)

samus
  • 6,102
  • 6
  • 31
  • 69
w33mhz
  • 360
  • 2
  • 3
0

In Microsoft Windows, you can go through by route -f command to delete your current Gateway, check route / ? for more advance option, like add / delete etc and also can write a batch to add route on specific time as well but if you need to delete IP cache, then you have the option to use arp command.

Flexo
  • 87,323
  • 22
  • 191
  • 272
Rizwan Ranjha
  • 380
  • 3
  • 4
  • 16
  • 12
    The route -f command causes the gateway to be permanently lost. You should definitely include that in your answer. – mavrosxristoforos May 26 '14 at 08:32
  • 1
    This completely destroyed my VPN configurations. I had to uninstall and reinstall the VPN clients to fix it. Just rebooting Windows didn't help. – Mat-KH Dec 12 '22 at 15:03