Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 IPTABLES and NAT on Fedora Core 6 Speaker : Rex Wu Date : 2007.6.11.

Similar presentations


Presentation on theme: "1 IPTABLES and NAT on Fedora Core 6 Speaker : Rex Wu Date : 2007.6.11."— Presentation transcript:

1 1 IPTABLES and NAT on Fedora Core 6 Speaker : Rex Wu Date : 2007.6.11

2 2 Outline Introduction What is NAT Private IP Address space Iptables NAT 語法 範例 Reference Introduction What is NAT Private IP Address space Iptables NAT 語法 範例 Reference

3 3 Introduction 說明何謂 Iptables 、 NAT ,並以 Fedora Core 6 的 Iptables 指令來 實際架設 NAT 說明何謂 Iptables 、 NAT ,並以 Fedora Core 6 的 Iptables 指令來 實際架設 NAT

4 4 What is NAT ?(1) 全名: Network Address Translation 功能: 允許多個 users 使用 Private IP Address 並 透過一個 Public IP Address 連上 Internet DNAT = Destination NAT 可用來改變 Destination IP Address SNAT = Source NAT 可用來改變 Source IP Address 全名: Network Address Translation 功能: 允許多個 users 使用 Private IP Address 並 透過一個 Public IP Address 連上 Internet DNAT = Destination NAT 可用來改變 Destination IP Address SNAT = Source NAT 可用來改變 Source IP Address

5 5 What is NAT ?(2) - 圖示

6 6 Private IP Address space The IANA has reserved the following blocks of the IP address space for private internets: 10.0.0.0 - 10.255.255.255 172.16.0.0 -172.31.255.255 192.168.0.0 -192.168.255.255 The IANA has reserved the following blocks of the IP address space for private internets: 10.0.0.0 - 10.255.255.255 172.16.0.0 -172.31.255.255 192.168.0.0 -192.168.255.255

7 7 Iptables(1) Netfilter is the framework in Linux 2.4 kernels that allow for firewalling, NAT. Iptables is the userspace tools that works with the Netfilter framework ie : Netfilter is in the kernel space Iptables is in the user space Netfilter is the framework in Linux 2.4 kernels that allow for firewalling, NAT. Iptables is the userspace tools that works with the Netfilter framework ie : Netfilter is in the kernel space Iptables is in the user space - What is Netfilter/Iptables?

8 8 Iptables(2) - 架構圖

9 9 Iptables(3) - 流程圖

10 10 - 語法 語法 : iptables [-t 作用的 Table] [ 處理 Chain 的方式 ] [ 比對規則 ] [ 處理方式 ] 範例 : iptables –t nat –A POSTROUTING –o eth1 –s 192.168.1.0/24 \ –j MASQUERADE 解釋: 在 NAT table 中,新增以下規則: 規定 source IP Address=192.168.1.0~192.168.1.255 且 欲通過 eth1 介面出去的封包 ( 即 output interface = eth1) 就將其偽裝 語法 : iptables [-t 作用的 Table] [ 處理 Chain 的方式 ] [ 比對規則 ] [ 處理方式 ] 範例 : iptables –t nat –A POSTROUTING –o eth1 –s 192.168.1.0/24 \ –j MASQUERADE 解釋: 在 NAT table 中,新增以下規則: 規定 source IP Address=192.168.1.0~192.168.1.255 且 欲通過 eth1 介面出去的封包 ( 即 output interface = eth1) 就將其偽裝 Iptables(4)

11 11 ip_forward=1 功能:啟動封包轉送 法一: echo “1” > /proc/sys/net/ipv4/ip_forward 法二:修改 /etc/sysctl.conf 設定檔,如下 net.ipv4.ip_forward =1 ip_forward=1 功能:啟動封包轉送 法一: echo “1” > /proc/sys/net/ipv4/ip_forward 法二:修改 /etc/sysctl.conf 設定檔,如下 net.ipv4.ip_forward =1 Iptables(5) -NAT 的必要設定

12 12 1. ip_conntrack → IP 追蹤連線模組 2. ip_conntrack_ftp → ftp 追蹤模組 3. ip_nat_ftp 功能:允許 private side 的主機使用 ftp 服務 ( 若無載入,則 private side 的 ftp server 無法讓 public side 存取 ) 載入方法: modprobe ip_conntrack modprobe ip_conntrack_ftp modprobe ip_nat_ftp 1. ip_conntrack → IP 追蹤連線模組 2. ip_conntrack_ftp → ftp 追蹤模組 3. ip_nat_ftp 功能:允許 private side 的主機使用 ftp 服務 ( 若無載入,則 private side 的 ftp server 無法讓 public side 存取 ) 載入方法: modprobe ip_conntrack modprobe ip_conntrack_ftp modprobe ip_nat_ftp Iptables(6) -NAT 的必要載入檔

