/etc/hosts doesn't work for localhost only - windows

What I need:
Localhost points to the IP of my other PC on the local network.
What I tried:
I added "IP localhost" to the /etc/hosts file.
Command ran: "ipconfig /flushdns"
Browser: Edge/Chrome/Internet Explorer
This doesn't work, but if I name it anything else than "localhost" it does actually work.
I know it is something about the DNS, but I read online that the hosts file should overwrite it.
Partly solution
Google OAuth only accepts localhost or example.com as redirect URL. Not being able to use localhost on a different PC for testing, I solved this by using example.com on both the local PC and the second PC. I added the following to the hosts file:
Local PC: 127.0.0.1 example.com
Second PC: IP_OF_LOCALPC example.com
You can then use URL example.com:PORT. This isn't supported by Microsoft OAuth though (I guess I will only use Google Login for developing). Any ideas on how to solve this for Microsoft OAuth are welcome :)

Are you using Chrome?
Chrome has it's own DNS, if you use another browser then it's likely it will work as you expect.
Edit: Confirmed that this is still possible in Safari today on a Mac (26/12/2021). However, browsers appear to be clamping down on this - and are making an effort to make sure that localhost and *.localhost will only ever point to your local machine.

Related

how to change xampp localhost to another domain on mac

I searched a lot but there is no answer for how to change xampp localhost domain to another domain on mac..I've done it in windows before and it was easy but on mac not at all.
this how I try to do it:picture of hosts file
and then I changed vhosts.conf by adding new domain's details too:picture of vhosts.conf
If you did it by the hosts file in windows you can edit /etc/hosts on mac. Add a line with the code 127.0.0.1 mydomain.com. After that restart your mac and try to connect to mydomain.com. It might not work on some browsers, because they have an option named DNS over HTTPS. On firefox you can disable it by going to Menu->Options->General->Network Settings->Settings and disabling it.

/etc/hosts file not redirecting to local application on mac

I've set up a redirect in the hosts file on my machine that basically points an auth domain to my local project in IIS (when run in Visual Studio for Mac) - however when I type the domain name into Chrome (for example), I get a message saying this site cannot be reached.
The local URL I want this to point to is: http://localhost:44380/ - the live URL I can't reveal for security but lets say for the sake of this example that it's: auth.site.com (the actual URL I'm using is valid and it does load in Chrome)
Here's my hosts file from terminal as it's currently set up:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 auth.site.com
I'm very familiar with windows and how the hosts file works, so from what I know there this would work in windows (I think anyways), is there something I'm missing here because obviously something isn't right?
I would first check where the problem is exactly. I think of the following possible issues:
Hosts file not properly working: Try running ping auth.site.com in a terminal. If you see responses from 127.0.0.1 this should work.
Is access to the port possible, open http://localhost:44380 in your browser. If you see your page, this should work.
Combine the two parts: open http://auth.site.com:44380 in your browser. If this does not work, maybe there are security features from the original page you visited before preventing access (like forcing SSL or a pinned certificate).
Try another browser or curl auth.site.com:44380 in a terminal.
If you are not happy with the given ports, you can do a port forwarding. Changing ports is not possible in the hosts file, because the hosts file is only for domain name lookup and this has nothing to do with the ports.
The listening address on the local instance would be http://auth.site.com:44380/

Can't access 127.0.0.1

