iptables使用

字数统计: 226阅读时长: 1 min
2019/05/12 Share

只在Android设备上测试过

介绍:https://en.wikipedia.org/wiki/Iptables
用法:https://linux.die.net/man/8/iptables

注意: 由于是修改配置文件,所以输入命令后要等一会才会生效

黑名单 禁止访问带百度关键字的链接

1
2
3
4
5
6
7
8
9
10
11
12
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -N 10029
iptables -A OUTPUT -m owner --uid-owner 10029 -j 10029
iptables -A 10029 -m string --string baidu --algo bm -j REJECT

白名单 只能访问带百度关键字的链接

1
2
3
4
5
6
7
8
9
10
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -F
iptables -X
iptables -t filter -N WEBWHITELIST
iptables -I OUTPUT -p tcp -j WEBWHITELIST
iptables -A WEBWHITELIST -p tcp -m string --string Host: --algo bm -j MARK --set-mark 1
iptables -A WEBWHITELIST -p tcp -m mark --mark 1 -m string --string baidu --algo bm -j ACCEPT
iptables -A WEBWHITELIST -p tcp -m mark --mark 1 -j REJECT

开放6796端口访问

1
2
3
4
5
6
7
iptables -F
iptables -X
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP
iptables -A INPUT -p tcp --sport 6796 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 6796 -j ACCEPT

原文作者:大瑞

原文链接:https://ruizhang81.github.io/2019/05/12/iptables使用/

发表日期:May 12th 2019, 3:43:15 pm

更新日期:May 12th 2019, 3:43:35 pm

版权声明:

CATALOG
  1. 1. 注意: 由于是修改配置文件,所以输入命令后要等一会才会生效
  2. 2. 黑名单 禁止访问带百度关键字的链接
  3. 3. 白名单 只能访问带百度关键字的链接
  4. 4. 开放6796端口访问