2 / 37
Jun 2024

I’m unable to access the DB unless I’m SSH’d into the machine

I forgot to include the machine, I’m currently using a raspberry pi 5 on Ubuntu Server 24.04 LTS / Noble

The firewall is currently disabled as shown below. If it is enabled (which it will be but for testing/development, it’s disabled), I have allowed access to the device as shown below.

sudo ufw status Status: inactive
Status: active To Action From -- ------ ---- 27017 ALLOW PUBLIC_IP 22 ALLOW PUBLIC_IP

mongod.conf

Error

read 5 min
  • “The machine” is what, please?
  • Are you saying that if the firewall is disabled it does work?
  • Access (externally, one assumes) from where?

I’ve edited the post to include information about the machine.
Raspberry Pi 5 on Ubuntu Server 24.04 LTS / Noble

Everything is accessed interally//on the same network as the machine.

The only way I can access the DB is by creating an SSH tunnel via code, MongoDB compass, etc.

Again, just to confirm … with the firewall totally disabled, you can connect?
And when you enable the firewall, even with the port exception, you cannot connect?
Can you curl to the port when the firewall is enabled?

Well, something is blocking you. What’s the environment you’re connecting from? Corporate? Your corporate firewall could be forbidding access to “strange” ports.

It’s a home environment; it runs on the same network with 0 firewall settings anywhere.

I’m able to SSH into the Pi just fine,

user@ubuntu:~$ ss -tlnp State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 4096 0.0.0.0:27017 0.0.0.0:* LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:* LISTEN 0 4096 127.0.0.54:53 0.0.0.0:* LISTEN 0 4096 *:22 *:*
user@ubuntu:~$ ip addr list 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host noprefixroute valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 2c:cf:67:2e:a5:1e brd ff:ff:ff:ff:ff:ff inet 192.168.1.214/24 metric 100 brd 192.168.1.255 scope global dynamic eth0 valid_lft 54718sec preferred_lft 54718sec inet6 fe80::2ecf:67ff:fe2e:a51e/64 scope link valid_lft forever preferred_lft forever 3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 2c:cf:67:2e:a5:1f brd ff:ff:ff:ff:ff:ff
user@ubuntu:~$ ps -aef | grep [m]ongo mongodb 885 1 0 Jun20 ? 00:11:16 /usr/bin/mongod --config /etc/mongod.conf

How does your home environment work?
Looks like you’re using DHCP … is the DHCP server your ISP’s network device?
Have you checked the firewall settings in that device?

Yes, it is that, and there are no firewall settings configured. I’ve only done port forwarding, but that’s to my PC, and it’s a very simple/straightforward thing.

The home environment is very simple. Everything in my room uses an ethernet cable with 2 basic ethernet switches.

share the value of IP and PORT you used to get the ETIMEOUT you got in the hastebin of the original post.

share the command you use to ssh to the rpi.

I primarily use putty to SSH but if I do it through CMD I do a basic command

ssh (USER)@IP) ssh (USER)@192.168.1.214

image

nextcord.errors.ApplicationInvokeError: Command raised an exception: ServerSelectionTimeoutError: 192.168.1.214:27017: timed out (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms), Timeout: 30s, Topology Description: <TopologyDescription id: 667706b27646d3c6757e696a, topology_type: Unknown, servers: [<ServerDescription ('192.168.1.214', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('192.168.1.214:27017: timed out (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms)')>]>

You might try once connecting your PC and the MongoDB Raspberry Pi directly via an ethernet cable, assign them static addresses, leave out the entire rest of the network, and see if it works. Simple sanity check.

Current Mongosh Log ID: 66771a73a3e25718af46b798 Connecting to: mongodb://<credentials>@192.168.1.3:27017/?directConnection=true&appName=mongosh+2.2.5 MongoServerSelectionError: connect ETIMEDOUT 192.168.1.3:27017**strong text**

It’s something on the Pi for sure.

No it is not. It is something about the command you run. Your machine is

and mongosh fails with

You are trying to connect to the wrong IP.

And it works when you ssh because you ssh to the appropriate machine

I had to change the IP when attempting to connect to it directly, pi to PC, so both IPs are correct.

The reply above your was in response to the other guy

IP when using router 192.168.1.214 IP when going pi to pc 192.168.1.3

So you’re right. Assuming your mongod config is right on the Pi (it looks right) there’s some weird networking issue in the Pi software.

Right, Joe. I saw it when you first posted it. If it’s wrong about networking, I don’t see it.

Have you tried the connection with just this much of a mongdb URI?