From 37e20f6ef282e1f5df8df8e558ee8c37651ae058 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 12 Dec 2022 18:48:46 -0800 Subject: [PATCH] feat: allow listening specific addrs for API port (#16223) --- cmd/server-main.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/cmd/server-main.go b/cmd/server-main.go index e9d34f40a..25e63afac 100644 --- a/cmd/server-main.go +++ b/cmd/server-main.go @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2021 MinIO, Inc. +// Copyright (c) 2015-2022 MinIO, Inc. // // This file is part of MinIO Object Storage stack // @@ -466,8 +466,23 @@ func getServerListenAddrs() []string { addrs.Add(net.JoinHostPort(ip.String(), globalMinioPort)) } } - // Add the interface specified by the user - addrs.Add(globalMinioAddr) + host, _ := mustSplitHostPort(globalMinioAddr) + if host != "" { + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) + defer cancel() + + haddrs, err := globalDNSCache.LookupHost(ctx, host) + if err == nil { + for _, addr := range haddrs { + addrs.Add(net.JoinHostPort(addr, globalMinioPort)) + } + } else { + // Unable to lookup host in 2-secs, let it fail later anyways. + addrs.Add(globalMinioAddr) + } + } else { + addrs.Add(globalMinioAddr) + } return addrs.ToSlice() }