WEB服務器轉發
公司會經常遷移一些服務器,在服務器轉移後,使用我司的DNS會批量解析,未使用的需要通知終端客戶,端口轉發能避免因爲遷移服務器帶來的大量事務量。
代碼片段(1)[全屏查看所有代碼]
1. [代碼][Shell/批處理]代碼
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #!/bin/bash if [ -z "$2" ] then echo -e "Usage: $0 SourceIP DestinationIP" exit 1 fi sed -i "s/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/g" /etc/sysctl .conf echo 1 > /proc/sys/net/ipv4/ip_forward modprobe iptable_nat modprobe ip_conntrack_ftp modprobe ip_nat_ftp for PORT in 20 21 80 do iptables -t nat -A PREROUTING -d $1 -p tcp -m tcp --dport $PORT -j DNAT --to-destination $2:$PORT iptables -t nat -A POSTROUTING -d $2 -p tcp --dport $PORT -j SNAT --to $1 done /etc/init .d /iptables save iptables -nL -t nat cat /etc/sysconfig/iptables |
原文:https://www.oschina.net/code/snippet_55803_3627