I would like to request support for IPv4/IPv6 dual stack in Spring Boot. Specifically, I need the ability to configure two addresses to listen on, one for IPv4 and one for IPv6, while disallowing listening on the unspecified address (0.0.0.0 or ::).

Currently, it seems that Spring Boot only allows configuration of a single address (server.address) for listening. It would be great if we could configure two addresses, one for IPv4 and one for IPv6, to enable dual stack support.

Thank you for your consideration!

Comment From: wilkinsona

I believe this is already supported. We don't have any plans to add property-based support for configuring multiple ports, addresses, and so on but, in the same way that you can programatically configure the embedded web server to listen on multiple ports, it can also be configured to listen on multiple addresses.

With Tomcat, this is done using a WebServerFactoryCustomizer and adding an additional Connector:

@Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> connectorCustomizer() {
    return (tomcat) -> tomcat.addAdditionalTomcatConnectors(createConnector());
}

private Connector createConnector() {
    Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
    connector.setPort(8080);
    try {
        ((Http11NioProtocol) connector.getProtocolHandler()).setAddress(InetAddress.getByName("127.0.0.1"));
    }
    catch (UnknownHostException ex) {
        throw new IllegalStateException(ex);
    }
    return connector;
}

With this bean in place, the embedded Tomcat server will listen on 127.0.0.1 port 8080 and whatever you have configured using server.address and server.port.

Comment From: copbint

Thanks for your reply! I have tried it, but added Connector by this way will not respect to server.ssl configuration. Is there any way to achieve that? Thanks!

Comment From: wilkinsona

server.* properties are only applied to the default, auto-configured connector. To use SSL with an additional connector you'll have to configure it manually. You could take some inspiration from Boot's org.springframework.boot.web.embedded.tomcat.SslConnectorCustomizer.

I'll close this one now as it sounds like you have a way to do what you want and, as I said above, we do not have any plans for property-based configuration of multiple connectors at this time.