• #!/bin/bash
  • PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  • export PATH
  • beginport = "10000"
  • endport = "20000"
  • transferip = "172.31.192.41"
  • destinationip = "45.76.146.203"
  • systemctl stop firewalld.service
  • systemctl disable firewalld.service
  • yum -y install iptables-services
  • systemctl enable iptables.service
  • echo -e "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
  • sysctl -p
  • iptables -t nat -A PREROUTING -p tcp -m tcp --dport ${beginport}:${endport} -j DNAT --to-destination ${destinationip}
  • iptables -t nat -A PREROUTING -p udp -m udp --dport ${beginport}:${endport} -j DNAT --to-destination ${destinationip}
  • iptables -t nat -A POSTROUTING -d ${destinationip} -p tcp -m tcp --dport ${beginport}:${endport} -j SNAT --to-source ${transferip}
  • iptables -t nat -A POSTROUTING -d ${destinationip} -p udp -m udp --dport ${beginport}:${endport} -j SNAT --to-source ${transferip}
  • service iptables save
  • 复制代码

78299