13 13 將 iptables 內所有 tables 的設定儲存在 /etc/iptables.save ex : iptables-save > /etc/iptables.save 將 iptables 中, NAT table 儲存於 /etc/iptables-nat.save ex : iptables-save -t nat > /etc/iptables-nat.save 以 /etc/iptables.save 設定檔,將 iptables 中,所有的設定重 新載入 ex : iptables-resotre < /etc/iptables.save 將 iptables 內所有 tables 的設定儲存在 /etc/iptables.save ex : iptables-save > /etc/iptables.save 將 iptables 中, NAT table 儲存於 /etc/iptables-nat.save ex : iptables-save -t nat > /etc/iptables-nat.save 以 /etc/iptables.save 設定檔,將 iptables 中,所有的設定重 新載入 ex : iptables-resotre < /etc/iptables.save Iptables(7) - 備份與還原

14 14 1. 以 iptables-restore 搭配 rc.local 使用 2. 存成 script 搭配 rc.local 使用 1. 以 iptables-restore 搭配 rc.local 使用 2. 存成 script 搭配 rc.local 使用 Iptables(8) - auto loading

15 15 Change source addresses to 1.2.3.4 ex : iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 1.2.3.4 Change source addresses to 1.2.3.4, 1.2.3.5 or 1.2.3.6 ex : iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to \ 1.2.3.4-1.2.3.6 Change source addresses to 1.2.3.4, ports 1-1023 ex : iptables -t nat -A POSTROUTING -p tcp -o eth0 -j SNAT –to \ 1.2.3.4:1-1023 Change source addresses to 1.2.3.4 ex : iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 1.2.3.4 Change source addresses to 1.2.3.4, 1.2.3.5 or 1.2.3.6 ex : iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to \ 1.2.3.4-1.2.3.6 Change source addresses to 1.2.3.4, ports 1-1023 ex : iptables -t nat -A POSTROUTING -p tcp -o eth0 -j SNAT –to \ 1.2.3.4:1-1023 NAT 語法 (1) - SNAT

16 16 Masquerade 為 SNAT 的特例,若防火牆對外使用 1. Static IP Address ,則使用 SNAT 2. Dynamic IP Address ,則建議使用 Masquerade Masquerade everything out ppp0. ex : iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE Masquerade everything out eth1. ex : iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE Masquerade 為 SNAT 的特例,若防火牆對外使用 1. Static IP Address ,則使用 SNAT 2. Dynamic IP Address ,則建議使用 Masquerade Masquerade everything out ppp0. ex : iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE Masquerade everything out eth1. ex : iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE NAT 語法 (2) - Masquerade is a specialized case of SNAT

17 17 Change destination addresses to 5.6.7.8 ex : iptables -t nat -A PREROUTING -i eth0 -j DNAT --to 5.6.7.8 Change destination addresses to 5.6.7.8, 5.6.7.9 or 5.6.7.10. ex : iptables -t nat -A PREROUTING -i eth0 -j DNAT –to \ 5.6.7.8-5.6.7.10 Change destination addresses of web traffic to 5.6.7.8, port 8080 ex : iptables -t nat -A PREROUTING -p tcp --dport 80 -i eth0 \ -j DNAT --to 5.6.7.8:8080 Change destination addresses to 5.6.7.8 ex : iptables -t nat -A PREROUTING -i eth0 -j DNAT --to 5.6.7.8 Change destination addresses to 5.6.7.8, 5.6.7.9 or 5.6.7.10. ex : iptables -t nat -A PREROUTING -i eth0 -j DNAT –to \ 5.6.7.8-5.6.7.10 Change destination addresses of web traffic to 5.6.7.8, port 8080 ex : iptables -t nat -A PREROUTING -p tcp --dport 80 -i eth0 \ -j DNAT --to 5.6.7.8:8080 NAT 語法 (3) - DNAT

18 18 範例 請參考 http://ms11.voip.edu.tw/~rex/FC6_nat.html

19 19 Reference Linux 防火牆與 NAT 主機 http://linux.vbird.org/linux_server/0250simple_firewall.php Linux 2.4 NAT HOWTO http://www.netfilter.org/documentation/HOWTO/NAT- HOWTO.html Linux 防火牆入門相關網站 http://linux.tnc.edu.tw/techdoc/firewall/ref-url.html Red Hat Enterprise Linux 4 安全性設定手冊 http://web.mit.edu/rhel-doc/4/RH-DOCS/rhel-sg-zh_tw- 4/index.html Linux 防火牆與 NAT 主機 http://linux.vbird.org/linux_server/0250simple_firewall.php Linux 2.4 NAT HOWTO http://www.netfilter.org/documentation/HOWTO/NAT- HOWTO.html Linux 防火牆入門相關網站 http://linux.tnc.edu.tw/techdoc/firewall/ref-url.html Red Hat Enterprise Linux 4 安全性設定手冊 http://web.mit.edu/rhel-doc/4/RH-DOCS/rhel-sg-zh_tw- 4/index.html


Download ppt "1 IPTABLES and NAT on Fedora Core 6 Speaker : Rex Wu Date : 2007.6.11."

Similar presentations


Ads by Google