Ben's notes

Linux, Unix, network, radio...

User Tools

Site Tools


Temporary redirect traffic to other host

I've used the steps below to temporary redirect IP traffic, during migration to another host. Tested on CentOS 6.x

  • Configure the kernel to allow forwarding:
    echo 1 > /proc/sys/net/ipv4/ip_forward
  • Route traffic to destination:
    iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination
  • Allow forwarding:
    iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
    iptables -A FORWARD -p tcp -d --dport 443 -j ACCEPT
  • Masquerade outgoing connections:
    iptables -t nat -A POSTROUTING -j MASQUERADE
  • Show active rules:
    iptables -nvL -t nat
  • Delete rules:
    • Find line numbers:
      iptables -nvL -t nat --line-numbers
    • Delete rules using line number:
      iptables -t nat -D <num>
      iptables -D FORWARD <num>
migration_temporary_redirect.txt · Last modified: 2021/10/09 15:14 by