Qixin
Qixin

Reputation: 41

Django project cannot be accessed using IPV6 address

I am running my Django project on a ubuntu server. I have changed the allowed host in settings.py

ALLOWED_HOSTS = ['my_IPV4', 'my_IPV6', 'localhost']

I allowed access to port 8000 by sudo ufw allow 8000.

I run the server by python manage.py runserver 0.0.0.0:8000 however I can only access the IPV4 address but the IPV6 address on port 8000 is not reachable. My IPV6 address is active but port 8000 seems not working. Did I miss something on configuring IPV6?

Upvotes: 3

Views: 3031

Answers (2)

rs_punia
rs_punia

Reputation: 449

The argument --ipv6, -6 uses IPv6 for the development server. This changes the default IP address from 127.0.0.1 to ::1.

Run Port 8000 on the IPv6 address of the host localhost:

django-admin runserver -6 localhost:8000

Reference: Django Docs: Examples of using different ports and addresses

Upvotes: 2

Qixin
Qixin

Reputation: 41

I read the documentation about IPV6 and got some answers, you must put IPV6 in square brackets.

Localhost for IPV6: ::1

Any address for IPV6 : :: (for IPV4 is 0.0.0.0)

So in settings.py AllOWED_HOSTS should be ['my_IPV4', '[my_IPV6]', 'localhost']

Django run server command: python manage.py runserver [::]:8000

To access the IPV6 address with port using https://[IPV6 address]:8000

You will need brackets for URL to access IPV6 address even without port number

http://[fe80::b746:6473:e65f:5dd4]/foo/bar

http://[fe80::b746:6473:e65f:5dd4]:8000/foo/bar

Reference https://cheat.readthedocs.io/en/latest/ipv6.html

Upvotes: 1

Related Questions