Simple setting of IPtables firewall in Linux

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.