顯示頁面舊版反向連結Fold/unfold all回到頁頂 本頁是唯讀的,您可以看到原始碼,但不能更動它。您如果覺得它不應被鎖上,請詢問管理員。 ====== Linux IP 分享(NAT)設定 ====== ===== 必須安裝的模組 ===== * iptables (iptables-1.2.11-3.1.RHEL4) ===== 設定程序 ===== * <code sh>vi /etc/sysctl.conf</code><file> : net.ipv4.ip_forward = 1 : </file> * <code sh>sysctl -p /etc/sysctl.conf cat /proc/sys/net/ipv4/ip_forward </code> * <code sh>lsmod | grep ip_tables </code> * 如果沒有出現 ip_tables 就輸入 modprobe ip_tables 然後再確認一次 * 規劃好預計達成的規則 - 來自 192.168.0.* 的 IP, 自動轉到 eth0 介面出去 - 來自 eth0 的 8080 自動轉到 192.168.0.241:80 - 來自 eth0 的 8081 自動轉到 192.168.0.22:8080 * <code sh>vi /etc/sysconfig/iptables</code><file> : *nat :PREROUTING ACCEPT [0:0] :POSTROUTING ACCEPT [0:0] :OUTPUT ACCEPT [0:0] [0:0] -A POSTROUTING -s 192.168.0.0/255.255.255.0 -o eth0 -j MASQUERADE [0:0] -A PREROUTING -p tcp --dport 8080 -j DNAT --to 192.168.0.241:80 [0:0] -A PREROUTING -p tcp --dport 8081 -j DNAT --to-destination 192.168.0.22:8080 COMMIT : </file> <note> * CentOS 6 (RHEL6) 增加一些安全的控管, 因此在 *filter 的 :FORWARD 項目要增加開放 nat 的來源資訊 * 例如 來自 eth1 都允許 nat 出去就可增加以下的設定資料<file> *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] -A FORWARD -i eth1 -j ACCEPT -A FORWARD -o eth1 -j ACCEPT :OUTPUT ACCEPT [0:0] </file> </note> * <code sh>service iptables restart</code> ===== 參考資料 ===== * http://www.adj.idv.tw/server/linux_nat.htm * http://www.linuxtopia.org/online_books/rhel6/rhel_6_security_guide/rhel_6_security_sect-Security_Guide-Firewalls-FORWARD_and_NAT_Rules.html {{tag>linux iptables nat 網路}} tech/nat.txt 上一次變更: 2016/03/27 17:59由 jonathan