|
1 #! /bin/sh
2
3 trusthost='192.168.0.20'
4 internal_net='192.168.0.0/24'
5 my_internal_ip='192.168.0.1'
6
7 echo 1 > /proc/sys/net/ipv4/ip_forward
8
9 ##############
10 #Flush & Reset
11 ##############
12 /sbin/iptables -F
13 /sbin/iptables -t nat -F
14 /sbin/iptables -X
15
16 ##############
17 #Deafult Rule
18 ##############
19 /sbin/iptables -P INPUT DROP
20 /sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
21
22 /sbin/iptables -P OUTPUT ACCEPT
23
24 /sbin/iptables -P FORWARD DROP
25 /sbin/iptables -A FORWARD -i eth1 -o eth0 -s $internal_net -j ACCEPT
26 /sbin/iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
27
28 #########
29 #loopback
30 #########
31 /sbin/iptables -A INPUT -i lo -j ACCEPT
32
33 ###############################
34 #ICMP trusthost->my_internal_ip
35 ###############################
36 /sbin/iptables -A INPUT -p icmp --icmp-type echo-request -s $trusthost -d $my_internal_ip -j ACCEPT
37 ###############################
38 #ICMP my_internal_ip->trusthost
39 ###############################
40 /sbin/iptables -A INPUT -p icmp --icmp-type echo-reply -s $trusthost -d $my_internal_ip -j ACCEPT
41 ###############################
42 #ssh trusthost-> my_internal_ip
43 ###############################
44 /sbin/iptables -A INPUT -p tcp --syn -m state --state NEW -s $trusthost -d $my_internal_ip --dport 22 -j ACCEPT
45 #################
46 #SNAT(masquerade)
47 #################
48 /sbin/iptables -t nat -A POSTROUTING -o eth0 -s $internal_net -j MASQUERADE
49
50 #################
51 #mangle table
52 #################
53 #Sample for TOS
54 /sbin/iptables -A PREROUTING -t mangle -p tcp --sport 22 -j TOS --set-tos Minimize-Delay
55 /sbin/iptables -A PREROUTING -t mangle -p tcp --sport 80 -j TOS --set-tos Maximize-Throughput
56 #Sample for DSCP,ECN,MARK
57 /sbin/iptables -A PREROUTING -t mangle -p tcp --sport 80 -j DSCP --set-dscp-class EF
58 /sbin/iptables -A PREROUTING -t mangle -p tcp --sport 80 -j ECN --ecn-tcp-remove
59 /sbin/iptables -A PREROUTING -t mangle -p tcp --sport 80 -j MARK --set-mark 15
60
61 ################################################
62 #Blocking Private Address
63 ################################################
64 /sbin/iptables -A OUTPUT -o eth0 -d 10.0.0.0/8 -j DROP
65 /sbin/iptables -A OUTPUT -o eth0 -d 176.16.0.0/12 -j DROP
66 /sbin/iptables -A OUTPUT -o eth0 -d 192.168.0.0/16 -j DROP
67 /sbin/iptables -A OUTPUT -o eth0 -d 127.0.0.0/8 -j DROP
68
69 #########
70 #logging
71 #########
72 /sbin/iptables -N LOGGING
73 /sbin/iptables -A LOGGING -j LOG --log-level warning --log-prefix "DROP:" -m limit
74 /sbin/iptables -A LOGGING -j DROP
75 /sbin/iptables -A INPUT -j LOGGING
76 /sbin/iptables -A FORWARD -j LOGGING
|
|