-
安装必要软件包:
- 连接到路由器,使用SSH或telnet登录。
- 更新软件包列表并安装必要的软件包:
opkg update opkg install dnsmasq ipkg kmod-iptunnel kmod-iptables-tc kmod-ipset
-
配置dnsmasq:
- 打开
/etc/dnsmasq.conf,添加以下内容:interface=tun dhcp-range=10...2,12...1,255.255.255.,24h dhcp-option=3,127...1 server=192.168.1.1
- 保存并退出,确保
server地址正确,通常是你的DNS服务器地址。
- 打开
-
启动dnsmasq服务:
- 启动并启用服务:
systemctl start dnsmasq systemctl enable dnsmasq
- 启动并启用服务:
-
配置iptables:
- 添加NAT规则:
iptables -t nat -A POSTROUTING -o eth -j MASQUERADE
- 确保允许所有流量:
iptables -P INPUT ACCEPT iptables -P FORWARD ACCEPT iptables -P OUTPUT ACCEPT
- 添加NAT规则:
-
设置tun接口:
- 检查并启用tun:
ip link set dev tun up
- 为tun分配IP地址:
dhclient tun
或手动设置:
ip addr add 192.168.1.2/24 dev tun ip link set dev tun up
- 检查并启用tun:
-
设置默认网关:
- 在
/etc/network中添加或修改network文件:network { default_gw=192.168.1.1 option=18 } - 重启网络服务:
/etc/init.d/network restart
- 在
-
测试配置:
- 检查tun IP:
ip link show tun
- 测试网络连接,
ping 8.8.8.8
- 查看dnsmasq日志,确保没有错误。
- 检查tun IP:
通过以上步骤,OpenWrt路由器将配置为透明代理,用户可以通过tun接口访问互联网,同时保持原有IP地址,确保每一步配置正确,特别是接口和IP地址设置。









