How to disable ping and iptables configuration for CentOS ECs

Source: Internet
Author: User

I. How to correctly set centos iptables and disable PING

1. Clear existing iptables rules

Iptables-F iptables-X iptables-Z

2. iptables configuration. Here we use the default firewall rules officially provided by centos in the small three resources network. We only need to add or delete unnecessary ports to maximize compatibility with various environments, reduces the Load Caused by incompatibility with the firewall.

First, run the command vi/etc/sysconfig/iptables to add the following content.

# Firewall configuration written by system-config-securitylevel

# Manual customization of this file is not recommended.

* Filter

: Input accept [0: 0]

: Forward accept [0: 0]

: Output accept [0: 0]

: RH-Firewall-1-INPUT-[0: 0]

-A input-j RH-Firewall-1-INPUT

-A forward-j RH-Firewall-1-INPUT

# Allow Local localhost access

-A RH-Firewall-1-INPUT-I lo-j ACCEPT

# Whether to disable ping. If not, add the # sign at the beginning of the following sentence.

-A RH-Firewall-1-INPUT-p icmp -- icmp-type any-j ACCEPT

# Allow established or related connections

-A RH-Firewall-1-INPUT-m state -- state ESTABLISHED, RELATED-j ACCEPT

# Open Port 22 of s. s. h (open other ports by yourself according to the following rules)

-A RH-Firewall-1-INPUT-m state -- state NEW-m tcp-p tcp -- dport 22-j ACCEPT

# Open Port 80

-A RH-Firewall-1-INPUT-m state -- state NEW-m tcp-p tcp -- dport 80-j ACCEPT

# Open Port 21 of ftp

-A RH-Firewall-1-INPUT-m state -- state NEW-m tcp-p tcp -- dport 21-j ACCEPT

# Prohibit other ports except the opened ports

-A RH-Firewall-1-INPUT-j REJECT -- reject-with icmp-host-prohibited

COMMIT

3. Save it.

Service iptables save

# To prevent the failure of iptables server restart, restart iptables and run the following command: chkconfig -- level 345 iptables on service iptables restart

Ii. iptables Application

1. view the added iptables rules:

Iptables-L

2. Delete the added iptables rule:

Set all iptables rules according to 1.2.3 .... sort and run: iptables-L-n -- line-numbers. If you want to delete the rule number 5 in INPUT, run: iptables-d input 5.

3. Use iptables to shield the specified IP Address:

# The command to shield a single IP address is iptables-I INPUT-s 123.45.6.7-j DROP

# The command for sealing the entire segment from 123.0.0.1 to 123.20.255.254

Iptables-I INPUT-s 123.0.0.0/8-j DROP

# An IP address segment is a command from 123.45.0.1 to 123.45.255.254.

Iptables-I INPUT-s 124.45.0.0/16-j DROP

# The command from 123.45.6.1 to 123.45.6.254 is

Iptables-I INPUT-s 123.45.6.0/24-j DROP

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.