Java Socket defines a specific network interface for outgoing connections

OK I know that similar questions have been asked before, but that's different.

I noticed from answers to similar questions that I can use Socket.bindto specify a specific network interface for outgoing connections. This page is an official instruction.

Now my machine has two network adapters eth0and eth1, and sets the system routing table eth0as the outgoing interface for connecting to the server S.

Then I tried the following:

Socket so = new Socket();
so.bind(new InetSocketAddress("ip.address.of.eth1", 0));
so.connect(new InetSocketAddress("ip.address.of.S", 80));

I used WireShark to capture packets and noticed that the "Source Address" field of the IP header did exist ip.address.of.eth1. But while checking the Ethernet headers, I noticed that the source MAC address is actually the MAC address eth0, that is, packets are still sent through eth0!

Can someone explain why he has this behavior? Expected? Many thanks!

+4
source share
1 answer

This is the result of a “weak finite system model”. It is too broad to describe, but it is discussed in RFC 1122 .

+4
source

All Articles