Implement iptables initialization in Ubuntu

Source: Internet
Author: User
Brief description: there is no ready-made iptables script in Ubuntu like in The RedHat series. You need to write it manually. So let's get one. One is provided below. Second, you need to install attachment software to control sysV. For example, rcconf can be automatically run by adding the script to/etc/init. d. The script is as follows :#! /Bin/bashcase "$1" instart)

Brief description: there is no ready-made iptables script in Ubuntu like in The RedHat series. You need to write it manually. So let's get one. One is provided below. Second, install attachment software to control sys V.

. For example, rcconf can be automatically run by adding the script to/etc/init. d.

The script is as follows:


#! /Bin/bash
Case "$1" in
Start)
Echo-n "Staring to write your Iptbales :..."
/Sbin/iptables-P INPUT DROP
/Sbin/iptables-P OUTPUT ACCEPT
/Sbin/iptables-a input-I lo-j ACCEPT
/Sbin/iptables-a input-p icmp-m icmp -- icmp-type 8-j DROP
/Sbin/iptables-a input-p tcp-m tcp -- dport 21-j ACCEPT
/Sbin/iptables-a input-p tcp-m tcp -- dport 22-j ACCEPT
/Sbin/iptables-a input-p tcp-m tcp -- dport 80-j ACCEPT
/Sbin/iptables-a input-p tcp-m tcp -- dport 3306-j ACCEPT
/Sbin/iptables-a input-p all-m state -- state ESTABLISHED, RELATED-j ACCEPT
/Sbin/iptables-a input-p all-m state -- state INVALID, NEW-j DROP
Echo "OK"

;;
Stop)
Echo-n "Cleaning your Iptables :..."
/Sbin/iptables-F
/Sbin/iptables-X
/Sbin/iptables-Z
Echo "OK"
;;
Restart)
Echo-n "Cleaning your Iptables :..."
/Sbin/iptables-F
/Sbin/iptables-X
/Sbin/iptables-Z
Echo "OK"
Echo-n "Staring to write your Iptbales :..."
/Sbin/iptables-P INPUT DROP
/Sbin/iptables-P OUTPUT ACCEPT
/Sbin/iptables-a input-I lo-j ACCEPT
/Sbin/iptables-a input-p icmp-m icmp -- icmp-type 8-j DROP
/Sbin/iptables-a input-p tcp-m tcp -- dport 20-j ACCEPT
/Sbin/iptables-a input-p tcp-m tcp -- dport 22-j ACCEPT
/Sbin/iptables-a input-p tcp-m tcp -- dport 80-j ACCEPT
/Sbin/iptables-a input-p tcp-m tcp -- dport 3306-j ACCEPT
/Sbin/iptables-a input-p all-m state -- state ESTABLISHED, RELATED-j ACCEPT
/Sbin/iptables-a input-p all-m state -- state INVALID, NEW-j DROP
Echo "OK"
;;
*)
Echo "Usage: $0 {start | stop | restart }"
Esac

Exit 0

Add to other startup levels

Apt-get install rcconf

By kook@52zhe.cn
Address: http://www.52zhe.cn/read.php/156.htm
Copyright: GNU. During reprinting, please note that "reposted" owes me a meal and redeem it when you come to the next day! Thank you for your cooperation!

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.