aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Change socket sender IP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Change socket sender IP" Watch "Change socket sender IP" New topic
Author

Change socket sender IP

Jochem Gruter
Greenhorn

Joined: Aug 16, 2011
Posts: 9
I've a VPS with 2 IP addresses (ip a and ip b). When I send packets with a socket, it sends allways with ip a. How can I change this so that it send with ip b?
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1282

Hi Jochem,

the sender IP usually depends on the routing table(s) and network configuration of your OS. The network stack decides which interface to use for sending your packets based on the routing table and the IP address of this interface is automatically used as sender IP. This can be changed though. With Linux for example you can use an iptables postrouting rule to modify the sender IP just before the network packets leave your box. There are surely similar approaches for any modern OS.

Marco
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Change socket sender IP