Listen on IPv6, also? #834
-
My server has both IPv4 and IPv6, and I want Axum to listen to both types of protocol on all interfaces. The following results in an Axum which is available on port 3000 via IPv4 only. How can I make it available on IPv6, also?
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 9 replies
-
Try with: let addr = ":::3000".parse().unwrap();
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap(); or let addr = ":::3000".parse::<std::net::SocketAddr>().unwrap();
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap(); |
Beta Was this translation helpful? Give feedback.
-
I would imagine that this would work: const PORT = 3000;
let svc = app.into_make_service();
let addr4 = SocketAddr::from((Ipv4Addr::UNSPECIFIED, PORT));
let addr6 = SocketAddr::from((Ipv6Addr::UNSPECIFIED, PORT));
let server4 = axum::Server::bind(&addr4).serve(svc.clone());
let server6 = axum::Server::bind(&addr6).serve(svc);
let (res4, res6) = futures_util::future::join(server4, server6).await;
res4.unwrap();
res6.unwrap(); |
Beta Was this translation helpful? Give feedback.
-
By the way, in relation to this, https://serverfault.com/a/39561/15081 describes well how this is OS dependent, and on Linux behavior can be adjusted in /proc/sys/net/ipv6/bindv6only |
Beta Was this translation helpful? Give feedback.
Try with:
or