OpenWrt VPN 按域名路由
https://blog.sorz.org/p/openwrt-outwall/
看到上面的文档,应该是很简单的能实现路由分流,可是花了一星期不得要领。昨天才注意到 vps 是 ipv4+ipv6 ,所以 nslookup 的结果包含了 AAAA 查询纪录,那么 youtube 的 ipset 结果都是基于 ipv4 结果而实际访问的是 ipv6 网站,当然怎么也无法按照文档实现。
Linux: Block DNS queries for specific zone with IPTables
https://www.perturb.org/display/1186_Linux_Block_DNS_queries_for_specific_zone_with_IPTables.htm
终于搜到一篇最简单的用 iptables 实现的禁止 AAAA 查询,这样就可以简单的用日本 vps vpn 分流 美国 vps 上的 youtube 资源,让访客判断 ip 为美国而不是日本。
就这么简单
iptables -A OUTPUT -o eth0 -p udp --dport 53 -m string --hex-string "|07|youtube|03|com|00001c|" --algo bm -j DROP
iptables -A OUTPUT -o eth0 -p udp --dport 53 -m string --hex-string "|05|ip138|03|com|00001c|" --algo bm -j DROP
Advanced:
Technically the query looks like X domain Y TLD 0 where the zero indicates that there are no more parts of the domain. This is immediately followed by two bytes indicating the type of query.
This allows you to get fancy and only block specific types of queries for a domain while allowing others:
Type Code
Any 00ff
A 0011
CNAME 0005
MX 000f
AAAA 001c
NS 0002
SOA 0006
https://blog.sorz.org/p/openwrt-outwall/
看到上面的文档,应该是很简单的能实现路由分流,可是花了一星期不得要领。昨天才注意到 vps 是 ipv4+ipv6 ,所以 nslookup 的结果包含了 AAAA 查询纪录,那么 youtube 的 ipset 结果都是基于 ipv4 结果而实际访问的是 ipv6 网站,当然怎么也无法按照文档实现。
Linux: Block DNS queries for specific zone with IPTables
https://www.perturb.org/display/1186_Linux_Block_DNS_queries_for_specific_zone_with_IPTables.htm
终于搜到一篇最简单的用 iptables 实现的禁止 AAAA 查询,这样就可以简单的用日本 vps vpn 分流 美国 vps 上的 youtube 资源,让访客判断 ip 为美国而不是日本。
就这么简单
iptables -A OUTPUT -o eth0 -p udp --dport 53 -m string --hex-string "|07|youtube|03|com|00001c|" --algo bm -j DROP
iptables -A OUTPUT -o eth0 -p udp --dport 53 -m string --hex-string "|05|ip138|03|com|00001c|" --algo bm -j DROP
Advanced:
Technically the query looks like X domain Y TLD 0 where the zero indicates that there are no more parts of the domain. This is immediately followed by two bytes indicating the type of query.
This allows you to get fancy and only block specific types of queries for a domain while allowing others:
Type Code
Any 00ff
A 0011
CNAME 0005
MX 000f
AAAA 001c
NS 0002
SOA 0006