diff --git a/Akka.Hosting.sln b/Akka.Hosting.sln
index c2c5c843..6a718ac5 100644
--- a/Akka.Hosting.sln
+++ b/Akka.Hosting.sln
@@ -31,6 +31,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{EF
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Hosting.SqlSharding", "src\Examples\Akka.Hosting.SqlSharding\Akka.Hosting.SqlSharding.csproj", "{2C2C2DE2-5A79-4689-9D1A-D70CCF17545B}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Remote.Hosting.Tests", "src\Akka.Remote.Hosting.Tests\Akka.Remote.Hosting.Tests.csproj", "{4D748F16-AC22-4E8B-94D7-3DAF6B7CBD00}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -75,6 +77,10 @@ Global
{2C2C2DE2-5A79-4689-9D1A-D70CCF17545B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2C2C2DE2-5A79-4689-9D1A-D70CCF17545B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2C2C2DE2-5A79-4689-9D1A-D70CCF17545B}.Release|Any CPU.Build.0 = Release|Any CPU
+ {4D748F16-AC22-4E8B-94D7-3DAF6B7CBD00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {4D748F16-AC22-4E8B-94D7-3DAF6B7CBD00}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {4D748F16-AC22-4E8B-94D7-3DAF6B7CBD00}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {4D748F16-AC22-4E8B-94D7-3DAF6B7CBD00}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/src/Akka.Remote.Hosting.Tests/Akka.Remote.Hosting.Tests.csproj b/src/Akka.Remote.Hosting.Tests/Akka.Remote.Hosting.Tests.csproj
new file mode 100644
index 00000000..881eb73a
--- /dev/null
+++ b/src/Akka.Remote.Hosting.Tests/Akka.Remote.Hosting.Tests.csproj
@@ -0,0 +1,16 @@
+
+
+ $(TestsNetCoreFramework)
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Akka.Remote.Hosting.Tests/RemoteConfigurationSpecs.cs b/src/Akka.Remote.Hosting.Tests/RemoteConfigurationSpecs.cs
new file mode 100644
index 00000000..b8fe0641
--- /dev/null
+++ b/src/Akka.Remote.Hosting.Tests/RemoteConfigurationSpecs.cs
@@ -0,0 +1,32 @@
+using System.Threading.Tasks;
+using Akka.Actor;
+using Akka.Hosting;
+using FluentAssertions;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+using Xunit;
+
+namespace Akka.Remote.Hosting.Tests;
+
+public class RemoteConfigurationSpecs
+{
+ [Fact]
+ public async Task AkkaRemoteShouldUsePublicHostnameCorrectly()
+ {
+ // arrange
+ using var host = new HostBuilder().ConfigureServices(services =>
+ {
+ services.AddAkka("RemoteSys", (builder, provider) =>
+ {
+ builder.WithRemoting("0.0.0.0", 0, "localhost");
+ });
+ }).Build();
+
+ // act
+ await host.StartAsync();
+ ExtendedActorSystem actorSystem = (ExtendedActorSystem)host.Services.GetRequiredService();
+
+ // assert
+ actorSystem.Provider.DefaultAddress.Host.Should().Be("localhost");
+ }
+}
\ No newline at end of file
diff --git a/src/Akka.Remote.Hosting/AkkaRemoteHostingExtensions.cs b/src/Akka.Remote.Hosting/AkkaRemoteHostingExtensions.cs
index 4c70585d..05ed8d57 100644
--- a/src/Akka.Remote.Hosting/AkkaRemoteHostingExtensions.cs
+++ b/src/Akka.Remote.Hosting/AkkaRemoteHostingExtensions.cs
@@ -8,6 +8,11 @@ public static class AkkaRemoteHostingExtensions
{
private static AkkaConfigurationBuilder BuildRemoteHocon(this AkkaConfigurationBuilder builder, string hostname, int port, string publicHostname = null, int? publicPort = null)
{
+ if (string.IsNullOrEmpty(publicHostname))
+ {
+ publicHostname = hostname;
+ hostname = "0.0.0.0"; // bind to all addresses by default
+ }
var config = $@"
akka.remote.dot-netty.tcp.hostname = ""{hostname}""
akka.remote.dot-netty.tcp.public-hostname = ""{publicHostname ?? hostname}""
@@ -30,7 +35,7 @@ private static AkkaConfigurationBuilder BuildRemoteHocon(this AkkaConfigurationB
/// The same instance originally passed in.
public static AkkaConfigurationBuilder WithRemoting(this AkkaConfigurationBuilder builder, string hostname, int port, string publicHostname = null, int? publicPort = null)
{
- var hoconBuilder = BuildRemoteHocon(builder, hostname, port);
+ var hoconBuilder = BuildRemoteHocon(builder, hostname, port, publicHostname, publicPort);
if (builder.ActorRefProvider.HasValue)
{