I have a linux box with two IP addresses (say IP1, and IP2).
I have a server-process listening to a specific port (say 60000). Now, I want to run two copies of the server-process on the above linux box. How can I set up my system such that I can have process1 handle packets to IP1:60000 and have process2 handle packets to IP2:60000?
Or can I?
Generally most daemons will have an option in the config to control which IP address and Port pair it will bind or listen on (see
man 2 bind
for the nitty-gritty C system call level details).After you have changed the configuration and restarted the daemon, you can see what it is bound to using the
netstat -ln
command. Example output will be something like:0.0.0.0
means all IPs and the:22
means it is listening destination TCP port 22. The second column0.0.0.0:*
means accepts all source IPs and source ports.In your case you should see one row that has a local address like
12.12.12.12:6000
and another row with a local address like13.13.13.13:6000
.If you there doesn't seem to be an option in the configuration file, it might be a command line switch for the daemon itself. In that case you might need to edit the start up file in
/etc/init.d/whatever
. This is usually not the case however.The process itself is generally in control of the IP addresses it listens on. For example, in Apache, you set up the listening IP in the
<VirtualHosts>
directive.