Disable ping and iptables on the centos server.

Source: Internet
Author: User
Tags centos server vps 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 the previous centosiptables tutorials, incorrect settings may play a role, but they will increase the system load. The iptables configuration method cannot be optimal and will be copied by various websites.

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 centos iptables 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 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

 

Related Article

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.