TShopping

 找回密碼
 註冊
搜索
查看: 5013|回復: 6
打印 上一主題 下一主題

[教學] 簡易 NAT 與 Firewall 設定及NAT導port

    [複製鏈接]
跳轉到指定樓層
1#
發表於 2008-5-19 11:50:03 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
 
Push to Facebook
#!/bin/bash

# ============================================================================

# network interface define

INTERNET_NIC=eth0 # to internet, eg eth0 or ppp+
INSIDE_NIC=eth1 # lan

INSIDE_NET=192.168.1.0/24 # internal network area

# ============================================================================

# firewall module

modprobe ip_tables
modprobe ip_conntrack
modprobe ip_conntrack_ftp
modprobe ip_conntrack_irc

modprobe ip_nat_ftp
modprobe ip_nat_irc

# ============================================================================

# reset main firewall policy

iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP

iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
iptables -t nat -P OUTPUT ACCEPT

iptables -t mangle -P INPUT ACCEPT
iptables -t mangle -P OUTPUT ACCEPT
iptables -t mangle -P FORWARD ACCEPT
iptables -t mangle -P PREROUTING ACCEPT
iptables -t mangle -P POSTROUTING ACCEPT
iptables -t mangle -P OUTPUT ACCEPT

# ============================================================================

# reset main firewall rule

iptables -F -t filter
iptables -F -t nat
iptables -F -t mangle

iptables -X -t filter
iptables -X -t nat
iptables -X -t mangle

# ============================================================================

# allow ESTABLISHED,RELATED packet and lo loopback

iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -i $INSIDE_NIC -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# ============================================================================

# drop port scan ...

# NMAP FIN/URG/PSH
iptables -A INPUT -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP

# Xmas Tree
iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP

# Another Xmas Tree
iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP

# Null Scan(possibly)
iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP

# SYN/RST
iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP

# SYN/FIN -- Scan(possibly)

iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP

# ============================================================================

# main firewall rule, open ports...

iptables -A INPUT -i $INTERNET_NIC -p tcp --dport 22 -m state --state NEW -j ACCEPT

iptables -A INPUT -i $INTERNET_NIC -p tcp --dport 80 -m state --state NEW -j ACCEPT

# ============================================================================

# nat

# forward rule

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

iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -s $INSIDE_NET -j ACCEPT

iptables -A POSTROUTING -t nat -o $INTERNET_NIC -j MASQUERADE

[size=17.3333px]在防火牆後端之網絡服務器 DNAT 設定
先來談一談,如果我想要處理DNAT的功能時, iptables要如何下達指令?另外,你必須要知道的是,DNAT用到的是nat table的Prerouting鏈喔!不要搞錯了。

答:
假設public IP 所在的接口為eth0 ,那麼你的規則就是:
  1. iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 192.168.100.10:80
複製代碼

假設有監視器在內網接口為eth0,監視器port 8080,那麼你的規則就是:
  1. iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 8080 -j DNAT --to-destination 192.168.100.10:8080 #video
複製代碼





 

臉書網友討論
2#
發表於 2013-11-10 00:57:28 | 只看該作者
自己知道了  

版主招募中

3#
發表於 2013-12-16 18:03:44 | 只看該作者
爱死你了,这么好的帖子要顶的


4#
發表於 2014-8-28 20:39:12 | 只看該作者


   路过 看看。


5#
發表於 2016-2-16 14:49:22 | 只看該作者
先顶后看~~












开发会员系统


*滑块验证:
您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2024-4-19 22:55 , Processed in 0.348859 second(s), 22 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表