服務器A:192.168.1.7
服務器B: 192.168.1.160shell
實現將本機(192.168.1.7:7410)端口流量轉發給(192.168.1.160:9200)。服務器
# 1.1 會話 echo 1 > /proc/sys/net/ipv4/ip_forward # 1.2 永久 vi /etc/sysctl.conf 添加以下代碼: net.ipv4.ip_forward=1 重啓network服務 systemctl restart network 查看是否修改爲功 sysctl net.ipv4.ip_forward
modprobe ip_conntrack
iptables -P INPUT ACCEPT iptables -P OUTPUT ACCEPT iptables -P FORWARD ACCEPT
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -t nat -A PREROUTING -d 192.168.1.7/32 -p tcp --dport 7410 -j DNAT --to-destination 192.168.1.160:9200; iptables -t nat -A POSTROUTING -d 192.168.1.160/32 -p tcp --dport 9200 -j SNAT --to-source 192.168.1.7;
service iptables save service iptables restart
telnet 192.168.1.7:7410
### 中止 service iptables stop ### 查看狀態 service iptables status ### 備份 iptables-save > ables.bak ### 還原 iptables-restore < iptables.bak