Create an alias for a website with /etc/hosts - windows

At work we have a series of aliases for websites like repositories etc. and they are used by typing something like open/repo in the browser.
I wanted to create something like this at my private PC and found out I could add a line to /etc/hosts file and it looks like this:
172.217.16.46 gl
Now what I would expect is to type gl in any browser and it would redirect me to google.com, but unfortunately I get 404 errors on every browser. The only answers I found were browser specific, like this one for Chrome, where other browsers actually work as expected.
What I tried:
I've run ipconfig /flushdns in cmd (on admin rights)
I put http:// before the alias in Chrome
Note:
I would like to keep all the changes locally on my machine (without changing router configuration etc.)

If you are getting a 404 error, the problem is probably not that DNS resolution is failing but that your address is wrong. It sounds like you have tried to point gl to Google's IP. That would cause your request to hit Google's server, but Google will probably reject it since it is labeled addressed to gl instead of google.com in the HTTP request.
This phenomenon happens because it is common for web servers to host different websites on the same IP only with different domain names. I believe the term for these is "virtual host".
At any rate, try pointing to an IP that takes any name to access the website, or otherwise you are probably looking for some kind of redirect instead of A record DNS.

Related

Unable to set up custom domain on Heroku using Google Domains DNS?

To preface this, I am new to backend web development so I'm coming at this totally clueless. My past experience is with Netlify, which makes it pretty seamless to add a custom domain to a website with their free DNS service.
To start, I am working on a Flask application that ideally I would like to put on a subdomain of my website (i.e. app.my-website.whatever, not actually my real domain since it includes my real name) on a different host, in this case Heroku, while keeping my main website (www.my-website.whatever) on Netlify. This required me to switch from using Netlify's DNS to using the DNS tools provided by Google Domains.
After deploying the app on the free domain, which went just fine, I tried setting up my domain for the website, following these steps:
On my website's dashboard, I went to Settings > Domains > Add domain and under domain entered app.my-website.whatever, including the subdomain of course.
Copied the DNS Target Heroku gave me.
At my dashboard for my-website.whatever at domains.google.com, under DNS > Default name servers > Resource records, I added a custom record with the hostname app.my-website.whatever (Google Domains automatically adds the .my-website.whatever), type CNAME, TTL 600, and in the Data field I pasted the DNS Target.
In my Ubuntu (WSL) terminal, when I type host app.my-website.whatever, the output says app.my-website.whatever is an alias for {bunch-of-random-characters}.herokudns.com.
Unfortunately, this has not been successful. When I try to visit the domain, I usually get an error such as DNS_PROBE_FINISHED_NXDOMAIN or alternatively ERR_SSL_UNRECOGNIZED_NAME_ALERT. I've also tried the same thing with just www.my-website.whatever, and the same issues occur.
When I try to visit the site, most browsers will automatically append https://, which I would assume doesn't quite work since I do not have a cert set-up for my site, which I need to do manually.
Does the above error mean that there is a problem related to SSL, or is it something else? Is it because my browser forces https:// that I cannot see anything changing (i.e. would http:// work?)?
From what I can tell, I should be able to do all of this on the free-tire, but I have some confusion about a few details, and feel like I could be missing some other things:
Do I need a certificate/SSL for my custom domain to work at all with Heroku?
If it could possibly be an easier solution: Is there a better alternative to Heroku in my case?
With regards to setting up the cert, I tried following the tutorial here:
https://medium.com/#bantic/free-tls-with-letsencrypt-and-heroku-in-5-minutes-807361cca5d3
For certbot, as the tutorial explains, you are given two strings like so: <long-string>.<other-long-string>, and you need to serve a file at /.well-known/acme-challenge/ with the name <long-string> (no extension), but as an unrelated issue, I cannot get Flask to serve this file, even on a local dev server, and I just get a 404 message, which the certbot utility also reports. I can create another file, such as a simple .txt file, in that same directory, and it will serve just fine.
I'll admit, these issues feel a bit basic, but I genuinely am lost, and none of the guides or posts I see online seem to have any remedy or explanation for what is happening here.
If there is any more information I should share, please let me know.

I can access my heroku free subdomain site via a browser, but I can't ping to it in the terminal

I have this site at heroku that I am trying to ping. It says
Ping request could not find host https://doc-hero.herokuapp.com/. Please check the name and try again.
even though I can still open the site on a browser. I thought it was an issue with heroku so I hosted it again on pythonanywhere but it still won't ping.
I'm sure there is a simple explanation for this but I tried Google and still no luck.
Is there a way I can get it to ping?
You might be wondering why I want it to do that when I can still browse to it. Well, it's because I need it to be visible to Open AI so that it can access some documents over there.
remove https:// prefix. ping is a different protocol and requires DNS only not protocol prefix.
heroku server still will probably not answer ping request as it is not required to.

