Agnus Dei (jackal) wrote,
Agnus Dei
jackal

How to reroute all TCP track to a given port to another server using iptables.

[root@fdsfdsfds ~]# cat /tmp/foo.sh
#!/bin/bash

LOCALPORT=443
REMOTEIP=123.123.123.123  # external IP for remove server
REMOTEPORT=443

iptables -F
iptables -t nat -F
iptables -X

iptables -t nat -A PREROUTING  -p tcp -m tcp --dport $LOCALPORT -j DNAT --to-destination $REMOTEIP:$REMOTEPORT
iptables -t nat -A POSTROUTING -j MASQUERADE
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

  • 0 comments