How to configure traffic from a specific IP hardcoded to an IP to forward to another IP:PORT using iptables?

Your NAT rule seems ok, but have you also added an ACCEPT rule for this traffic?

Otherwise, NAT will kick in finely, but then the resulting packet will silently be dropped...


Update:

You need this rule in the FORWARD chain (which is where packets going thorugh the firewall but not directly related to it are processed).

FORWARD rules are applied after PREROUTING rules (like NAT), so when this rule is applied the packets will appear like they're coming from the original IP but directed to the modified new destination IP. The rule should thus be somewhat like this:

/sbin/iptables -A FORWARD -s $CUSTIP -d $NEW_SERVER_IP -j ACCEPT

I presume you're using the linux box as a router and that this linux box can see the new IP.

I believe that the NAT table only kicks in when /proc/sys/net/ipv4/ip_forward is set to 1. To make this persistent, put the following line in /etc/sysctl.conf:

net.ipv4.ip_forward = 1

There is a sysctl setting preventing dnat to loopback. replace eth0 below with your external interface traffic is coming in on.

To allow it

sysctl -w net.ipv4.conf.eth0.route_localnet=1

or

echo 1 > /proc/sys/net/ipv4/conf/eth0/route_localnet

and to check the setting.

cat /proc/sys/net/ipv4/conf/eth0/route_localnet

now you can dnat to 127.0.0.1