1

I cannot seem to figure out why I cannot access my local django webserver from an outside device. I suspect it has to do with port forwarding but none of my attempts to solve it seem to work.

I started by following the suggestions posted here How to access the local Django webserver from outside world by launching the server using python manage.py runserver 0.0.0.0:8000 and by entering <my-ip-address>:<port> in my external device' browser. This did not work, so I tried to explicitly make sure port forwarding was enabled by adding the following lines to iptables.

iptables -A INPUT -p tcp --dport 8000 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport 8000 -m conntrack --ctstate ESTABLISHED -j ACCEPT
netfilter-persistent save

Still, I'm not able to access the local webserver. No error messages show up, the browser just tells me that the address took too long to respond. I've tried to do the above but this time with port 80 and using sudo when needed without avail. In addition I've tried to use this line ALLOWED_HOSTS = ['*'] as suggested by multiple users.

I've tried to investigate whether the application is really running on the indicated port using lsof -i which shows several PYTHON lines but I'm not sure what else I'm supposed to look for to see whether things are running correctly. Finally, I've disabled my firewall on my external device, which didn't help either.

Can anyone point me to a direction to find out what's wrong?

EDIT: to clarify, I can access the server perfectly fine from the same device where the local server is running.

pepeisadog
  • 11
  • 3
  • is `outside device` in the same local network (`LAN`)? Devices from internet may not access because access can be blocked by Internet Provider Routers which you can't reconfigure. – furas Dec 06 '21 at 14:53
  • maybe problem is not forwarding but some bug in code. – furas Dec 06 '21 at 14:53
  • first you should check if you can access from the same computer on which you run it. – furas Dec 06 '21 at 14:54
  • @furas, yes I should have made that clear in the original post that I can access it perfectly fine from the same computer on which the local server is running. The outside device is on a different network. – pepeisadog Dec 06 '21 at 15:01
  • if device is on different network then problem can be not your computer but router between your network and another network. Usually they are configured to block access to local servers for your security - to stop hackers to use bugs in servers to access your computer. And you don't have acccess to this router so you can't change it. You may eventually try [ngrok](https://ngrok.com/) – furas Dec 06 '21 at 15:09
  • Ok thanks for suggesting ngrok, I'll look into that. – pepeisadog Dec 06 '21 at 15:34

0 Answers0