linux防火牆實現連接埠轉寄、連接埠映射及雙向通路____linux

來源:互聯網
上載者:User

iptables實現連接埠轉寄、連接埠映射及雙向通路其實不難配置,看下文:

允許資料包轉寄:

#echo 1 > /proc/sys/net/ipv4/ip_forward  

轉寄TCP 8081到xx.xx.xx.xx:

#iptables -t nat -I PREROUTING -p tcp –dport 80 -j DNAT –to xx.xx.xx.xx  

使轉寄資料包實現“雙向通路”,給資料包設定一個正確的返回通道:

#iptables -t nat -I POSTROUTING -p tcp –dport 8080 -j MASQUERADE  

表示將規則儲存到/etc/sysconfig/iptables檔案

#service iptables save  

重啟iptables使剛才添加的規則生效

#service iptables restart  

如果執行上述命令,依然不能轉寄,可能由於iptables服務沒有停止,命令無法寫入iptables檔案,應先執行service iptables stop,再執行上述命令,最後service iptables start再啟動服務

由於Linux防火牆預設是關閉3306連接埠。因此,若要能夠訪問3306連接埠,可以用兩種方式,一個是關閉防火牆,另一個就是讓防火牆開放3306連接埠。

開放3306連接埠的解決步驟如下:

1、修改/etc/sysconfig/iptables檔案,增加如下一行:

-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT

2、重啟防火牆,這裡有兩種方式重啟防火牆

a) 重啟後生效

開啟: chkconfig iptables on

關閉: chkconfig iptables off

b) 即時生效,重啟後失效

開啟: service iptables start

關閉: service iptables stop

資料庫映射成功。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.