REJECT
--reject-with icmp-host-unreachable # 当不设置任何值时,默认值为icmp-port-unreachable。 # 其他可选项 icmp-net-unreachable icmp-host-unreachable icmp-port-unreachable icmp-proto-unreachable icmp-net-prohibited icmp-host-pro-hibited icmp-admin-prohibited
LOG
--log-level # 选项可以指定记录日志的日志级别,可用级别有emerg,alert,crit,error,warning,notice,info,debug。 --log-prefix# 选项可以给记录到的相关信息添加"标签"之类的信息,以便区分各种记录到的报文信息,方便在分析时进行过滤。 # 配置iptables日志文件 vim /etc/rsyslog.conf kern.waring /var/log/iptables.log service rsyslog restart # 服务重启后,配置即可生效,iptables的日志就存入/var/log/iptables.log中
NAT表
echo 1 > /proc/sys/net/ipv4/ip_forward # 开启内核转发 iptables -t nat -I POSTROUTING -s 192.168.0.0/24 -j SNAT --to-source 10.10.10.1 iptables -t nat -I POSTROUTING -s 192.168.0.0/24 -j MASQUERADE iptables -t nat -I PREROUTING -d 10.10.10.1 -p tcp -m tcp --dport 80 -j DNAT --to-destination 192.168.0.2:80 iptables -t nat -I PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
RAW表
# 访问22端口增加不追踪标识 iptables -t raw -I PREROUTING -p tcp --dport 22 -j NOTRACK iptables -t raw -I OUTPUT -p tcp --dport 22 -j NOTRACK
自定义链
iptables -t table -N chain_name # 创建自定义链 iptabels -t table -E chain_name # 重命名自定义链 iptables -t table -X chain_name # 删除自定义链(前提是没有被引用且没有规则) iptables -t table -A|-I chain match_expression -j chain_name # 引用自定义链 iptables -t filter -N VM_FIREWARD iptables -t filter -I VM_FIREWARD -p tcp -m multiport --dports 22,80,8080 -j ACCEPT iptables -t filter -I VM_FIREWARD -m conntrack --ctstate ESTABLISH,RELATED -j ACCEPT iptables -t filter -A VM_FIREWARD -p icmp -j ACCEPT iptables -t filter -I INPUT -j VM_FIREWARD # 引用VM_FIREWARD链 iptables -t filter -P INPUT DROP
原文:https://www.cnblogs.com/wang-hongwei/p/14659632.html