LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   General (http://www.linuxquestions.org/questions/general-10/)
-   -   Some theoretical questions (LAN). (http://www.linuxquestions.org/questions/general-10/some-theoretical-questions-lan-4175450204/)

stf92 02-14-2013 09:29 PM

Some theoretical questions (LAN).
 
Hi:

A number such as 192.168.1.2 if somehow mapped to a hardware address such as 34:4f:45:9c. It is also mapped to some hostname. Question: how do I know, given the IP, which the hostname is? Or the other way around: given the hostname find the IP?

leehanken 02-14-2013 09:50 PM

Quote:

Originally Posted by stf92 (Post 4891945)
Hi:

A number such as 192.168.1.2 if somehow mapped to a hardware address such as 34:4f:45:9c. It is also mapped to some hostname. Question: how do I know, given the IP, which the hostname is? Or the other way around: given the hostname find the IP?

The hardware address, also known as MAC address has six bytes. (your example only shows 4 bytes) This is not really related to your question.

Mapping between hostname and IP address happens through DNS (Domain Name System), basically a hierarchical table accessed by connecting to remote name servers. Hostnames and their corresponding addresses can also be stored in a local file called 'hosts'. In practice you can type: nslookup hostname.com OR nslookup 100.100.100.100 to try to discover this information.

The 'hosts' method is more likely for local IP addresses like 192.168.1.2, where as the DNS (accessed via a TCP/IP connection on port 53) will more likely for remote IP addresses like 100.100.100.100. Finding IP address from the host/domain name is known as a DNS lookup operation, whereas finding a hostname/domain from IP address is called a reverse DNS lookup.

stf92 02-14-2013 10:28 PM

Thank you very much. I ask because in /etc/rc.d/inet1.conf I put:

IPADDR[0]="192.168.0.2"

However, in /etc/hosts I only have
Code:

# For loopbacking.
127.0.0.1                localhost
127.0.0.1                darkstar.domain_name_2 darkstar

# End of hosts.

Is not 192.168.0.2 a local IP address?

leehanken 02-14-2013 11:38 PM

In inet1.conf you are setting a static IP address for your computer.

In hosts you are naming your computer darkstar.

The address 127.0.0.1 is another way of saying 'the address of my computer as seen by itself'.

In fact you could address your computer as 192.168.0.2 or as 127.0.0.1 from itself. However, from another computer on the network, it has to be addressed as 192.168.0.2.

Thanks to hosts, your computer knows its own name. However, none of the other computers on the network will know its name, unless you put a line in their hosts file saying

Code:

192.168.0.2    darkstar
So yes, 192.168.0.2 is a local address in that it is relevant only to the local area network (LAN). It does not apply if you are outside the LAN. So from another person somewhere else on the internet it will not reach your computer.

I am simplifying a bit, for more information you could try http://en.wikipedia.org/wiki/Internet_protocol_address

stf92 02-15-2013 12:18 AM

However I myself, computer 192.168.0.2 can't see the IP<->hostname association from computer 192.168.0.2.

chrism01 02-15-2013 12:55 AM

1. I don't understand your last comment

2. each entry in /etc/hosts should have a unique ipaddr at the left hand side, and then 1 or more names/aliases on the same line, so combine those 127.0.0.1 records.

3. 127.0.0.1 is how the computer talks to itself. Its the same (internal) address on every computer and usually the basic entry is
Code:

127.0.0.1  localhost localhost.localdomain
4. 192.168.0.2 is the ipaddr of the machine from the external/LAN point of view
If you have an entry for it in the /etc/hosts file, it will recognise itself.

stf92 02-15-2013 01:07 AM

Alright. Now, has it any sense to issue, from machine A,

Code:

 
# ifconfig eth0 192.168.1.1 netmask 255.255.255.0
# route add default gw 192.168.1.1

and then to add this line to /etc/rc.d/rc.local?:

/sbin/ifconfig eth0:0 192.168.0.1 netmask 255.255.255.0

leehanken 02-15-2013 02:44 PM

Hi stf92

This first line sets the computer's address to be 192.168.1.1:

Code:

# ifconfig eth0 192.168.1.1 netmask 255.255.255.0
The next line sets which computer/router will be contacted first for communicating to other computers:

Code:

# route add default gw 192.168.1.1
It does not make sense for the two addresses to be the same, because the computer will only be able to talk to itself.

Putting the following line in rc.local will set the IP address to 192.168.0.1 when the computer is booted:

Code:

/sbin/ifconfig eth0:0 192.168.0.1 netmask 255.255.255.0
Typically this is not needed because it is usually handled by rc.inet1

Regards Lee

johnsfine 02-15-2013 02:59 PM

I think /etc/hosts is only for name to IP associations that you don't want to look up in the next higher level of DNS.

I assume you have some kind of home router which is acting as a DHCP server (associating those 192.168.???.??? addresses to Mac addresses) and a DNS server (keeping track of local machine names and caching results from a distant DNS server for names on the rest of the net) and doing address translation (between the real IP address assigned by your internet provider to your home network and all the 192.168 addresses that same router invents for that network).

Linux can do and/or override any of the above tasks. But you probably don't want it to. You probably want Linux to look to the home router for all of that.

stf92 02-15-2013 04:03 PM

Thanks. Definitely what I now have is a modem provided by my ISP (DHCP), a router with a WAN port and several LAN ports and computers A and B. And all I want to do is to interconnect A, B and the router (router goes to the WAN of course). That is, what everybody has at home: two computers connected to Internet (only one IP) and with each other. I know the job is very easy but not how to do it, though I have learned some of the jargon (reading The Linux Network Administrator's Guide from TLDP). If I boot in Windows at least I'll be able to see it works, but the ideal would be to make it work with Linux.

jefro 02-15-2013 08:54 PM

The name localhost is a very old way and is still used.

stf92 02-15-2013 09:04 PM

Quote:

Originally Posted by jefro (Post 4892701)
The name localhost is a very old way and is still used.

You mean 'rlogin darkstart@127.0.0.1? But I would be loging into myself?


All times are GMT -5. The time now is 12:03 PM.