Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Do we add a private IP in etc hosts or a public IP?

avatar
Expert Contributor

I have a single node cluster so far.The new host I am going to be adding is located in a different data-center than the existing host.

I see:

  1. Using a text editor, open the hosts file on every host in your cluster. For example:

    vi /etc/hosts

  2. Add a line for each host in your cluster. The line should consist of the IP address and the FQDN. For example:

    1.2.3.4 <fully.qualified.domain.name>

1.2.3.4 here is a public IP or a private IP?

The new host I am trying to add is hosted with AWS . Existing node ona dedicated server hosted with some other company.

What should I add in /etc/hosts of the

1. existing node

2. new node

AWS node (new one) has -> a public DNS, a private DNS, a public IP , a private IP. (Private DNS is the hostname).

In all your examples, you have added private IP and hostname (private DNS).

But how does adding private IP help if it's not a part of network? Please help!

5 REPLIES 5

avatar

@simran kaur

You can use both of them. Either public or private.

However, Private IP addresses are not reachable over the Internet, and can be used for communication between the instances in your VPC. Public IP addresses are reachable over the Internet, and can be used for communication between your instances and the Internet, or with other AWS services that have public endpoints.

In AWS environment you also need to Check whether your EC2 instance is inside a VPC or not. Instances inside VPC will retain their private IP addresses when stopped and restarted. But instances outside VPC (ie. EC2-Classic) will change their private IP address when stopped and restarted.

avatar
Expert Contributor

@jss: Thank you for your response. I get your point. But how does it matter if the instance is inside VPC or not. If my existing node is hosted remotely, how would it be able to interact with it using the private IP?It has a VPC ID so I suppose it is inside VPC and for as long as I am not restarting the instance, atleast until then it should be good to go. No? But my primary concern here is how does adding private IP address help at all when the server /existing node is not in the same network as the other node.

avatar
Expert Contributor

Also, to add a new host I should use Public DNS in that case (since my existing host is not hosted with AWS and so ofcourse isn't inside VPC from amazon as my new host it.

But as I see, everywhere FQDN is added in the hosts file. or is it like I add (FQDN/private DNS )with public IP in the hosts file .

Also, while searching for the host that needs to be added, it has to be Public DNS right? It wasnot able to find it if I used FQDN-which is private DNS in AWS.

avatar

All hosts in your system must be configured for DNS and Reverse DNS. If you are unable to configure DNS and Reverse DNS, you must edit the hosts file on every host in your cluster to contain the address of each of your hosts and to set the Fully Qualified Domain Name hostname of each of those hosts. You can define whatever IP address you want (public/private) the only thing you will need to make sure that those IPs are pingable/accessible from other hosts.

Also we need to Confirm that the hostname is set by running the following command:

hostname -f

This should return the <fully.qualified.domain.name> you just set.

avatar
Expert Contributor

@jss : Yes, hostname -f returns the FQDN as expected but in AWS it is the private DNS which is not pingable from outside network. Only public DNS is pingable from outside netowrk and public DNS is not the FQDN. What do you suggest in this case?