Search code examples
node.jsreactjsreact-nativelan

NodeJS and React - LAN connection not working


Description

I have a Node server and React App running on my notebook Ubuntu 18.04.
Notebook ip is 10.0.0.101

I tried to connect my desktop to this server on the same network
Desktop ip is 10.0.0.100

Node is running on PORT=3333
React is running on PORT=3000

I can ping my notebook from my desktop but when I try to connect to node using Insomnia or to http://10.0.0.101:3000 from my desktop I cannot reach.

Errors

When try to connect to backend with Insomnia
Error: Couldn't connect to server

When try to connect to app on 10.0.0.101:3000
ERR_CONNECTION_TIMED_OUT

What I've done

  1. I already changed the node listen and specified the port and the ip but it didn't work.
  2. I tried to use my phone as router and connect from my phone to react on my notebook and also didn't work.
  3. I've tried so many things since I can't remember them all.

I'm also creating a react-native app and when I try to connect to my mobile using Expo, it just works using tunnel, but cannot get data from the backend.

Please save me.
Thanks


Solution

  • After making many failed attempts, I realized that the problem was in my notebook. I checked my firewall and it was disabled and still cannot get acess to my notebook on LAN. But finally I discovered what have to be done

    Solution

    You have to open the specific port for TCP traffic

    Ubuntu:

    sudo ufw allow <PORT-NUMBER>/tcp
    

    or for Red Hat Enterprise

    firewall-cmd --add-port <PORT-NUMER>/tcp
    

    Reference: Examples of how to open firewall ports