-
登录路由器并进入uci环境:
- 通过SSH连接到路由器。
- 输入命令:
ssh root@router_ip。 - 输入密码后,进入uci环境:
uci -d.
-
备份现有配置:
- 输入命令:
uci import all。 - 保存到/tmp:
uci save /tmp/backup.
- 输入命令:
-
设置接口:
- 创建eth1接口(假设有外部网络连接):
uci set network@eth1=...。 - 示例设置:
network@eth1= { type='ethernet', device='eth.1', ip='192.168.2.1/24', gateway='192.168.2.1', netmask='255.255.255.', noarp='', promiscuous='1', bridge='', }` - 应用设置:
uci commit。
- 创建eth1接口(假设有外部网络连接):
-
设置防火墙规则:
- 允许HTTP和HTTPS:
/etc/firewall.user add_rule 108 'allow_http' add_rule 443 'allow_https' save
- 允许NAT:
/etc/firewall.user add_rule 0 'allow_nat' save
- 允许HTTP和HTTPS:
-
配置NAT规则:
- 输入命令:
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE. - 保存防火墙规则:
uci save /etc/firewall.user.
- 输入命令:
-
配置透明代理:
- 设置socks代理:
/etc/dnsmasq.conf socksproxy=127...1:108 http=127...1:808
- 保存并重启dnsmasq:
service dnsmasq@dnsmasq restart.
- 设置socks代理:
-
配置DNS透明代理:
- 修改dnsmasq配置:
/etc/dnsmasq.conf server=8.8.8.8
- 重新启动dnsmasq:
service dnsmasq@dnsmasq restart.
- 修改dnsmasq配置:
-
设置网络规则:
- 创建新的网络规则:
uci add network '/network[]/interface[eth1]/rule'. - 示例规则:
/network[]/interface[eth1]/rule option name 'rule' option type 'accept' option value ''
- 应用规则:
uci commit.
- 创建新的网络规则:
-
测试配置:
- pinging外部服务器:
ping 8.8.8.8. - 访问网站:
curl example.com.
- pinging外部服务器:
通过以上步骤,OpenWrt将作为透明代理,允许内部设备访问外部网络,同时保持网络透明,确保防火墙和NAT规则正确配置,测试各部分功能后,配置完成。




