Python socked bound to secondary IP gets connection reset from server
Question: I'm trying to create a python socket script that binds to a secondary IP and
connects to a server. When I run the script python gives me a "socket.error:
[Errno 111] Connection refused"

The TCPdump shows that the server I try to connect to sends back a reset
response. Running the script without the socket.bind works.

The script:

    
    
    import socket
    port = 9009
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.bind(("123.123.123.123", port)) # Not the real IP I use
    sock.connect(("81.236.48.66", 80)) # Raises connection refused
    

The tcpdump:

    
    
    11:22:08.211502 IP 123.123.123.123.9009 > 81.236.48.66.80: Flags [S], seq 3687363746, win 5840, options [mss 1460,sackOK,TS val 1304421782 ecr 0,nop,wscale 6], length 0
    11:22:08.211763 IP 81.236.48.66.80 > 123.123.123.123.9009: Flags [R.], seq 0, ack 3687363747, win 5840, length 0
    

I run the script on a linux box and the secondary IP I use is listen when I
use the command: "ip list all"

Thanks in advance and please bear with me since I'm not very experienced in
socket programming.


Answer: I found the error. The firewall was configured to block the response and sent
a reset flag.