When debugging at a remote location, how do we use hosts file to do that?

If I use foo.my-company.com at work, then all works well, but if we fix any bug remotely, then the web server will respond with a forbidden.
I heard we can use dev1-foo.my-company.com at a remote location, and it is the same site, but if I access that, I found that all the AJAX are still done to foo.my-company.com and it won't work because it is still forbidden. It seems that "hosts file" can be used to overcome this, but how specifically?
All a hosts file can do is associate a hostname (like dev1-foo.my-company.com) to an IP address (like 10.1.1.5).
This can be enormously useful if:
Your DNS doesn't have an entry for the host you need (e.g. "dev1")
... or ..
You want to override DNS (substitute your own "dev1", e.g. for testing)
This is all TCP/IP - it has nothing directly to do with higher-level protocols like HTTP or AJAX.
'Hope that helps ..

I need a browser-compatible proxy that can do this

I am looking for a proxy server that can do this.
If I set my firefox settings to that proxy, and go to google, then it should "proxy" to google normally. Just a normal proxy.
But I want there to be rules. I want to redirect anything that matches http://google.com/... to http://12.34.56.78/...
I was thinking about writing one but to be honest there has to be something to do this already built.
Fiddler should do what you want. If you type into the black box at the bottom "overridehost google.com 12.34.56.78" it should redirect any Google requests to the specified IP.
Not a proxy per se, but what about editing your local host file? If you are a Windows user just go to "C:\WINDOWS\system32\drivers\etc" and edit the "hosts" file accordingly. Eg. add a new line:
12.34.56.78 google.com
I know the use is limited, because you cannot make more complex redirects. However it might be sufficient for your problem. Good luck! (on linux/unix the file is often located in /etc/hosts).
If you want a better solution, it would be helpful to give us your OS.

Switch firefox to use a different DNS than what is in the windows.host file

For example, I have a development site on a different server but I'm trying to copy content over from the live site so it'd be handy to have the live site in IE and the dev site in FF.
I tried FoxyProxy but I can't seem to get it to work.
I use this to override system's DNS with localserver
in about:config
change this value:
network.dns.forceResolve
network.dns.ipv4OnlyDomains
network.dns.localDomains
with IP address of local DNS server (for exsample 192.168.1.88)
Sorry for my english
It's now possible, with the DNS over HTTPS function:
Open Options, General, scroll to very bottom and open Network Settings,
On the very bottom, you can find DNS over HTTPS:
You had to use about:config before to change this setting, here's for documentation:
Type about:config in firefox address bar.
search for:
network.trr.uri
You can use one of the DNS servers below:
Cloudflare: https://cloudflare-dns.com/dns-query
Google: https://dns.google/dns-query
Secure DNS EU: https://doh.securedns.eu/dns-query
Quad 9: https://dns.quad9.net/dns-query
And set network.trr.mode to 1
Hijacked from here:
https://www.ghacks.net/2018/04/02/configure-dns-over-https-in-firefox/
It appears from your question that you already have a second set of DNS servers available that reference the development site instead of the live site.
I would suggest that you simply run a standard SOCKS proxy either on that DNS server system or on a low-end spare system and have that system configured to use the development DNS server. You can then tell Firefox to use that proxy instead of downloading pages directly.
Doing it this way, the actual DNS lookups will be done on the proxy machine and not on the machine that's running the web browser.
DNS resolving is usually done at the system level and not at the application level, so you can't normally have one program use one dns and another program use a different dns. I'm not aware of any firefox extensions that allow you to use a different dns.
What about having different names for your dev and prod servers? That should avoid any confusions and you'd not have to edit the hosts file every time.
I am using the SwitchHost extension exactly for this problem:
https://addons.mozilla.org/en-US/firefox/addon/14258
It is easy to configure, and even more easy to switch hosts.
I wonder if you could write a custom rule for Fiddler to do what you want? IE uses no proxy, Firefox points to Fiddler, Fiddler uses custom rule to direct requests to the dev server...
http://www.fiddlertool.com/fiddler/
Since http proxy protocol is similar to raw http protocol, you can redirect desired traffic to your development server by telling firefox it's a proxy server.
two limitations:
A. this won't let you use https connections.
B. some frameworks (e,g: wordpress) don't like this method and redirect the request the wrong way
just copy the following code into a .pac file (enter your site domain and IP address, of course), and switch development/production just by changing proxy configuration.
function FindProxyForURL(url, host) {
var prox4site = {
"mysite.com":"PROXY 10.0.1.100:80",
"www.mysite.com":"PROXY 10.0.1.100:80"
}
return prox4site[host] || "DIRECT";
}
Go to options->Advanced->Network->Settings->Automatic proxy configuration url and enter 8.8.8.8 All you Mozilla traffic uses Google dns now.

Resources