How to map an IP adress to localhost?
You would have to assign the IP address 192.168.1.222 to one of your network interfaces. Merely altering the routing table will not have the desired result; traffic would indeed arrive at the localhost, but your computer will then conclude the message has not yet reached its destination. Lacking any further options of passing the message along, it will then be dropped.
Assigning 192.168.1.222 to one of your physical interfaces would be the simplest solution, but if you do not have a spare interface and do not want your changes to affect the rest of the network, you can create another loopback interface, similar to the one at 127.0.0.1.
The procedure has changed somewhat since Windows XP. Open the device manager via the control panel and in the Action menu, click 'Add legacy hardware'. If this option is missing, the wizard can be started via the executable 'hdwwiz.exe'.
When asked, select hardware manually from a list rather than installing it automatically. In the following menus, select 'Network Adapter', 'Microsoft' as manufacturer and look for the 'Microsoft Loopback Adapter'. If the device has been installed correctly, a new network adapter will have appeared in the device manager.
Open the Network and Sharing Center via the control panel and click 'Change adapter settings' in the left bar. The following window will appear, including our newly installed adapter.
Open its properties. From the Networking tab, select the IPv4 item and click the Properties button. Enter the IP address you wish to assign to the loopback interface. Because it will be the only interface on its network, we enter '255.255.255.255' as the subnet mask.
Voila.
C:\Users\Marcks>ping 192.168.1.122
Pinging 192.168.1.122 with 32 bytes of data:
Reply from 192.168.1.122: bytes=32 time<1ms TTL=128
Reply from 192.168.1.122: bytes=32 time<1ms TTL=128
Reply from 192.168.1.122: bytes=32 time<1ms TTL=128
Reply from 192.168.1.122: bytes=32 time<1ms TTL=128
Ping statistics for 192.168.1.122:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
Run under admin command prompt:
C:\Windows\system32>netsh int ip add address "Loopback" 192.168.1.222
C:\Windows\system32>netsh int ip show addresses
接口 "Loopback Pseudo-Interface 1" 的配置
DHCP 已启用: 否
IP 地址: 192.168.1.222
子网前缀: 192.168.1.0/24 (掩码 255.255.255.0)
IP 地址: 127.0.0.1
子网前缀: 127.0.0.0/8 (掩码 255.0.0.0)
InterfaceMetric: 75
C:\Windows\system32>ping 192.168.1.222
正在 Ping 192.168.1.222 具有 32 字节的数据:
来自 192.168.1.222 的回复: 字节=32 时间<1ms TTL=128
来自 192.168.1.222 的回复: 字节=32 时间<1ms TTL=128
This should work in both Windows 7 and XP, from command window:
route ADD 192.168.1.222 MASK 255.255.255.255 127.0.0.1
If you want the new route to be persistent between reboots:
route -p ADD 192.168.1.222 MASK 255.255.255.255 127.0.0.1