mongodb connection failed after assigning IP to new server

Viewed 198

We have mongodb running and everything is fine with it. I can connect to it from my kubernetes cluster and from my PC. I created new kubernetes cluster, assigned IP addresses from old cluster machines to new nodes and i'm not able to connect from those new nodes. Application and settings are the same. When i try manually connect to mongodb then:

mongo mongodb://correct-username:correct-password@correct-IP
.......
Error: Authentication failed.

When i assign those IP's back to old cluster nodes then i'm able to connect again. Only thing that has been changed is MAC address and OS. IP addresses are the same. Is there somekind of "connection cache". Differect MAC but same IP causing problems? I'm quite new with mongodb.

3 Answers

Authentication happens after a successful connection. Therefore, if you are receiving an authentication error, the connection succeeded.

Since authentication is orthogonal to IP addresses, you misconfigured something during your move.

Are you using Atlas instance or self-hosted MongoDB Server?

Maybe your current setup has IP Access List (whitelist of IP addresses) configured, and when you try to connect from somewhere which is not in that list, you will not be authenticated. You should check that, and if that is the problem, just add new IP addresses on the list.

Is this a mongodb replicaSet , standalone or sharded cluster, how rs.conf() looks like? If you configure the rs based on old ip-addresses this explain the issue... , you will need to rs.reconfig() and change to the new IPs...

Related