1

Question: How do I "set" the canonical hostname as reported by java's InetAddress.getCanonicalHostname() method?

Context: I'm trying to run Neo4j (which has an embedded jetty server) on CentOS 5.6. The service starts up just fine, but it's binding to the wrong address (IPv6) as evidenced by netstat. Instead of :::*, I need it to bind to 0.0.0.0 (IPv4).

Is there a JVM parameter I can use to force getCanoncialHostname() to return the string I want? If not, what can I add to my hosts file or other linux config file to achieve the same?

[edit - added netstat output]

$ netstat -plten
...
Proto  Local Address    Foreign Address    State       User       Inode      PID/Program name
tcp    0.0.0.0:930      0.0.0.0:*          LISTEN      0          10240      -
tcp    0.0.0.0:139      0.0.0.0:*          LISTEN      0          57484      -
tcp    0.0.0.0:111      0.0.0.0:*          LISTEN      0          10104      -
tcp    127.0.0.1:25     0.0.0.0:*          LISTEN      0          12714      -
tcp    0.0.0.0:445      0.0.0.0:*          LISTEN      0          57483      -
tcp    :::7474          :::*               LISTEN      500        524965     28200/java
tcp    :::22            :::*               LISTEN      0          62967      -
tcp    :::1337          :::*               LISTEN      500        524953     28200/java
tcp    :::15003         :::*               LISTEN      500        481149     3926/java
tcp    :::60156         :::*               LISTEN      500        524951     28200/java
tcp    :::15004         :::*               LISTEN      500        524917     28177/java

Port 22 is ssh - I can ssh into the machine just fine, so there's evidence that the :::* foreign address is (in principle) just fine.

[edit - added remote nmap output]

Running nmap from another host, specifically listing all the above produces this:

$ nmap -T4 -A -v -PE -PS22,25,80 -PA21,23,80,930,139,111,25,445,7474,22,1337,15003,60156,15004,3389 192.168.176.138
...
Initiating SYN Stealth Scan at 13:31
Scanning 192.168.176.138 [1000 ports]
Discovered open port 111/tcp on 192.168.176.138
Discovered open port 139/tcp on 192.168.176.138
Discovered open port 445/tcp on 192.168.176.138
Discovered open port 22/tcp on 192.168.176.138
Discovered open port 15003/tcp on 192.168.176.138
Discovered open port 15004/tcp on 192.168.176.138
Completed SYN Stealth Scan at 13:31, 0.04s elapsed (1000 total ports)
4

3 回答 3

3

您可以通过以下网络属性告诉您的 JVM 使用 IPv4 而不是 IPv6:-Djava.net.preferIPv4Stack=true

请参阅网络属性

于 2011-06-02T17:31:14.473 回答
2

也许设置-Djava.net.preferIPv4Stack=true系统属性会有所帮助?

于 2011-06-02T17:28:38.803 回答
1

你必须告诉码头监听特定的接口(IP),看这里: http: //www.paralint.com/blog/2007/05/18/making-jetty-listen-to-the-local-interface-only /

行: <Set name="Host"><SystemProperty name="jetty.host" default="localhost"/></Set> 这样做

于 2011-06-02T17:27:29.743 回答