NAT and blocking all but Port 22 1.0

NAT and blocking all but Port 22 is a simple iptables firewall script.
NAT and blocking all but Port 22 is a simple iptables firewall script.

Sample:

# Internal and External Devices
dev_world=ppp0
dev_int=eth0

# Firewall IP
addr_int=192.168.1.1

# Internal Net
net_int=192.168.1.0/24

###################################################
# Load Modules
insmod ip_tables
insmod ip_conntrack
insmod ip_conntrack_ftp
insmod ipt_state
insmod iptable_nat
insmod ipt_MASQUERADE

###################################################
# Delete all Rules in Filtertable
iptables -F

###################################################
# Define new chains
iptables -N BLOCK
iptables -N EXT-INT
iptables -N INT-EXT
iptables -N ICMP-DENY
iptables -N INT-IF
iptables -N EXT-IF

###################################################

iptables -A BLOCK -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A BLOCK -m state --state NEW -i ! $dev_world -j ACCEPT
iptables -A BLOCK -j DROP

iptables -A INPUT -j BLOCK
iptables -A FORWARD -j BLOCK

###################################################
# Point to chains
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -i $dev_int -s $net_int -j INT-IF
iptables -A INPUT -d ! $addr_int -i $dev_world -s ! $net_int -j EXT-IF
iptables -A INPUT -j DROP

iptables -A FORWARD -d ! $net_int -i $dev_world -s $net_int -j INT-EXT
iptables -A FORWARD -d $net_int -i $dev_int -s ! $net_int -j EXT-INT
iptables -A FORWARD -j DROP

iptables -A OUTPUT -j ACCEPT

###################################################
# Chain Rules
iptables -A EXT-INT -j DROP

iptables -A EXT-IF -i ! $dev_world -j DROP
iptables -A EXT-IF -p tcp --dport 22 -j ACCEPT
iptables -A EXT-IF -p tcp --dport 5901 -j ACCEPT
iptables -A EXT-IF -p tcp --dport 1024: -j ACCEPT
iptables -A EXT-IF -p udp --dport 1024: -j ACCEPT
iptables -A EXT-IF -j DROP

iptables -A INT-IF -j ACCEPT

###################################################
# NAT Rules
# Standard Routing
iptables -A POSTROUTING -t nat -o $dev_world -j MASQUERADE -s $net_int

# Port Forwarding
#iptables -A PREROUTING -t nat -p tcp -d 192.168.1.1 --dport 5901 --to 192.168.1.2:5901 -j DNAT

##################################################
# Enable IP-Forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward)

last updated on:
February 14th, 2007, 17:34 GMT
price:
FREE!
homepage:
www.linuxguruz.com
license type:
GPL (GNU General Public License) 
developed by:
Peter Rektorschek
category:
ROOT \ System \ Networking
NAT and blocking all but Port 22
Download Button

In a hurry? Add it to your Download Basket!

user rating

UNRATED
0.0/5
 

0/5

Rate it!

Add your review!

SUBMIT