How do I set the port use for an IP address when there are multiple NIC environment?
 Technote (FAQ)
 
Problem
When creating a Registry on a machine that has two(2) IP addresses, the registry port is bound to both addresses. Is there a way to have it bind to only valid IP?

Ports binding to Zero-IP address is a security exposure as it renders the ports open to any application to bind. Also, the RMIRegistry default port is 1099 for the Zero-IP address in a Dual-NIC environment
 
Cause
In a Dual-NIC environment, when starting RMIRegistry script from $WAS_HOME/java/jre/bin/rmiregistry , It is started on the default port 1099 and running netstat -a shows the port 1099 bound to Zero-IP address, in other words 0.0.0.0:1099.
 
Solution
The rmiregistry tool does not provide a command line option to bind to a specific (valid) IP address, but there is an application programming interface (API).

You can use the LocateRegistry.createRegistry() method, and
specify an RMIServerSocketFactory to use for that registry. Therefore, you can
use an RMIServerSocketFactory implementation that creates a server socket bound to a specific local address. For example:

    ...
    LocateRegistry.createRegistry(REGISTRY_PORT,
                                  null,
                                  new BindAddrSSF(REGISTRY_BIND_ADDR);
    ...

    private static class BindAddrSSF implements RMIServerSocketFactory {
        private final InetAddress bindAddr;
        BindAddrSSF(InetAddress bindAddr) {
            this.bindAddr = bindAddr;
        }
        public ServerSocket createServerSocket(int port) throws IOException {
            return new ServerSocket(port, 0, bindAddr);
        }
        public int hashCode() {
            return bindAddr.hashCode();
        }
        public boolean equals(Object obj) {
            if (obj == this) {
                return true;
            } else if (obj == null || getClass() != obj.getClass()) {
                return false;
            }
            BindAddrSSF other = (BindAddrSSF) obj;
            return bindAddr.equals(other.bindAddr);
        }
    }


The Object.hashCode/equals overrides are important. Visit these sites to learn more:
http://developer.java.sun.com/developer/bugParade/bugs/4492317.html
http://java.sun.com/j2se/1.4.1/docs/api/java/rmi/server/RMIServerSocketFactory.html
 
 
Cross Reference information
Segment Product Component Platform Version Edition
Application Servers Runtimes for Java Technology Java SDK
 
 


Document Information


Product categories: Software > Application Servers > Distributed Application & Web Servers > WebSphere Application Server > General
Operating system(s): Windows
Software version: 5.1
Software edition:
Reference #: 1246908
IBM Group: Software Group
Modified date: Sep 30, 2006