I can't figure out when this started to happen, but the result is - 127.0.0.1 is not working on any port from anywhere (for example, browser says Unable to connect). Here are the results of my research:
localhost, COMPUTER_NAME and actual IP address all work fine
there is nothing special in my hosts file
ping to 127.0.0.1 and tracert do work fine
all the programs that have 127.0.0.1 hardcoded are not working (this point makes me disappointed the most, because I can't do anything in this case )
What else can I do to identify the source of problem and fix it?
UPDATE: as soon as Redis does work on 127.0.0.1 and both IIS and AzureStorageEmulator don't work I assume this is HTTP only issue.
Just one command did the work
netsh http add iplisten 127.0.0.1
If it's a DNS problem, you could try:
ipconfig /flushdns
ipconfig /registerdns
If this doesn't fix it, you could try editing the hosts file located here:
C:\Windows\System32\drivers\etc\hosts
And ensure that this line (and no other line referencing localhost) is in there:
127.0.0.1 localhost
In windows first check under services if world wide web publishing services is running. If not start it.
If you cannot find it switch on IIS features of windows: In 7,8,10
it is under control panel , "turn windows features on or off".
Internet Information Services
World Wide web services and
Internet information Services Hostable Core are required.
Not sure if there is another way to get it going on windows, but this worked for me for all browsers.
You might need to add localhost or http:/127.0.0.1 to the trusted websites also under IE settings.
I had a similar issue. Check your listen port.
A mistake I made ealier was
app.listen(() => console.log(APP_NAME} is listening on port ${PORT}`))
Make sure you include the port as shown below
app.listen(PORT, () =>{
console.log(`${APP_NAME} is listening on port ${PORT}`)
})
This answer may seem overly obvious, but in most cases it is sufficient to simply remove the "localhost" entry in the "Host Name" field:
In the end for us, it was IE11 that was blocking for 127.0.0.1 - after adding it to the exceptions list, it loaded the page.

Can't browse local domains without a network connection

I have a few different PHP sites running on local domains (i.e. domains set to 127.0.0.1 in /etc/hosts) so I can work on them without any network delay.
I'd like to be able to work on these sites when I have no connection at all (e.g. on the bus or in the park) but my browser (Firefox on LinuxMint) can't load the local pages when there's no network connection (it doesn't have to have Internet access, but it must have a working network connection). Note that it can load a site via local IP addresses or "localhost", but not using any other local domain name.
I'd like to create some kind of local network that makes the Network Manager show a valid connection even when there is no LAN adapter present. Or alternatively a way to make Firefox work with the local domains without needing the network would be just as good.
Reproduce this problem as follows:
- Run a local web-server such as micro_httpd and serve a test site
- Set up some other names for 127.0.0.1 in addition to localhost in your /etc/hosts file such as foo.bar
- Test that your site works from localhost and from foo.bar
- Unplug your network cable
- Test again, only localhost works, not foo.bar
- Test with wget, both work fine
I have the same issue. Either of these work for me, in Firefox go to about:config and click I'll be careful, I promise!, search for network.dns then either:
Set network.dns.disableIPv6 to false
or
Add your local domain names to network.dns.localDomains
I think the latter is probably the better of the two options, but either works for me.
Adding a little to Lee Kowalkowski answer:
I have modified below at admin:config in my firefox developer edition 61.0b3 (64-bit)
network.dns.localDomains added localhost as I bind my local sites with localhost
I haven't needed this functionality for a couple years and noticed now as of Firefox 60 that there is no problem any more.
This old Bugzilla thread mentions the issue and says it was resolved by adding the about:config key network.dns.offline-localhost, perhaps that's set to true by default now which is why it works?

Can't access my index.html (via Apache) from other computer (LAN nor Internet)? Please help

lets make it simple to answer.
I installed Apache 2.2. Now when I do 127.0.0.1 in Firefox, I get the "It works" page. When I do 10.0.1.10 (my servers internal IP) on another PC on the SAME network, I won't get anything :-(. I forwarded port 80 on my router and made sure Firewall doesn't block Apache. If I type my external IP:80 I still can't get into my "index.html". My settings (more less default)
Network Domain: localhost
Server Name: localhost
I also got a FTP via FileZilla running on that PC. It works perfectly, even over Internet. I have also set up a DynDns hostname. If I do ftp://mydyndns.hostname.com I get to my ftp server.
What am I missing? Some more Windows setup?
Thanks a lot in advance!
I installed Linux on my computer and found all servers run better on it :) Thanks everyone...

Resources