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?
Asked
Active
Viewed 213 times
1
-
1relevant similar question https://stackoverflow.com/questions/12739768/snmp-error-with-port-already-in-use – Stephan Jun 25 '18 at 15:37
-
1what error do you get when you try to bind to port 161? – corsiKa Jun 25 '18 at 15:44
-
1You 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 Answers
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
-
1On some OSes the security manager might allow users to use reserved ports. – Peter Lawrey Jun 25 '18 at 16:00