Requirement was to run a process on a server on a new port but the original port was hard-coded into the client so we needed to redirect all traffic bound for the original port to the new port.
First check the IP Forwarding is enabled.
sysctl net.ipv4.ip_forward
if IP forwarding is not enabled then:
echo "net.ipv4.ip_forward = 1"|sudo tee /etc/sysctl.d/99-ipforward.conf
sysctl -p /etc/sysctl.d/99-ipforward.conf
Then add an iptables REDIRCT from the old port 1111 to the new port 2222
iptables -t nat -A PREROUTING -p tcp --dport 1111 -j REDIRECT --to-port 2222
Check it with:
iptables -t nat -L -n