I have set up some virtual IPs via:
~# ip link add link eth0 name eth0.1 address 11:22:33:44:55:66 type macvlan
~# ifconfig eth0.1 10.10.0.0/24
I am using the following code to connect from it:
sTCP = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sTCP.setsockopt(socket.SOL_SOCKET, IN.SO_BINDTODEVICE, IFACE)
print "PORT s_TCP:" + str(HOST) +":" +str(TCP_PORT)
sTCP.connect((HOST, TCP_PORT))
print "Connected"
this works fine if IFACE is eth0, but it does not get past sTCP.connect from eth0.1 and fails in bindtodevice (as expected) on eth0.2.
Why does eth0.1 not work? Is this a python problem, or something in the linux network implementation?
I just tried this on my Fedora 13 system and it worked. I did have to make some modifications to make it work on my system, hopefully this will give you clues. Code used:
I used tcpdump to prove to myself the packets were coming out of eth0.1. Perhaps you’re running into a VLAN issue? Run packet captures on the client and server to see what’s actually happening on the wire.