linux - How to redirect 162 port to a customized port which above 1024 for snmp trap? -
i wrote pieces of code listen on 162 port. looks following
listenaddress = genericaddress.parse(system.getproperty("snmp4j.listenaddress", "udp:0.0.0.0/162")); transportmapping transport; if (listenaddress instanceof udpaddress) { transport = new defaultudptransportmapping((udpaddress) listenaddress); } else { transport = new defaulttcptransportmapping((tcpaddress) listenaddress); } snmp = new snmp(dispatcher, transport); snmp.getmessagedispatcher().addmessageprocessingmodel(new mpv2c()); snmp.listen();
but code can started non-root user. when run program, got error. java.net.bindexception permission denied.
i redirect 162 port 16200. , in code, can call
listenaddress = genericaddress.parse(system.getproperty("snmp4j.listenaddress", "udp:0.0.0.0/16200"));
then modified /etc/sysconfig/iptables, didn`t work. following iptables configuration.
*nat :prerouting accept [1379:235423] :postrouting accept [6:680] :output accept [6:680] -a prerouting -p udp -m udp --dport 162 -j redirect --to-ports 16200 commit # completed on thu nov 10 18:07:25 2016 # generated iptables-save v1.3.5 on thu nov 10 18:07:25 2016 *filter :input accept [38534:3129869] :forward accept [0:0] :output accept [2052:284032] -a input -p tcp -m tcp --dport 161 -m state --state new,established -j accept -a input -p udp -m udp --dport 161 -m state --state new,established -j accept -a input -p tcp -m tcp --dport 162 -m state --state new,established -j accept -a input -p udp -m udp --dport 162 -m state --state new,established -j accept -a input -p tcp -m tcp --dport 161 -m state --state new,established -j accept -a input -p udp -m udp --dport 161 -m state --state new,established -j accept -a input -p tcp -m tcp --dport 162 -m state --state new,established -j accept -a input -p udp -m udp --dport 162 -m state --state new,established -j accept -a input -p tcp -m tcp --dport 16200 -m state --state new,established -j accept -a input -p udp -m udp --dport 16200 -m state --state new,established -j accept -a output -p tcp -m tcp --sport 161 -m state --state established -j accept -a output -p udp -m udp --sport 161 -m state --state established -j accept -a output -p tcp -m tcp --sport 162 -m state --state established -j accept -a output -p udp -m udp --sport 162 -m state --state established -j accept -a output -p tcp -m tcp --sport 161 -m state --state established -j accept -a output -p udp -m udp --sport 161 -m state --state established -j accept -a output -p tcp -m tcp --sport 162 -m state --state established -j accept -a output -p udp -m udp --sport 162 -m state --state established -j accept -a output -p tcp -m tcp --sport 16200 -m state --state established -j accept -a output -p udp -m udp --sport 16200 -m state --state established -j accept commit # completed on thu nov 10 18:07:25 2016 # generated iptables-save v1.3.5 on thu nov 10 18:07:25 2016 *mangle :prerouting accept [39240:3206748] :input accept [38535:3129909] :forward accept [0:0] :output accept [2052:284032] :postrouting accept [2052:284032] commit
how configure iptables can trap message on 16200 port? or there other methods this?
i confused. please give me suggestions. thanks!
you have configure iptables properly forward incoming udp packets port 162
user defined port (>1024
).
sudo iptables -t nat -a prerouting -i enp0s3 -p udp --dport 162 -j redirect --to-port 5678
you should replace the enp0s3
with proper network interface name. use ifconfig to find out name of ethernet interface. - eth0
. in example incoming udp packets from port 162
will forwarded to udp port 5678
.
Comments
Post a Comment