yum install iptables
iptables -L -n
iptables -A OUTPUT -m state --state NEW -p tcp -d 182.92.228.160 --dport 80 -j ACCEPT
iptables -L INPUT --line-numbers
iptables -D INPUT 3
1 /sbin/iptables -P INPUT ACCEPT 2 /sbin/iptables -F 3 /sbin/iptables -X 4 /sbin/iptables -Z 5 6 /sbin/iptables -A INPUT -i lo -j ACCEPT 7 /sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT 8 /sbin/iptables -A INPUT -p tcp --dport 80 -j ACCEPT 9 /sbin/iptables -A INPUT -p tcp --dport 8080 -j ACCEPT 10 /sbin/iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT 11 /sbin/iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT 12 /sbin/iptables -P INPUT DROP 13 service iptables save
Linux系统脚本
1 #!/bin/bash 2 ######################################### 3 #Function: linux drop port 4 #Usage: bash linux_drop_port.sh 5 #Author: Customer Service Department 6 #Company: Alibaba Cloud Computing 7 #Version: 2.0 8 ######################################### 9 10 check_os_release() 11 { 12 while true 13 do 14 os_release=$(grep "Red Hat Enterprise Linux Server release" /etc/issue 2>/dev/null) 15 os_release_2=$(grep "Red Hat Enterprise Linux Server release" /etc/redhat-release 2>/dev/null) 16 if [ "$os_release" ] && [ "$os_release_2" ] 17 then 18 if echo "$os_release"|grep "release 5" >/dev/null 2>&1 19 then 20 os_release=redhat5 21 echo "$os_release" 22 elif echo "$os_release"|grep "release 6" >/dev/null 2>&1 23 then 24 os_release=redhat6 25 echo "$os_release" 26 else 27 os_release="" 28 echo "$os_release" 29 fi 30 break 31 fi 32 os_release=$(grep "Aliyun Linux release" /etc/issue 2>/dev/null) 33 os_release_2=$(grep "Aliyun Linux release" /etc/aliyun-release 2>/dev/null) 34 if [ "$os_release" ] && [ "$os_release_2" ] 35 then 36 if echo "$os_release"|grep "release 5" >/dev/null 2>&1 37 then 38 os_release=aliyun5 39 echo "$os_release" 40 elif echo "$os_release"|grep "release 6" >/dev/null 2>&1 41 then 42 os_release=aliyun6 43 echo "$os_release" 44 else 45 os_release="" 46 echo "$os_release" 47 fi 48 break 49 fi 50 os_release=$(grep "CentOS release" /etc/issue 2>/dev/null) 51 os_release_2=$(grep "CentOS release" /etc/*release 2>/dev/null) 52 if [ "$os_release" ] && [ "$os_release_2" ] 53 then 54 if echo "$os_release"|grep "release 5" >/dev/null 2>&1 55 then 56 os_release=centos5 57 echo "$os_release" 58 elif echo "$os_release"|grep "release 6" >/dev/null 2>&1 59 then 60 os_release=centos6 61 echo "$os_release" 62 else 63 os_release="" 64 echo "$os_release" 65 fi 66 break 67 fi 68 os_release=$(grep -i "ubuntu" /etc/issue 2>/dev/null) 69 os_release_2=$(grep -i "ubuntu" /etc/lsb-release 2>/dev/null) 70 if [ "$os_release" ] && [ "$os_release_2" ] 71 then 72 if echo "$os_release"|grep "Ubuntu 10" >/dev/null 2>&1 73 then 74 os_release=ubuntu10 75 echo "$os_release" 76 elif echo "$os_release"|grep "Ubuntu 12.04" >/dev/null 2>&1 77 then 78 os_release=ubuntu1204 79 echo "$os_release" 80 elif echo "$os_release"|grep "Ubuntu 12.10" >/dev/null 2>&1 81 then 82 os_release=ubuntu1210 83 echo "$os_release" 84 else 85 os_release="" 86 echo "$os_release" 87 fi 88 break 89 fi 90 os_release=$(grep -i "debian" /etc/issue 2>/dev/null) 91 os_release_2=$(grep -i "debian" /proc/version 2>/dev/null) 92 if [ "$os_release" ] && [ "$os_release_2" ] 93 then 94 if echo "$os_release"|grep "Linux 6" >/dev/null 2>&1 95 then 96 os_release=debian6 97 echo "$os_release" 98 else 99 os_release="" 100 echo "$os_release" 101 fi 102 break 103 fi 104 os_release=$(grep "openSUSE" /etc/issue 2>/dev/null) 105 os_release_2=$(grep "openSUSE" /etc/*release 2>/dev/null) 106 if [ "$os_release" ] && [ "$os_release_2" ] 107 then 108 if echo "$os_release"|grep "13.1" >/dev/null 2>&1 109 then 110 os_release=opensuse131 111 echo "$os_release" 112 else 113 os_release="" 114 echo "$os_release" 115 fi 116 break 117 fi 118 break 119 done 120 } 121 122 exit_script() 123 { 124 echo -e "