I have a mongod daemon running on one machine.
I can confirm it, by running these two commands:
$ ps -ef | grep mongod
ubuntu 4908 1 5 07:44 ? 00:00:03 mongod --tlsMode requireTLS --tlsCertificateKeyFile Server2.cert --tlsCAFile RootCA.pem --auth --dbpath /mnt/mongoDB-One/DB_X509 --logpath /mnt/mongoDB-One/DB_X509/mongod.log --fork --bind_ip 192.168.1.2
ubuntu 4951 3223 0 07:45 pts/0 00:00:00 grep --color=auto mongod
$
$ sudo netstat -tulpn | grep mongod
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 4612/mongod
$
While being on the same machine I can launch mongo shell, using one of these two commands:
$ mongo --tls --host localhost --tlsCertificateKeyFile Client.cert --tlsCAFile RootCA.pem
$ mongo --tls --host 127.0.0.1 --tlsCertificateKeyFile Client.cert --tlsCAFile RootCA.pem
But from a different machine, the following is not working:
$ mongo --tls --host 192.168.1.2 --tlsCertificateKeyFile Client.cert --tlsCAFile RootCA.pem --authenticationDatabase '$external' --authenticationMechanism MONGODB-X509
MongoDB shell version v4.2.0
connecting to: mongodb://192.168.1.2:27017/?authMechanism=MONGODB-X509&authSource=%24external&compressors=disabled&gssapiServiceName=mongodb
2021-01-21T16:26:42.690+0900 E QUERY [js] Error: couldn't connect to server 192.168.1.2:27017, connection attempt failed: SocketException: Error connecting to 192.168.1.2:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:341:17
@(connect):3:6
2021-01-21T16:26:42.693+0900 F - [main] exception: connect failed
2021-01-21T16:26:42.693+0900 E - [main] exiting with code 1
$
Why could that be?
Some more information which may be useful:
The server certificate has been created using these 2 commands.
$ openssl req -new -newkey rsa:4096 -nodes -keyout Server.key.pem -out Server.req.pem -subj /C=US/ST=CA/O=ServerCA/CN=localhost
$ openssl x509 -req -days 365 -in Server.req.pem -CA IntermedCA.pem -CAkey IntermedCA.key.pem -set_serial 01 -out Server.pem -extfile X509_v3.ext
With X509_v3.ext being :
$ cat X509_v3.ext
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost
IP.1 = 127.0.0.1
IP.2 = 192.168.1.2
$