Virginia Beach Finance

Aug 11 2017

Using port number in Windows host file – Stack Overflow #host #entry #in #windows


#

The hosts file is for host name resolution only (on Windows as well as on Unix-like systems). You cannot put port numbers in there, and there is no way to do what you want with generic OS-level configuration – the browser is what selects the port to choose.

So use bookmarks or something like that.
(Some firewall/routing software might allow outbound port redirection, but that doesn’t really sound like an appealing option for this.)

answered Dec 28 ’11 at 7:15

I managed to achieve this by using Windows included Networking tool netsh.

As Mat points out. The hosts file is for host name resolution only, so a combination of the two did the trick for me.

Example

Overview

Actions

  • Started my server on localhost:8081
  • Added my “local DNS” in the hosts file as a new line
    • 127.65.43.21 example.app
      • Any free address in the network 127.0.0.0/8 can be used.
      • Note: I am assuming 127.65.43.21:80 is not occupied by another service.
      • You can check with netstat -a -n -p TCP | grep “LISTENING”
  • added the following network configuration with netsh command utility
    • netsh interface portproxy add v4tov4 listenport=80 listenaddress=127.65.43.21 connectport=8081 connectaddress=127.0.0.1
  • I can now access the server at http://example.app

Notes:
– These commands/file modifications need to be executed with Admin rights

– netsh portproxy needs ipv6 libraries even only to use v4tov4, typically they will also be included by default, otherwise install them using the following command: netsh interface ipv6 install

You can see the entry you have added with the command:

netsh interface portproxy show v4tov4

You can remove the entry with the following command:

netsh interface portproxy delete v4tov4 listenport=80 listenaddress=127.65.43.21

Links to Resources:

If what is happening is that you have another server running on localhost and you want to give this new server a different local hostname like http://teamviewer/

I think that what you are actually looking for is Virtual Hosts functionality. I use Apache so I do not know how other web daemons support this. Maybe it is called Alias. Here is the Apache documentation:

answered Jul 29 ’15 at 20:17

I modified the %windows/systems32/drivers/etc/hosts file as below

then I am able to access the local url without fiddler by typing

answered Jul 6 at 18:21

All this did is create another localhost alias called 1234. Port numbers have no place in a hosts file. EJP 23 hours ago

Your Answer

2017 Stack Exchange, Inc


Written by admin


Leave a Reply

Your email address will not be published. Required fields are marked *