Common rules for iptables learning

Source: Internet
Author: User
The following describes how to define a simple iptables rule: Step 1: clear all defined rules and user-defined rules # iptables-F # iptables-X # iptables-Z Step 2: set the default policy for security and aspect control, set all default policies to DROP # iptables-PINPUTDROP # iptables-PF

The following is a simple example:IptablesSteps and methods for rule definition:

Step 1: Understand all defined rules and user-defined rules

# Iptables-F
# Iptables-X
# Iptables-Z

Step 2: set the default policy. here, all the default policies are set to DROP for security and aspect control)

# Iptables-P INPUT DROP
# Iptables-P FORWARD DROP
# Iptables-P OUTPUT DROP

Step 3: disable Server ping

#/Bin/echo "1">/proc/sys/net/ipv4/icmp_echo_ignore_all

Step 4: disable ip forwarding

#/Bin/echo "0">/proc/sys/net/ipv4/ip_forward

Step 5: allow local loops

# Iptables-a input-I lo-j ACCEPT
# Iptables-a output-o lo-j ACCEPT

Step 6: ensure that the tcp connection is a valid syn packet

# Iptables-a input-I eth0-p tcp! -- Syn-m state -- state NEW-j DROP

Step 7: Open the ssh port (port 22)
# Iptables-a input-I eth0-p tcp -- sport 22-m state -- stateESTABLISHED-j ACCEPT
# Iptables-a output-o eth0-p tcp -- dport 22-m state -- stateNEW, ESTABLISHED-j ACCEPT

Step 8: Open the ftp port (Port 21)

# Iptables-a input-I eth0-p tcp -- sport 21-m state -- stateESTABLISHED-j ACCEPT
# Iptables-a output-o eth0-p tcp -- dport 21-m state -- stateNEW, ESTABLISHED-j ACCEPT

Step 9: Open the www port (port 80)

# Iptables-a input-I eth0-p tcp -- sport 80-m state -- stateESTABLISHED-j ACCEPT
# Iptables-a output-o eth0-p tcp -- dport 80-m state -- stateNEW, ESTABLISHED-j ACCEPT

Step 10: Save

# Iptables-save> iptables-script
# Iptables-restore iptables-script

Or

# Service iptables save

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.