CentOS系統中使用iptables設定連接埠轉寄

來源:互聯網
上載者:User

   將本地介面IP 61.144.14.72 的3389連接埠 轉寄到 116.6.73.229的3389

  (主要訪問到61.144.14.72的3389連接埠,就會跳轉到116.6.73.229的3389)

  【步驟】

  1、 首先應該做的是/etc/sysctl.conf設定檔的 net.ipv4.ip_forward = 1 預設是0 這樣允許iptalbes FORWARD。

  2、 service iptables stop 關閉防火牆

  3、 重新設定規則

  iptables -t nat -A PREROUTING --dst 61.144.14.72 -p tcp --dport 3389 -j DNAT --to-destination 116.6.73.229:3389

  iptables -t nat -A POSTROUTING --dst 116.6.73.229 -p tcp --dport 3389 -j SNAT --to-source 61.144.14.72

  service iptables save

  將當前規則儲存到 /etc/sysconfig/iptables

  若你對這個檔案很熟悉直接修改這裡的內容也等於命令列方式輸入規則。

  5、 啟動iptables 服務, service iptables start

  可以寫進指令碼,裝置啟動自動運行;

  # vi /etc/rc.local

  #!/bin/sh

  #

  # This script will be executed *after* all the other init scripts.

  # You can put your own initialization stuff in here if you don't

  # want to do the full Sys V style init stuff.

  touch /var/lock/subsys/local

  sh /root/myshipin.log

  ---------------------------------------------------------------------

  vi myshipin.log

  #!/bin/sh

  #

  # This script will be executed *after* all the other init scripts.

  # You can put your own initialization stuff in here if you don't

  # want to do the full Sys V style init stuff.

  iptables -F -t nat iptables -t nat -A PREROUTING --dst 61.144.14.72 -p tcp --dport 3389 -j DNAT --to-destination 116.6.73.229:3389

  iptables -t nat -A POSTROUTING --dst 116.6.73.229 -p tcp --dport 3389 -j SNAT --to-source 61.144.14.72

  ~

  ----------------------------------------------------------------

  TCP

  iptables -t nat -A PREROUTING --dst 61.144.14.87 -p tcp --dport 9304 -j DNAT --to-destination 10.94.143.204:9304

  iptables -t nat -A POSTROUTING --dst 10.94.143.204 -p tcp --dport 9304 -j SNAT --to-source 61.144.14.87

  UDP

  iptables -t nat -A PREROUTING --dst 61.144.14.87 -p udp --dport 9305 -j DNAT --to-destination 10.94.143.204:9305

  iptables -t nat -A POSTROUTING --dst 10.94.143.204 -p udp --dport 9305 -j SNAT --to-source 61.144.14.87

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.