3

I recently got a machine with 10 IPv6 addresses, this is a CentOS running MySQL and tomcat, I'm using spring to create servlets.

I was wondering is there a Java way (not OS routing tables) to set the outgoing IP from the ones available on my server?

What I am trying to do is have a incoming address reach the servlets and do an http post from a specific IP accordingly.

For all my research the thing I saw closest to solving this would be httplib, but is there something like this for Java?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
twk87
  • 33
  • 4
  • http://stackoverflow.com/questions/4327970/how-can-a-java-application-running-on-windows-7-choose-which-network-adapter-to and http://stackoverflow.com/questions/1008781/is-it-possible-to-specify-which-network-interface-for-a-jvm-or-ide-to-use – Aravind Yarram Jan 22 '13 at 19:42
  • @Pangea: multiple IPs don't mean multiple interfaces. Could be the same interface with multiple IPs. – m0skit0 Jan 22 '13 at 19:43
  • I don't quite understand what are you asking. Are you just wanting to make an HTTP POST come from a specific IP address? (it just so happens that this action is triggered by a request to a tomcat server?) Or are you wanting to change what IP address tomcat is listening on? Or some combination of both? – Charlie Jan 22 '13 at 19:57
  • Does not [this documentation](http://docs.oracle.com/javase/7/docs/api/java/net/Socket.html#Socket%28java.net.InetAddress,%20int,%20java.net.InetAddress,%20int%29) meet your requirements? Check it out. – BevynQ Jan 22 '13 at 19:51
  • possible duplicate of [How can I specify the local address on a java.net.URLConnection?](http://stackoverflow.com/questions/91678/how-can-i-specify-the-local-address-on-a-java-net-urlconnection) – Qantas 94 Heavy Apr 15 '14 at 13:57

1 Answers1

4

just use localaddr parameter in your socket.

Pretty much duplicate question here:

Community
  • 1
  • 1
Mark
  • 2,423
  • 4
  • 24
  • 40