Article Title: Simple setting of IPtables firewall in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Iptables. rule is the general rule of firewall;
Iptables. allow is a sufficient host to enter;
Iptables. deny is a host that is not allowed to be placed;
The iptables. allow Code is as follows:
#! /Bin/bash
# This is an esay firewall.
# The inside interface. if you don't have this one
# And you must let this be black ex> INIF = ""
INIF = "eth0"
INNET = "192.168.160.0/20"
#2.0 load the right module
PATH =/sbin:/bin:/usr/sbin:/usr/bin
Export PATH EXTIF INIF INNET
Modprobe ip_tables>/dev/null 2> & 1
Modprobe iptable_nat>/dev/null 2> & 1
Modprobe ip_nat_ftp>/dev/null 2> & 1
Modprobe ip_nat_irc>/dev/null 2> & 1
Modprobe ip_conntrack>/dev/null 2> & 1
Modprobe ip_conntrack_ftp>/dev/null 2> & 1
Modprobe ip_conntrack_irc>/dev/null 2> & 1
#3.0 clear iptables rule
/Sbin/iptables-F
/Sbin/iptables-X
/Sbin/iptables-Z
/Sbin/iptables-F-t nat
/Sbin/iptables-X-t nat
/Sbin/iptables-Z-t nat
/Sbin/iptables-P INPUT DROP
/Sbin/iptables-P OUTPUT ACCEPT
/Sbin/iptables-P FORWARD ACCEPT
/Sbin/iptables-t nat-P PREROUTING ACCEPT
/Sbin/iptables-t nat-P POSTROUTING ACCEPT
/Sbin/iptables-t nat-P OUTPUT ACCEPT
#4.0 start loading trusted and denied file.
If [-f/usr/local/virus/iptables. allow]; then
Sh/usr/local/virus/iptables. allow
Fi
If [-f/usr/local/virus/iptables. deny]; then
Sh/usr/local/virus/iptables. deny
Fi
#5.0 if the following file exist, please executed
If [-f/usr/local/virus/httpd-err/iptables. http]; then
Sh/usr/local/virus/httpd-err/iptables. http
Fi
#6.0 allow icmp data packet and the establishd data
/Sbin/iptables-a input-m state -- state ESTABLISHED, RELATED-j ACCEPT
AICMP = "0 3 3/4 4 11 12 14 16 18"
For tyicmp in $ AICMP
Do
/Sbin/iptables-a input-I $ EXTIF = "eth0"-p icmp -- icmp-type $ tyicmp-j ACCEPT
Done
[1] [2] Next page