iptables 禁止端口与放行端口
禁止端口iptables -t filter -A INPUT-p tcp --dport 80 -j DROP
iptables -t filter -A OUTPUT -p tcp --sport 80 -j DROP
-p 指定协议,这里以 tcp 为例。其它可选值有例如 udp、icmp 等。
INPUT 表示数据流入。--dport 即 destination port,表示外部客户访问服务器时的目标端口。所以第一条规则就是禁止所有外部对本机 80 端口的 tcp 访问。
OUTPUT 表示数据流出。--sport 即 source port,表示数据从服务器流向外部时的监听端口。所以第二条规则就是禁止所有本机在 80 端口的 tcp 对外数据发送。
放行端口
iptables -t filter -A INPUT-p tcp --dport 80 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --sport 80 -j ACCEPT
和上文一样的规则,只是把 drop 换成了 accept。
页:
[1]