问题
Our system has an whitelist based on IP address to specify which gRPC client is allowed to connect. once before a new remote gRPC client join the network, the end user has to add its ip into the white list. Most time, it's easy for end user to know which NIC(ip) will be used by the gRPC client, but If there is too many NIC(ip) in the gRPC client node, it's hard for the end user to know which ip will be used before it's running, 'cause which NIC(ip) to be used is determine by the Linux system by default. Maybe 'route -n' command can be used to know the NICs priority, but the end user has to login via ssh, it makes a very bad user experience. So, Our customer deliver a new requirement which suggest us to bind a specified ip address for the gRPC client. I know it's easy for a normal socket programme to use 'bind' routine to bind an ip address for the client socket, but I don't know if there's some way for gRPC client(C++) to do that.
回答1:
gRPC doesn't have a way to bind a certain NIC when connecting to a server. You might need to get help from OS. https://unix.stackexchange.com/questions/338338/configure-a-process-to-use-specific-nic/338357 appears to be relevant.
来源:https://stackoverflow.com/questions/62710179/how-to-bind-network-interface-for-c-grpc-client