Skip to content

[HTTPS转发还有问题 待解决]

前提

需要先确认使用的防火墙类型

iptables -V | grep -q "nf_tables" && echo "nftables" || echo "iptables"

配置说明

字段 意义
192.168.1.50-192.168.1.60 范围
192.168.1.50 单个IP
192.168.1.214:8888 抓包地址和端口

单个IP[iptables]

重定向来自192.168.1.50的HTTP和HTTPS流量到Fiddler代理

iptables -t nat -A PREROUTING -s 192.168.1.50 -p tcp --dport 80 -j DNAT --to 192.168.1.214:8888
iptables -t nat -A PREROUTING -s 192.168.1.50 -p tcp --dport 443 -j DNAT --to 192.168.1.214:8888

删除重定向来自192.168.1.50的HTTP和HTTPS流量的规则

iptables -t nat -D PREROUTING -s 192.168.1.50 -p tcp --dport 80 -j DNAT --to 192.168.1.214:8888
iptables -t nat -D PREROUTING -s 192.168.1.50 -p tcp --dport 443 -j DNAT --to 192.168.1.214:8888

IP范围[iptables]

重定向来自192.168.1.50到192.168.1.60的HTTP和HTTPS流量到Fiddler代理

iptables -t nat -A PREROUTING -m iprange --src-range 192.168.1.50-192.168.1.60 -p tcp --dport 80 -j DNAT --to 192.168.1.214:8888
iptables -t nat -A PREROUTING -m iprange --src-range 192.168.1.50-192.168.1.60 -p tcp --dport 443 -j DNAT --to 192.168.1.214:8888

删除重定向来自192.168.1.50到192.168.1.60的HTTP和HTTPS流量的规则

iptables -t nat -D PREROUTING -m iprange --src-range 192.168.1.50-192.168.1.60 -p tcp --dport 80 -j DNAT --to 192.168.1.214:8888
iptables -t nat -D PREROUTING -m iprange --src-range 192.168.1.50-192.168.1.60 -p tcp --dport 443 -j DNAT --to 192.168.1.214:8888

确认当前规则[iptables]

iptables -t nat -L PREROUTING -n -v

添加 nat 表[nftables]

nft add table ip nat
nft add chain ip nat prerouting { type nat hook prerouting priority 0 \; }

单个IP[nftables]

重定向来自192.168.1.50的HTTP和HTTPS流量到Fiddler代理

nft add rule ip nat prerouting ip saddr 192.168.1.50 tcp dport { 80, 443 } dnat to 192.168.1.214:8888

IP范围[nftables]

重定向来自192.168.1.50到192.168.1.60的HTTP和HTTPS流量到Fiddler代理

nft add rule ip nat prerouting ip saddr 192.168.1.50-192.168.1.60 tcp dport { 80, 443 } dnat to 192.168.1.214:8888

删除重定向来自192.168.1.50的HTTP和HTTPS流量的规则

# 删除整个 prerouting
nft delete chain ip nat prerouting

# 删除单个
nft -a list chain ip nat prerouting
# 看下要删除的 handle 号码是多少,末尾的5是handle号码
nft delete rule ip nat prerouting handle 5

确认当前规则[nftables]

nft -a list chain ip nat prerouting