When should I configure the hosts file in system32? - hosts

When I need to access some urls, I modify the content of "hosts" file in System32.
I am confused about this.
When should I change this file? What can this file do?

I normally think about the hosts file as my local DNS.
As you know, the internet is made of computers, each having its own unique IP address. So for exmaple, in command line, if you ping google (via the command: ping www.google.com), you will get a respoinse with the ip address for google. In my case, it returned 173.194.77.99. Now, if I enter this number to the address bar of the browser and hit enter, it will take me to google.
However, memorizing those numbers is really hard, and therefore some smart people invented DNS servers (Domain Name Servers). Those are computers whose job is to map an IP address to a URL, so it is like a table that contains a lot of information about IP addresses, so there is an entry three for google for example. Now, when you type google.com in your address bar, the address is taken to the DNS server, and the corresponding IP address is returned and your browser is taken to that site.
Now, the hosts file is used for to create a similar table to contain IP/name information. I use it on my local network to give names to cumputers, so inested of saying go to computer 192.168.0.001, I would say go to computer "barcelona" or computer "toronto" depending on how I name it.
Hope this helps, cheers.

The hosts file is a computer file used in an operating system to map hostnames to IP addresses. The hosts file is a plain text file and is conventionally named hosts.
references.
http://en.wikipedia.org/wiki/Hosts_%28file%29

If your system unable to find the IP address for the host name then you can explicitly mention the ipaddress here.

This file managed to resolve domains to IP-addresses before DNS-servers were invented.
For instance: example.org --> 123.56.13.25

Related

How to set private IP address name to a generic name to show to user?

I have a rails app that is running on heroku server.
According to my knowledge, Ip addresses are managed by heroku itself but when I have scanned through Probely vulnerability scanner, it gave me Private IP addresses disclosed. Even I have not displayed my ips to any view.
Well after some analysis, I came to that point that Remote_addr: 127.0.x.x kind of ip address is showing in the rails error screen and scanner is pointing out for this.
It also suggested that to fix this issue give a generic name to the ip address so it will be displayed over there instead of its actual value.
But I don't know how to do this on my server or app. How can I give a name to my private ip address???
You can't control much on the Heroku apps.
Anyway, 127.x.x.x is localhost... regardless of what the X's are.
What is suggested is to use the etc/hosts to provide a name and don't access the host directly through IP, in case the IP changes. (not available for Heroku afaik)

Is there a difference between ftp.mysite.com and using an IP directly?

Lets say I use DNS to configure ftp.mysite.com to my site's IP, I want to give clients the credentials to use the ftp site. Can I give them the URL (ftp.mysite.com) OR should I give then the IP directly (even though the URL points to that IP).
Am I risking compatibility issues of some sort?
Do not use an IP address, always use a domain name. A domain name is less likely to change and carries more information than an IP address.
While a domain name is indeed just an alias to an IP address, a single IP address can be used for multiple domains. This is common with virtual hostings.
In this case, an IP address may not carry enough information. This more common with HTTP, where a domain name, that is otherwise lost in domain-to-IP resolution, is provided to an HTTP server using Host: HTTP header.
FTP protocol has a similar mechanics, the HOST command. But as that command was introduced relatively recently, it is actually quite rare that an FTP server relies on this. Even on shared hostings, a domain is usually included in an FTP username to allow even FTP clients, that do not (yet) support the HOST command.
See also Do the SSH or FTP protocols tell the server to which domain I am trying to connect?
there is no deference. you can give either you IP or your domain name. once people have the domain, they can get your IP very easy.
the domain can be better choice in case the IP is going to be changed.
Most FTP servers are hosted on port 21 (or 22 for SFTP).
ftp.mysite.com usually points to localhost:21 or localhost:22
So there is no difference, except for the ports.

Why IP is not pointing to Joomla main page

