how to bind grpc client to specific network interface

1,152 views
Skip to first unread message

joe.p...@decisionsciencescorp.com

unread,
Apr 26, 2019, 5:58:08 PM4/26/19
to grpc.io
Is it possible to pass a parameter to grpc that allows clients to pick a specific network interface on a computer with multiple ethernet interfaces? 

Carl Mastrangelo

unread,
Apr 26, 2019, 6:37:35 PM4/26/19
to grpc.io
What language?

xkw...@connect.hku.hk

unread,
Jul 11, 2019, 8:33:12 AM7/11/19
to grpc.io
Can grpc-go bind grpc client to specific network interface?

dfa...@google.com

unread,
Jan 27, 2021, 2:47:29 PM1/27/21
to grpc.io
Sorry for the very late reply to this question.  Yes, this is possible in Go by providing a custom dialer to grpc: https://pkg.go.dev/google.golang.org/grpc#WithContextDialer

It would look something like:

myDialer := net.Dialer{LocalAddr: <your network interface address info here>}
client, err := grpc.Dial(target, <other options>,
  grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
    return myDialer.DialContext(ctx, "tcp", addr)
})

Reply all
Reply to author
Forward
0 new messages