File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 Android Security Essentials Live Lessons this week in the Android 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: 1280

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Change socket sender IP
 
Similar Threads
Problems with Binding a socket on a remote machine
socket's http connection
Forward Socket to another server socket
Socket communiction works on XP but not on Vista
how to get Client Ip address?