Given the following URL: htttp://domain/index.php, where index.php is the main webpage in a joomla server. I want to get the URL with the IP format, http://IP/index.php. I've tried that with several Joomla servers without success. What is it happening?
I will try to keep this answer simple, yet understandable.
The relation between Internet domains and IP address is not necessarily one-to-one.
In shared hosting, a single IP address may be used by several domains (or hostnames).
A Host header, which is a part of the HTTP standard, is sent with the HTTP request. This allows the server to determine which site to serve.
When you are trying to access a domain for which you don't know the IP, DNS lookup is performed, which provides the requested IP address.
A HTTP request is then sent to that IP with a Host header with the hostname (which contains the domain name).
If you are trying to access the ip directly, for example by typing in a web browser's address bar, the value of the Host header will be the IP itself and the server will have no indication what domain you actually want.
It is possible to set up a default behavior for cases where the IP address is directly accessed, but it is highly likely that a shared host will not allow you to set it yourself.

Detect which address client entered to land on a website

Since it is possible to link different domain names to the same webserver, is it possible to detect which address [can be the ip address] a client entered to access a website, so it is possible to implement conditions depending on this value?
I'm maybe totally wrong about the multiple domain names. I don't know a lot about dns and domains.
You can see it in the HTTP Host: header. For example, if you're running a PHP script, you can see it in $_SERVER['HTTP_HOST'].

How to configure http://localhost:9000 to http:/mylocal.loc

I'm using the Play Framework which uses http://localhost:9000 by default. I'm also trying something with Twitter and it needs to use a callback url for authentication, but Twitter won't accept http://localhost:9000 as a callback URL.
How can I configure my localhost to map to something like http://mylocal.loc, (similar as with an Apache vhost), instead of http://localhost:9000?
The problem is that the URL needed to be entered in the following format:
http://127.0.0.1:9000/twitter-callback
The above works perfectly as a Twitter callback address.
Twitter isn't trying to access localhost directly, it simply takes the above address as far as I understand, sticks it into the HTTP response header, prompting whichever browser being used to perform a straight forward 302 redirect.
The following blog post had some invaluable information in regards to this question:
http://www.tonyamoyal.com/2009/08/17/how-to-quickly-set-up-a-test-for-twitter-oauth-authentication-from-your-local-machine/
The reason that twitter can't use localhost as a callback url is because localhost is a redirect to your computers loopback interface. In other words, localhost is always the computer that you're on. In order for other computers (including twitter) to access your host, you need to use an external IP address, or a hostname.
To get your IP address, visit whatsmyip. This will tell you your external IP address (which other computers on the internet can access). If you have a static IP address, you can purchase a domain name, or get a free one from something like no-ip or dyndns to make it easier to remember and type. You'll need to point a DNS record from that domain to your IP. You'll also probably need to do some port forwarding and stuff to get it to go to your computer on port 9000, rather than your router (dependent on your network setup).
Possibly an easier option would be to obtain a free hosting/domain service whilst you're testing.
EDIT: josef's problem was not related to the absence of internet access to his local server, see his own answer for what was going on and a solution. This answer handles the case where a local server needs to be visible from the internet.
localhost, aka 127.0.0.1 is the name that on each computer points to the computer itself. So Twitter looks at itself, obviously doesn't see the service, end of story.
If your computer is connected to a local network, most likely that network is NATed and using private addresses like 192.168.x.x, 10.x.x.x or 172.16x.x.x. These addresses are private (not known outside of the local network because not routed on the internet), so that doesn't help you either.
What remains is your public IP address, ie the address your router gets from your ISP. Via DNS you can map that address to a name, a free service that allows you to map a fixed name also to a variable address is DynDNS.
But wait, there is more! Your router protects your network by not allowing traffic originating OUTSIDE the private network IN, unless you define some forwarding rule in the router, in your case a rule that forwards incoming tcp traffic on port 9000 to your machine's port 9000.
Once all that has been taken care of, your computer will be accessible from the outside, and your callback should work.
Edit your hosts file and add the following line:
127.0.0.1 mylocal.loc
For Windows, it is located in C:\Windows\System32\drivers\etc\. On *nix, you can find it in /etc.

Resources