CentOS iptables configuration process

Source: Internet
Author: User
Set iptables to improve server security performance (1) block all ports (2) set the default SSH port to 56565 (3) open ports 56565, 80, and 3306 (4) set Port 3306 to allow access only to the local machine. if iptables is not installed, run the command yuminstalliptables to finish the status quo of recent website intrusion. IptablesMake the following settings to improve server security performance
(1) shield all ports
(2) set the default port of SSH to 56565.
(3) open ports 56565, 80, and 3306
(4) set Port 3306 to allow only local access
If iptables is not installed, run the command yum install iptables to install iptables.
After initialization and installation, the following information is displayed:
[Root @ tp ~] # Iptables-L-n
Chain INPUT (policy ACCEPT)
Target prot opt source destination
Chain FORWARD (policy ACCEPT)
Target prot opt source destination
Chain OUTPUT (policy ACCEPT)
Target prot opt source destination
(1) shield all ports
[Root @ tp ~] # Iptables-F
[Root @ tp ~] # Iptables-X
[Root @ tp ~] # Iptables-P INPUT DROP
[Root @ tp ~] # Iptables-P OUTPUT DROP
[Root @ tp ~] # Iptables-P FORWARD DROP
When two chain rules (INPUT, FORWARD) in the filter table in IPTABLES are exceeded, how can we process data packets not in these two rules? that is, DROP (discard ), some people like to configure OUTPUT as accpet, because if it is intruded, the other party can use the server as a transit, initiate an attack, and generate a large number of data packets, so here the configuration is set to DROP
(2) set the default port of SSH to 56565.
When modifying the ssh port, add the port number 56565 to the whitelist.
[Root @ tp ~] # Iptables-a input-p tcp -- dport 56565-jACCEPT
[Root @ tp ~] # Iptables-a output-p tcp -- sport 56565-j ACCEPT
[Root @ tp ~] #/Etc/rc. d/init. d/iptables save
[Root @ tp ~] # Service iptables restart
Modify the port number.
[Root @ linux ~] # Vi/etc/ssh/sshd_config
Change "# Port 22" to "Port 56565"
Restart the ssh service
[Root @ linux ~] #/Etc/init. d/sshd restart
Stopping sshd: [OK]
Starting sshd: [OK]
If you want to check whether the sshd port number is successfully modified, you can run the netstat-an Command to check or exit ssh and try to log on with the new port number.
(3) open port 80
[Root @ tp ~] # Iptables-a input-p tcp -- dport 80-j ACCEPT
[Root @ tp ~] # Iptables-a output-p tcp -- sport 80-j ACCEPT
[Root @ tp ~] #/Etc/rc. d/init. d/iptables save
[Root @ tp ~] # Service iptables restart
(4) set Port 3306 to allow only local access
[Root @ tp ~] #/Sbin/iptables-a input-p tcp-s 127.0.0.1 -- dport3306-j ACCEPT
[Root @ tp ~] #/Sbin/iptables-a output-p tcp-s 127.0.0.1 -- dport3306-j ACCEPT
So far, the CentOS iptables configuration has been completed. this configuration can improve server security performance and filter out some common linux attacks. for a few linux 0-day attacks with excessive system permissions, it is only lucky.

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.