I have a server that is receiving syslog traffic. Many of my devices can only send to the default udp/514 port. My syslog server can't run on ports <1024 and is running on 5000. I have a nat PREROUTING REDIRECT on the system and it's working great.

I do have a few Aruba wireless controllers that I want to direct to a different port. I'm trying to redirect packets with source addreess to port 5008. Here is the complete config.

:PREROUTING ACCEPT [53851:21198923]
:INPUT ACCEPT [53851:21198923]
:OUTPUT ACCEPT [1227:8988526]
:POSTROUTING ACCEPT [1227:8988526]
# Completed on Thu Sep 30 14:52:43 2021
# Generated by iptables-save v1.8.4 on Thu Sep 30 14:52:43 2021
-A PREROUTING -s -p udp -m udp --dport 514 -j REDIRECT --to-ports 5008
-A PREROUTING -p udp -m udp --dport 514 -j REDIRECT --to-ports 5000
# Completed on Thu Sep 30 14:52:43 2021
# Generated by iptables-save v1.8.4 on Thu Sep 30 14:52:43 2021
:INPUT ACCEPT [53852:21199096]
:OUTPUT ACCEPT [1234:8990186]
-A INPUT -s -p udp -m udp --dport 514 -j ACCEPT

The redirect to udp/5000 is working great, but everything is getting redirected to 5000. The Aruba traffic from is failing to get pushed to udp/5008.

If I issue the command: iptables -t nat -L -n -v --line-number . It confirms that zero bytes are hitting Line 1 and everything is hitting Line 2.

I figure the order is important and the more-specific line should be ahead of the generic line (as show above). I tried reversing them and it didn't help.

Syslog on UDP is unidirectional and stateless, so you would think this would be the easiest NAT in the world.

Has anyone done this kind of config? This is all on-box and I'm just trying to separate out my incoming Aruba syslog message from all my other messages.


  • 1
    You probably need to flush out the conntrack rules in the kernel so they get re-created from the new iptables you've added. If the syslog traffic is consistent (as in packets are coming in within every 30 seconds or something, which is the default TTL for conntrack entries before they expire (tweakable via a kernel setting)), the older conntrack entries will remain active and so traffic will keep hitting the old port. See serverfault.com/questions/367626/… for a quick example of how to use conntrack.
    – parkamark
    Sep 30 at 16:18
  • My system doesn't have conntrack. What I did do is service iptables restart. That clears the counters. Right now I'm assuming that also clears the connection table. It still doesn't work. No hits on the first line item. The syslog server still sees no packets arriving on udp/5008. Sep 30 at 18:09
  • Can you check with packet capture tool (like tcpdump or tshark) that you indeed are receiving traffic from network to UDP port 514? Is the DESTINATION address correct? BTW, what is the INPUT rule for? It is superfluous.
    – Tomek
    Oct 1 at 7:09
  • @Tomek I used 'tcpdump udp -nnX port 514 and net' and yes, I am getting plenty of syslog packets in. The INPUT rule is there because I didn't realize the default condition to pass all traffic was in place and I was just trying anything to get this running. Please be kind and remember, I'm rather new to iptables. Thanks! Oct 1 at 11:51
  • 1
    For the love of pete. That did it. conntrack -L confirmed the problem. conntrack -F solved the problem. I was making that assumption because of how dumb it would be that it needed a separate step. Does Linux want to destroy people’s lives? :-) Thank you for your help! Oct 1 at 20:24

Redirect port 514 to 5000 and make it work on local machine

If you are creating the iptables rule on your syslog server use below command:

iptables -t nat -A OUTPUT -o lo -p tcp --dport 514 -j REDIRECT --to-port 5000


iptables -A PREROUTING -t nat -i eth0<Incoming-interface> -p tcp --dport 514 -j REDIRECT --to-port 5000

redirect an incoming connection to a different IP address on a specific port

If you are trying to do port forwarding to another IP and your server(I called it firewall) which receiving UDP/514 is behind client and Syslog server like scenario on my github, you mus do iptables port forwarding with tree setp:

simple example scenario:

 | client: | -->   | firewall enp0s3: | --> | Syslog |

1- Enable IP forwarding

sudo sysctl -w net.ipv4.ip_forward=1

2- PREROUTING for the incoming traffic to the firewall

sudo iptables -t nat -A PREROUTING -d -i enp0s8  -p tcp --dport 514 -j DNAT --to-destination 

3- POSTROUTING for the leaving traffic to Syslog server

sudo iptables -t nat -A POSTROUTING -o enp0s3 -p tcp --dport 514 -d -j SNAT --to-source

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.