Each table contains built-in chains and user-defined chains. INPUT FORWARD OUTPUT Each chain is a list of rules Each rule specifies what to do with a packet that matches. ACCEPT, DROP or RETURN
1 2 3 4 5 6 7 8 9 10 11 12 13 14
--append -A chain Append to chain --check -C chain Check for the existence of a rule --delete -D chain Delete matching rule from chain --delete -D chain rulenum Delete rule rulenum (1 = first) from chain --insert -I chain [rulenum] Insert in chain as rulenum (default 1=first) --replace -R chain rulenum Replace rule rulenum (1 = first) in chain --list -L [chain [rulenum]] List the rules in a chain or all chains --list-rules -S [chain [rulenum]] Print the rules in a chain or all chains --flush -F [chain] Delete all rules in chain or all chains --zero -Z [chain [rulenum]] Zero counters in chain or all chains --new -N chain Create a new user-defined chain --delete-chain -X [chain] Delete a user-defined chain --policy -P chain target Change policy on chain to target(built-in only) --rename-chain -E old-chain new-chain Change chain name, (moving any references)
rule-specification
-p, –protocol protocol: tcp, udp, udplite, icmp, icmpv6,esp, ah, sctp, mh or the special keyword “all” -s, –source address[/mask][,…] 写多个地址最后会拆分多条规则 -d, –destination address[/mask][,…] -m, –match match -j, –jump target: ACCEPT DROP REJECT
-m comment 注释 --comment "my local LAN" -m multiport 适用于tcp, udp, udplite, dccp and sctp. Up to 15 ports can be specified. A port range (port:port) counts as two ports. --ports port[,port|,port:port]... --source-ports,--sports port[,port|,port:port]... --destination-ports,--dports port[,port|,port:port]... -m iprange --src-range from[-to] --dst-range from[-to] -m tcp can be used if `--protocol tcp' is specified --source-port,--sport port[:port] --destination-port,--dport port[:port]
排除连接的ip端口 tcpdump -c 100 -i bond1 -nntq -P in '( (not src net 10.27.48) and (not src net 10.17.14) and (!src port 9092) and (dst portrange 30000-49999 ) and (tcp) )'
简化结果 head test|awk -F'[ :]' '{print $2, $4}'|sort -u
-A INPUT -p tcp -m tcp --dport 8088 -m comment --comment yarn -j DROP -A INPUT -p tcp -m tcp --dport 50070 -m comment --comment hdfs -j DROP -A INPUT -p tcp -m tcp --dport 18080 -m comment --comment sjh -j DROP -A INPUT -p tcp -m tcp --dport 8050 -m comment --comment NameNode -j DROP -A INPUT -p tcp -m tcp --dport 8019 -m comment --comment DFSZKFailoverController -j DROP -A INPUT -p tcp -m multiport --dports 8030:8033 -m comment --comment ResourceManager -j DROP
# zeppelin/jupyter WEBUI + 8090,15588
# dolphins WEBUI + 12345 -A INPUT -p tcp -m tcp --dport 5678 -m comment --comment ds_master -j DROP
# mysql :MYSQL - [0:0]
-A INPUT -p tcp -m multiport --dports 3306 -j MYSQL -m comment --comment "访问mysql" -A MYSQL -s 10.17.41.125/32 -m comment --comment "海豚worker" -j ACCEPT -A MYSQL -s 10.33.7.5/32 -m comment --comment "数据资产安全管理" -j ACCEPT -A MYSQL -m iprange --src-range 10.19.85.1-10.19.85.6 -m comment --comment "中台元数据信息接入" -j ACCEPT -A MYSQL -j DROP
kafka
1 2 3 4 5 6 7 8 9 10 11 12
:KAFKA - [0:0]
-A INPUT -p tcp -m multiport --dports 9092 -j KAFKA -m comment --comment "访问KAFKA" -A KAFKA -s 10.35.0.0/24 -m comment --comment "运营平台网段" -j ACCEPT -A KAFKA -s 10.136.102.0/24 -j ACCEPT -A KAFKA -s 10.35.24.0/24 -m comment --comment kafka -j ACCEPT -A KAFKA -s 10.17.49.0/24 -j ACCEPT -A KAFKA -s 10.3.4.0/24 -j ACCEPT -A KAFKA -s 10.17.41.125/32 -j ACCEPT -A KAFKA -m iprange --src-range 10.19.6.144-10.19.6.147 -m comment --comment "建设小组_移动云" -j ACCEPT -A KAFKA -j DROP
CK
1 2 3 4 5 6 7 8 9 10 11 12 13 14
:CK - [0:0]
-A INPUT -p tcp -m multiport --dports 9000,8123,9004,9005,9009,9363 -j CK -m comment --comment "访问ck" -A CK -s 10.136.102.0/24 -m comment --comment "放通中台服务器访问移动云ck" -j ACCEPT -A CK -m iprange --src-range 10.3.16.127-10.3.16.131 -m comment --comment "放通中台服务器访问移动云ck" -j ACCEPT -A CK -m iprange --src-range 10.35.0.126-10.35.0.136 -j ACCEPT -A CK -m iprange --src-range 10.35.0.84-10.35.0.91 -j ACCEPT -A CK -m iprange --src-range 10.3.4.113-10.3.4.122 -j ACCEPT -A CK -m iprange --src-range 10.3.4.49-10.3.4.59 -j ACCEPT -A CK -m iprange --src-range 10.69.195.193-10.69.195.194 -j ACCEPT -A CK -m iprange --src-range 10.247.107.1-10.247.107.5 -j ACCEPT -A CK -m iprange --src-range 10.56.17.74-10.56.17.76 -j ACCEPT -A CK -s 10.56.17.235/32 -j ACCEPT -A CK -j DROP
端口转发
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
sysctl -w net.ipv4.ip_forward=1 # less /etc/sysctl.conf #net.ipv4.ip_forward=1