Reputation: 1226
I am having two linux devices dev1 and dev2. my dev1 ip is 192.168.1.1, dev2 ip is 192.168.1.2,
both are in the same network.
when ping 192.168.1.1 from dev2 to dev1, i am able to ping.
when i have added /etc/hosts with "192.168.1.1 dev1" on dev1, and tried to ping dev1 from dev2 using
$pin dev1
I got unknown hostname
when i have added /etc/hosts with "192.168.1.1 dev1" on dev2, and tried to ping dev1 from dev2 using
$pin dev1
it is working, but this is not what we are expecting. Without any change from dev2,
we want to ping dev1.
In between any DNS server should be configured ? Please help us .
Upvotes: 0
Views: 382
Reputation: 442
In your case,
when i have added /etc/hosts with "192.168.1.1 dev1" on dev1, and tried to ping dev1 from dev2 using
$ping dev1
I got unknown hostname
You added entry in dev1 machine and trying to ping from Dev2, Dev2 does not have /etc/hosts entry for Dev1
Hence you are getting Unknown hostname
Next:
when i have added /etc/hosts with "192.168.1.1 dev1" on dev2, and tried to ping dev1 from dev2 using
$ping dev1
Yes this work, because you have added your dev1 entry in dev2 /etc/hosts file, now your dev2 machine able to resolve ip address of dev1 from /etc/hosts file.
If you want resolve IP address without adding entries in /ect/hosts file, then you need to set up dns server, make dev1 and dev2 as dns clients, then you can able to ping with hosts names
Without DNS setup, you have to add /etc/hosts entries in both dev1 and dev2 Machines like below
Example in Dev1 machine add below entries in /etc/hosts file:
192.168.1.1 dev1 # Dev1 IP address
192.168.1.2 dev2 # Dev2 IP address
Example in Dev2 machine add below entries in /etc/hosts file:
192.168.1.1 dev1 # Dev1 IP address
192.168.1.2 dev2 # Dev2 IP address
Upvotes: 1