woff 發表於 2008-5-19 11:50:03

簡易 NAT 與 Firewall 設定及NAT導port

#!/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

在防火牆後端之網絡服務器 DNAT 設定先來談一談,如果我想要處理DNAT的功能時, iptables要如何下達指令?另外,你必須要知道的是,DNAT用到的是nat table的Prerouting鏈喔!不要搞錯了。
答:假設public IP 所在的接口為eth0 ,那麼你的規則就是:iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 192.168.100.10:80
假設有監視器在內網接口為eth0,監視器port 8080,那麼你的規則就是:
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 8080 -j DNAT --to-destination 192.168.100.10:8080 #video



镧久聪远 發表於 2013-11-10 00:57:28

自己知道了

btgztwao 發表於 2013-12-16 18:03:44

爱死你了,这么好的帖子要顶的

一波波冲 發表於 2014-8-28 20:39:12



   路过 看看。

wvcozre 發表於 2016-2-16 14:49:22

先顶后看~~











static/image/common/sigline.gif
开发会员系统
頁: [1]
查看完整版本: 簡易 NAT 與 Firewall 設定及NAT導port