While reading about Linux I got:
You can view your system’s hostname simply by typing hostname with no argument.
anupam@JAZZ:~$ hostname
JAZZthen I found this:
The special
hostnamelocalhostis associated with the IP address127.0.0.1, and describes the machine you are currently on (which normally has additional network-related IP addresses).
and I tried :
anupam@JAZZ:~$ cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 JAZZ
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allroutersI am confused here hostname gives JAZZ but IP associated with JAZZ is 127.0.1.1 not 127.0.0.1 .which is not as per the second part of description.
Another query: Can I use my dynamic IP (as configured by DHCP in my wifi connection) as a localhost to host my html or php files?
I guess localhost and hostname signifies the same here.and localhost is also known as loopback address, which corresponds to 127.0.0.1 isn't it??
1 Answer
You've asked two questions, so I have to split them up.
Firstly, about the first two lines in your /etc/hosts
There's a few parts we have to consider here. First, localhost and JAZZ are both on local loopback addresses. 127.0.0.1 and 127.0.1.1 respectively.
The 'loopback' range of IP addresses is 127.0.0.0 - 127.255.255.255. All of those are considered "local loopback", and any of those addresses is technically considered 'local'. It does not hurt, however, to put localhost on 127.0.0.1, and $HOSTNAME on its own, 127.0.1.1, or some other address within that namespace.
Considering that 127.0.0.1 - 127.255.255.255 is all considered local loopback, it doesn't really matter which address gets assigned locally within that namespace when referring to your own hostname. (Having said this, it is customary in your /etc/hosts to have localhost as 127.0.0.1, as that is typically how the system handles it. You can put it, theoretically, onto anything, but 127.0.0.1 is the default and is typically what its on.)
As well, your source quotes the following:
The special hostname
localhostis associated with the IP address 127.0.0.1, and describes the machine you are currently on (which normally has additional network-related IP addresses).
It's specifically referring to localhost, and not the hostname for your machine.
Your second one is about your dynamic IP.
That should be in its own question, but I think we need to redefine what you're asking. You ask this:
Another query: Can I use my dynamic IP (as configured by DHCP in my wifi connection) as a localhost to host my html or php files?
Lets change this to ask this:
Can I use my dynamic IP assigned by my wireless router with other systems to host my HTML or PHP files?
I redefine your question like this because you can't use localhost outside of your computer. 127.0.0.1 - 127.255.255.255 only work on that one computer. If you're asking to use your dynamic 192.168.x.x (or whatever private IP range is configured on your wifi) address for your files, you'd be referring to your computer with that IP instead of localhost, elsewhere on your network.
To that end, either your router needs to be able to resolve HOSTNAME queries from other systems and point to the private internal DHCP address, or each other system needs to have their hosts file edited to point hostname to the DHCP address.
Now, if you want to host files OUTSIDE your network, you're going to need two things: (1) Dynamic DNS address from some dynamic DNS provider. (2) port forwarding from your router to your internal computer address. (There's other questions and answers for doing this one, though, hence why i'm not going into detail here)
1