Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Change socket sender IP

 
Jochem Gruter
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic