In Microsoft Azure, even when a VM has a public IP address internface, the system sees it as a private network address. It also uses a private IP address as the gateway. The only way to "fix" this without making routing table changes is to use setsockopt()
with SO_BINDTODEVICE
, which is a privileged operation. In addition to that (and this can't be worked around in any generic way) you will need to do the standard socket bind()
with the private IP address corresponding to the interface you want to use.
The new generation of network configuration tools (I guess they're not that new, but they replaced route
and ifconfig
) makes policy-based routing pretty easy, especially if you don't require anything too special