Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to connect to Memgraph via IPv6 host addres #1010

Open
antejavor opened this issue Oct 4, 2024 · 3 comments
Open

Not able to connect to Memgraph via IPv6 host addres #1010

antejavor opened this issue Oct 4, 2024 · 3 comments
Assignees
Labels
priority: medium (missing info) An additional information can be helpful or interesting, but the absence is not disruptive

Comments

@antejavor
Copy link
Contributor

antejavor commented Oct 4, 2024

Create a IPv6 network:

docker network create --ipv6 --subnet 2001:db8::/64 ip6net

Start Memgraph in IPv6 network:

docker run --name memgraph --network ip6net -p 7687:7687 memgraph/memgraph:2.20.0 --log-level=TRACE --also-log-to-stderr --telemetry-enabled=False

Keep in mind that now Bolt port works both for IPv4 and IPv6 networking.

maple@big-bang:~$ ss -tuln | grep LISTEN
tcp   LISTEN 0      4096                                     0.0.0.0:7687       0.0.0.0:*
tcp   LISTEN 0      128                                    127.0.0.1:631        0.0.0.0:*
tcp   LISTEN 0      4096                               127.0.0.53%lo:53         0.0.0.0:*
tcp   LISTEN 0      128                                      0.0.0.0:22         0.0.0.0:*
tcp   LISTEN 0      1024                                   127.0.0.1:43509      0.0.0.0:*
tcp   LISTEN 0      4096                              100.64.149.141:54544      0.0.0.0:*
tcp   LISTEN 0      4096                                        [::]:7687          [::]:*
tcp   LISTEN 0      4096   [fd7a:115c:a1e0:ab12:4843:cd96:6240:958d]:54544         [::]:*
tcp   LISTEN 0      128                                        [::1]:631           [::]:*
tcp   LISTEN 0      128                                         [::]:22            [::]:*

You can disable IPv4 network access by setting the port like this: -p '[::]::7687'

This can be checked via: docker container inspect memgraph --format "{{json .NetworkSettings.Ports}}"

The problem is that connection to the [::] [::1] or IPv6 address from the container "GlobalIPv6Address": "2001:db8::2", does not work in any way, and results in the following errors, depending how you change the driver or URI config:

maple@big-bang:~/repos/mgconsole/build/src$ ./mgconsole --host=2001:db8::2
Connection failure: couldn't connect to host: Connection refused

Neo4j driver:

Error: Couldn't connect to [::]:7687 (resolved to ('[::]:7687',)):
Failed to read any data from server ResolvedIPv6Address(('::', 7687, 0, 0)) after connected (deadline <neo4j._deadline.Deadline object at 0x70d036001de0>)
maple@big-bang:~/repos/mgconsole/build/src$ ./mgconsole --host=ip6-localhost
mg_raw_transport_recv: Connection reset by peer
Connection failure: failed to receive handshake response

Snippets:

from neo4j import GraphDatabase


URI = "bolt://[::]:7687"
AUTH = ("", "")
employee_threshold=10


def main():
    with GraphDatabase.driver(URI, auth=AUTH) as driver:
        with driver.session(database="") as session:
            for i in range(100):
                try:
                    session.run("CREATE (a:Person {name: 'Alice'})")
                except Exception as e:
                    print(f"Error: {e}")

main()
import mgclient

try:
    conn = mgclient.connect(host='[::]', port=7687)
    cursor = conn.cursor()
    cursor.execute("CREATE (a:Person {name: 'Alice'})")
    cursor.close()
    print("Success")
except Exception as e:
    print(f"Error: {e}")

Context:

maple@big-bang:~$ cat /etc/hosts
127.0.0.1	localhost
127.0.1.1	big-bang

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
@as51340 as51340 self-assigned this Oct 4, 2024
@as51340
Copy link
Contributor

as51340 commented Oct 4, 2024

Hi,

Memgraph must be configured to listen on all ipv6 addresses by setting --bolt-address=::.

To run without explicit docker network, use:

docker run --name memgraph -p 7687:7687 memgraph/memgraph:2.20.0 --log-level=TRACE --also-log-to-stderr --telemetry-enabled=False --bolt-address=::

For the host parameter in mgconsole or uri in Python driver, you can use :: (corresponding to IPv4 0.0.0.0) or ::1 (corresponding to Ipv4 127.0.0.1).

If you create an explicit ipv6 docker network, you can then also use network's ipv6 address to connect in addition to :: and ::1.

@antejavor
Copy link
Contributor Author

antejavor commented Oct 4, 2024

Nice, then this is a documentation issue, will transfer this issue on the docs, so we can properly document this.

Please edit your answer here 🙏 : https://stackoverflow.com/questions/74025244/how-to-connect-using-neo4j-driver-over-ipv6

@antejavor antejavor transferred this issue from memgraph/memgraph Oct 8, 2024
@antejavor antejavor assigned antejavor and unassigned as51340 Oct 8, 2024
@antejavor
Copy link
Contributor Author

We also need to document/test similar for monitoring server.

@katarinasupe katarinasupe added the priority: medium (missing info) An additional information can be helpful or interesting, but the absence is not disruptive label Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: medium (missing info) An additional information can be helpful or interesting, but the absence is not disruptive
Projects
None yet
Development

No branches or pull requests

3 participants