Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was just wondering how I go about pointing a static IP address which I have purchased to an application instance on my server, using a different IP from the one I currently have pointing to my main server?

This baffles me completely, I know of two commands that are related but I don't know how to force them to point the IP to a certain port on my localhost. I think they are ARP and route. I could be completely wrong.

All I want to do is point different IP addresses to different instances of Java.

Also I'm using CentOS 5.9

share|improve this question
iptables NAT, port forwarding – goldilocks Feb 5 '13 at 20:47
Care to expand at all? – Conner Stephen McCabe Feb 5 '13 at 21:45
up vote 3 down vote accepted

IP addresses do not point to ports or applications. They point to (virtual) machines, or containers, or contexts.

An application listens on a port, which can be (depending on what it passes to bind) on either all IP addresses on the machine, or on one IP address. So the best thing to do would be to get your application to call bind with the correct IP. You can have two different programs listening on port 80 (for example) as long as they're listening on a different IP address. Many programs allow you to specify the IP to listen on, for sometimes using the syntax where is the IP and 1234 the port. When you leave out the IP, they default to which is all addresses on the machine.

If your application can't do that, you can—as goldilocks hinted—work around it using NAT. Basically, you have each app listen on a different port, say 8080 and 8081. Then you set up NAT rules to redirect port 80:

iptables -t nat -A PREROUTING -d -p tcp --dport 80 -j DNAT --to-destination 8080
iptables -t nat -A PREROUTING -d -p tcp --dport 80 -j DNAT --to-destination 8081

You can add additional firewall rules block direct access to ports 8080 and 8081, of course.

You could also use ipvs to do this. Or a proxy server. There are probably several more ways.

share|improve this answer
Thanks very much derobert, this was very informative, really really appreciate it :) – Conner Stephen McCabe Feb 5 '13 at 22:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.