Disable ping and iptables on the centos server.

Source: Internet
Author: User
Tags centos server ssh port

Introduction: centos generally has an iptables firewall. Because the vps of the centos System in hyper-v architecture adopts the IPTABLES setting method widely circulated on the Internet, port 22 of ssh cannot be modified, if you modify the ssh port, you can also refer to this article. In some previous centosiptables tutorials, incorrect settings may be useful, but they will increase the system load and cannot be the best iptables configuration method, then it will be copied from various websites, which will eventually cause some troubles for new linux users. We strongly recommend that you use the configuration method described in this article to reconfigure iptables of centos.

I. How to correctly set centosiptables and disable PING

1. Clear existing iptables rules

Iptables-Fiptables-Xiptables-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.

# Firewallconfigurationwrittenbysystem-config-securitylevel

# Manualcustomizationofthisfileisnotrecommended.

* Filter

: INPUTACCEPT [0: 0]

: FORWARDACCEPT [0: 0]

: OUTPUTACCEPT [0: 0]

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

AINPUT-jRH-Firewall-1-INPUT

AFORWARD-jRH-Firewall-1-INPUT

# Allow Local localhost access

ARH-Firewall-1-INPUT-ilo-jACCEPT

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

-ARH-Firewall-1-INPUT-picmp -- icmp-typeany-jACCEPT

# Allow established or related connections

-ARH-Firewall-1-INPUT-mstate -- stateESTABLISHED, RELATED-jACCEPT

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

-ARH-Firewall-1-INPUT-mstate -- stateNEW-mtcp-ptcp -- dport22-jACCEPT

# Open Port 80

-ARH-Firewall-1-INPUT-mstate -- stateNEW-mtcp-ptcp -- dport80-jACCEPT

# Open Port 21 of ftp

-ARH-Firewall-1-INPUT-mstate -- stateNEW-mtcp-ptcp -- dport21-jACCEPT

# Prohibit other ports except the opened ports

-ARH-Firewall-1-INPUT-jREJECT -- reject-withicmp-host-prohibited

COMMIT

3. Save it.

Serviceiptablessave

# To prevent the failure of iptables server restart, restart iptables to take effect automatically. Run the following command chkconfig -- level345iptablesonserviceiptablesrestart

Ii. iptables Application

1. view the added iptables rules:

Iptables-L

2. Delete the added iptables rule:

Sort all iptables rules by 1.2.3..., execute: iptables-L-n -- line-numbers if you want to delete rules with serial number 5 in INPUT, execute: iptables-DINPUT5

3. Use iptables to shield the specified IP Address:

# The command to shield a single IP address is iptables-IINPUT-s123.45.6.7-jDROP

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

Iptables-IINPUT-s123.0.0.0/8-jDROP

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

Iptables-IINPUT-s124.45.0.0/16-jDROP

# The command from 123.45.6.1 to 123.45.6.254 is

Iptables-IINPUT-s123.45.6.0/24-jDROP

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.