3

I want to use low port in my application (SNMP Trap Receiver on Spring web + Tomcat7). As I told in this thread Binding Low Port to Java Program on Ubuntu Server, before, I got error Permission denied. Then I change tomcat7 user group be root. But after that, I got java.net.BindException: Cannot assign requested address error. For every port that I try (low or high port), I always got this error.

I check if the port has used, I see that the port still free. I check my /etc/host content, it is like this:

127.0.0.1 localhost 
127.0.1.1 test-server 
# The following lines are desirable for IPv6 capable hosts 
::1 localhost ip6-localhost ip6-loopback 
ff02::1 ip6-allnodes 
ff02::2 ip6-allrouters 
124.81.xx.x test-server.com

note: my OS is ubuntu server

Community
  • 1
  • 1
Mahadi Siregar
  • 615
  • 3
  • 17
  • 38
  • What {address:port} are you binding to? and is `address` a local IP address of the localhost? – user207421 Jun 03 '15 at 07:04
  • Yes, ip address of localhost (124.81.xx.xx:162) – Mahadi Siregar Jun 03 '15 at 07:08
  • But is it a *local* IP address of the host, or its public address via a router/firewall and port forwarding? You can't bind to the latter, only the former. – user207421 Jun 03 '15 at 07:16
  • oh, the ip address is a public ip. My server only has this one ip, whereas when I try to bind/listen on localhost ip (127.0.0.1:162), the trap cannot catched. How can I solve this. Fyi, I am not the admin of networking – Mahadi Siregar Jun 03 '15 at 09:02

1 Answers1

2

You should bind to 0.0.0.0 instead of trying to specify a local-address.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • The listener on at 0.0.0.0:162, but when I try send trap to real ip (public ip->124.81.xx.xx), the trap is not catched – Mahadi Siregar Jun 03 '15 at 11:18
  • Sorry, today I try it again and it working well. I do not know why yesterday it was not working, maybe I missed something. Thank you for the answer. – Mahadi Siregar Jun 05 '15 at 04:57
  • You can't bind to any address that isn't a local IP address of the localhost. You can't for example bind to the outside address provided by an external router. – user207421 Jun 05 '15 at 05:39