1

I'm working on a Java Project where I need to Simulate a Printer. Clients of the Printer send SNMP messages to the Printer. Printer should have SNMP Agent running on port 161. Since, port 161 is a well known port, I'm unable to use that port. How can I get my Application bound to port 161?

vineeth kumar
  • 175
  • 1
  • 12
  • 1
    relevant similar question https://stackoverflow.com/questions/12739768/snmp-error-with-port-already-in-use – Stephan Jun 25 '18 at 15:37
  • 1
    what error do you get when you try to bind to port 161? – corsiKa Jun 25 '18 at 15:44
  • 1
    You can bind to any port and then use firewall to do portforwarding from port 161 – rkosegi Jun 25 '18 at 15:55
  • @rkosegi, can you explain how to do portforwarding using firewall? – vineeth kumar Jun 25 '18 at 18:11
  • @vineethkumar : that would highly depend on OS you are using – rkosegi Jun 25 '18 at 18:18
  • And on the particular router. Usually you just enter the router configuration and add a port forwarding rule. Trigger port `161` (traffic comes to port `161`) and then let the router forward the traffic to a different port `X` and from there to your app which listens to that port. – Zabuzard Jun 25 '18 at 22:55

1 Answers1

4

The problem is not because this is a well known port but because it is a reserved port (lower than 1024). On many operating systems, reserved ports can be bound by the superuser. So just run your java VM as root.

Alexandre Fenyo
  • 4,526
  • 1
  • 17
  • 24