In Linux, firewall simple settings-Linux Enterprise Application-Linux server application information. The following is a detailed description. 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
#7.0 open the other service ports
/Sbin/iptables-a input-p TCP-I $ EXTIF = "eth0" -- dport 25-j ACCEPT # SMTP
/Sbin/iptables-a input-p TCP-I $ EXTIF = "eth0" -- dport 53-j ACCEPT # DNS
/Sbin/iptables-a input-p TCP-I $ EXTIF = "eth0" -- dport 80-j ACCEPT # WWW
/Sbin/iptables-a input-p TCP-I $ EXTIF = "eth0" -- dport 110-j ACCEPT # POP3
/Sbin/iptables-a input-p TCP-I $ EXTIF = "eth0" -- dport 113-j ACCEPT # AUTH
/Sbin/iptables-a input-p TCP-I $ EXTIF = "eth0" -- dport 22222-j ACCEPT # SSH
/Sbin/iptables-a input-p UDP-I $ EXTIF = "eth0" -- dport 138-j ACCEPT #138
/Sbin/iptables-a input-p TCP-I $ EXTIF = "eth0" -- dport 139-j ACCEPT #139
/Sbin/iptables-a input-p UDP-I $ EXTIF = "eth0" -- dport 137-j ACCEPT #137
/Sbin/iptables-a input-p TCP-I $ EXTIF = "eth0" -- dport 445-j ACCEPT #445
The iptables. allow Code is as follows:
#! /Bin/bash
# This program is used to allow some IP or hosts to access your server
/Sbin/iptables-a input-I $ EXTIF = "eth0"-s 192.168.161.242-j ACCEPT
/Sbin/iptables-a input-I $ EXTIF = "eth0"-s 192.168.160.178-j ACCEPT
/Sbin/iptables-a input-I $ EXTIF = "eth0"-s 192.168.160.218-j ACCEPT
The iptables. deny code is as follows:
#! /Bin/bash
# This script will deny some IPs that I don't want in IN
/Sbin/iptables-a input-I $ EXTIF = "eth0"-s 192.168.160.242-j DROP
All the preceding three files are stored in the/usr/local/virus/iptables directory. Modify the/etc/rc. d/rc. local file as follows:
#! /Bin/sh
#
# This script will be executed * after * all the other init scripts.
# You can put your own initialization stuff in here if you don't
# Want to do the full Sys V style init stuff.
Touch/var/lock/subsys/local
#1. Starting firewall settings
/Usr/local/virus/iptables. rule
The above is the simple setting of firewall in linux.
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