2017-08-31 01:19:49 +08:00
|
|
|
|
2017-08-31 01:23:26 +08:00
|
|
|
## 8. Transparent Proxy with dnsmasq
|
2017-08-31 01:19:49 +08:00
|
|
|
|
2018-07-30 01:13:44 +08:00
|
|
|
#### Setup a redirect proxy and a dns server with glider
|
2017-08-31 01:19:49 +08:00
|
|
|
glider.conf
|
|
|
|
```bash
|
|
|
|
verbose=True
|
|
|
|
listen=redir://:1081
|
|
|
|
forward=http://forwarder1:8080,socks5://forwarder2:1080
|
|
|
|
forward=http://1.1.1.1:8080
|
2018-07-30 01:13:44 +08:00
|
|
|
dns=:5353
|
|
|
|
dnsserver=8.8.8.8:53
|
2017-08-31 01:19:49 +08:00
|
|
|
strategy=rr
|
|
|
|
checkwebsite=www.apple.com
|
2019-01-06 21:01:20 +08:00
|
|
|
checkinterval=30
|
2017-08-31 01:19:49 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
#### Create a ipset manually
|
|
|
|
```bash
|
2020-09-13 15:25:57 +08:00
|
|
|
ipset create myset hash:net
|
2017-08-31 01:19:49 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
#### Config dnsmasq
|
|
|
|
```bash
|
|
|
|
server=/example1.com/127.0.0.1#5353
|
|
|
|
ipset=/example1.com/myset
|
|
|
|
server=/example2.com/127.0.0.1#5353
|
|
|
|
ipset=/example2.com/myset
|
|
|
|
server=/example3.com/127.0.0.1#5353
|
|
|
|
ipset=/example4.com/myset
|
|
|
|
```
|
|
|
|
|
|
|
|
#### Config iptables on your linux gateway
|
|
|
|
```bash
|
|
|
|
iptables -t nat -I PREROUTING -p tcp -m set --match-set myset dst -j REDIRECT --to-ports 1081
|
2018-11-25 13:18:15 +08:00
|
|
|
#iptables -t nat -I OUTPUT -p tcp -m set --match-set myset dst -j REDIRECT --to-ports 1081
|
2017-08-31 01:19:49 +08:00
|
|
|
```
|
|
|
|
|
2017-08-31 11:30:27 +08:00
|
|
|
#### When client requests network, the whole process:
|
2017-08-31 01:19:49 +08:00
|
|
|
1. all dns requests for domain example1.com will be forward to glider(:5353) by dnsmasq
|
|
|
|
2. glider will forward dns requests to 8.8.8.8:53 in tcp via forwarders
|
2017-09-03 01:18:01 +08:00
|
|
|
3. the resolved ip address will be added to ipset "myset" by dnsmasq
|
|
|
|
4. all tcp requests to example1.com will be redirect to glider(:1081) by iptables
|
2017-08-31 01:19:49 +08:00
|
|
|
5. glider then forward requests to example1.com via forwarders
|