4

I have two different Networks at two different places:

192.168.10.0 / 255.255.255.0

192.168.20.0 / 255.255.255.0

Now I want to define a host entry on my windows pc, who maps

either 192.168.10.1 or 192.168.20.1 to the name "myServer", depending on in which network i am.

Maybe there are some kind of wildcards for the own address like *.*.*.1 ?

Thanks, Tobi

  • I don't think this is possible. I'm fairly certain that the hosts file uses a "first match" rule, so only the first entry will be used and all further processing of the hosts file for that particular host name will be ignored. – joeqwerty Dec 17 '15 at 16:55
  • Ok, than more general: Is there another way to achieve the goal that i can reach the two Ips with the same name without having different DNS Servers? – Programmer879 Dec 17 '15 at 16:56
  • @Programmer879 you could maybe write a powershell function that does this. but i'm not sure if this is the right solution for this problem, perhaps there are better ways to achieve that. – SimonS Dec 17 '15 at 17:15

2 Answers2

1

You can't do this with the hosts file and you don't need two DNS servers. You need one DNS server with an A record for both ip addresses. The DNS server will serve up the A record that matches the subnet that the client request came from.

So when you query that name from the 192.168.10.0 network interface the DNS server will return the 192.168.10.0 A record. Vice versa for the 192.168.20.0 interface and A record.

joeqwerty
  • 109,901
  • 6
  • 81
  • 172
0

You did not specify why you want this entry. You can just add two lines to the the hosts file, one for each IP address. This assumes your IP address is static on both these networks. (It can be static even if you use DHCP to get the address.) Any programs that display names for IP address will display your server's name when you are connected to either network.

If you want this to connect to myServer from your computer, it might be better to define a hosts entry reading 127.0.0.1 myServer. This will work on either network, or even if you aren't on a network.

BillThor
  • 27,737
  • 3
  • 37
  • 69
  • I´m sorry, I dont understand yet. How can I connect to `myServer` by using `127.0.0.1 myServer`? – Programmer879 Dec 21 '15 at 21:38
  • @Programmer879 127.0.0.1 always refers to your system. It is the IP address of the loopback interface. This will be used if you are connecting to the system you are connecting from. – BillThor Dec 22 '15 at 02:27