0

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?

2 Answers 2

4

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:

Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     

0.0.0.0 means all IPs and the :22 means it is listening destination TCP port 22. The second column 0.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 like 13.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.

2
  • But the process will still have the port bound on both IPs, and the second instance won't be able to bind the same port.
    – mfinni
    Mar 15, 2011 at 14:37
  • @mfinni: Oh didn't read that quite right. Ya, iptables won't help. Mar 15, 2011 at 14:40
0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .