0

I would like to duplicate port 127.0.0.1:27017 to 127.0.0.1:27018.

My initial attempts were using ip tables:

iptables -t nat -I PREROUTING -p tcp --dport 27018 -j REDIRECT --to-port 27017

(And variations of this idea). But this did not work.

mongo --host 127.0.0.1 --port 27018
MongoDB shell version: 2.6.10
connecting to: 127.0.0.1:27018/test
2019-01-12T04:04:12.403+0000 warning: Failed to connect to 127.0.0.1:27018, reason: errno:111 Connection refused
2019-01-12T04:04:12.404+0000 Error: couldn't connect to server 127.0.0.1:27018 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:148
exception: connect failed

What is the correct way of allowing one mongo instance to be accessible via 27017 and 27018.

  • What is your use case for binding mongod to multiple ports on the same network interface? – Stennie Jan 13 at 20:50
0

Packets destined for the loopback interface do not pass through the PREROUTING chain. You need to use the OUTPUT chain.

iptables -t nat -A OUTPUT -o lo -p tcp --dport 27018 -j REDIRECT --to-port 27017

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.