Redirecting an external IP address to localhost is a common requirement for developers working with:
- Local API testing
- Mocking external services
- Debugging network applications
- Blocking unwanted connections
For simple cases, you can modify the hosts file (requires admin privileges):
# Path: C:\Windows\System32\drivers\etc\hosts
127.0.0.1 146.112.61.106
For more control over specific ports, use Windows' netsh command:
netsh interface portproxy add v4tov4 listenaddress=146.112.61.106 listenport=80 connectaddress=127.0.0.1 connectport=80
To check active port proxies:
netsh interface portproxy show all
Ensure Windows Firewall allows the connection:
netsh advfirewall firewall add rule name="IP Redirect" dir=in action=allow protocol=TCP localport=80
To remove the proxy when done:
netsh interface portproxy delete v4tov4 listenaddress=146.112.61.106 listenport=80
For scripted solutions, PowerShell offers more flexibility:
Add-NetNatStaticMapping -NatName "LocalRedirect" -Protocol TCP -ExternalIPAddress 146.112.61.106 -InternalIPAddress 127.0.0.1 -ExternalPort 80 -InternalPort 80
Remember that these changes affect only your local machine and don't modify actual network routing.
Redirecting an external IP address (like 146.112.61.106) to localhost (127.0.0.1) is a common requirement for developers testing applications, debugging network issues, or creating isolated testing environments. Windows provides several methods to achieve this, with netsh
being the most native and powerful tool.
The most reliable way is to create a port proxy using netsh:
netsh interface portproxy add v4tov4 listenaddress=146.112.61.106 listenport=80 connectaddress=127.0.0.1 connectport=80
This command forwards all traffic coming to 146.112.61.106 on port 80 to your local machine. You'll need to:
- Run Command Prompt as Administrator
- Specify both listen and connect ports (use the same if redirecting same service)
- Ensure the IP isn't already in use
Check if the rule was created successfully:
netsh interface portproxy show all
Sample output should show your mapping:
Listen on ipv4: Connect to ipv4:
Address Port Address Port
146.112.61.106 80 127.0.0.1 80
If netsh doesn't work for your scenario, consider these alternatives:
Hosts File Modification
Edit C:\Windows\System32\drivers\etc\hosts
(as Administrator):
127.0.0.1 146.112.61.106
PowerShell Script
For dynamic scenarios, use this PowerShell script:
New-NetFirewallRule -DisplayName "IP Redirection" -Direction Inbound -LocalAddress 146.112.61.106 -Action Allow
Add-NetRoute -InterfaceAlias "Ethernet" -DestinationPrefix 146.112.61.106/32 -NextHop 127.0.0.1
- Administrator privileges are required for all methods
- Windows Firewall may block redirected traffic
- DNS caching might require
ipconfig /flushdns
- For system-wide changes, reboot may be necessary
If redirection fails:
1. Verify IP isn't being used: ping 146.112.61.106
2. Check port availability: netstat -ano | findstr :80
3. Review Windows Firewall rules
4. For netsh issues, reset with:
netsh interface portproxy reset