Skip to content

Commit

Permalink
Merge pull request #1 from wadahiro/dns-option
Browse files Browse the repository at this point in the history
Add -dns-over-tcp-disabled option
  • Loading branch information
wadahiro authored Sep 26, 2017
2 parents cf6993b + 561b9be commit a91aa71
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
34 changes: 28 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Options:
Use DNS-over-HTTPS service as public DNS
-dns-over-https-endpoint string
DNS-over-HTTPS endpoint URL (default "https://dns.google.com/resolve")
-dns-over-tcp-disabled
Disable DNS-over-TCP for querying to public DNS
-dns-proxy-listen [host]:port
DNS Proxy listen address, as [host]:port (default ":3131")
-dns-tcp
Expand All @@ -62,7 +64,7 @@ Options:
```

Proxy configuration is used from standard environment variables, `http_proxy`, `https_proxy` and `no_proxy`.
Also We can use **IP Address**, **CIDR**, **Suffix Domain Name** in `no_proxy`.
Also you can use **IP Address**, **CIDR**, **Suffix Domain Name** in `no_proxy`.

### Example

Expand All @@ -74,10 +76,10 @@ export http_proxy=http://foo:[email protected]:3128
export no_proxy=example.org,192.168.0.0/24
# Start go-transproxy with admin privileges(sudo)
sudo go-transproxy -private-dns 192.168.0.100 -public-dns 8.8.8.8
sudo -E go-transproxy -private-dns 192.168.0.100 -public-dns 8.8.8.8
```

For testing, using docker is easy way. Now, we can access to google from docker container with no proxy configuration as follows.
For testing, using docker is easy way. Now, you can access to google from docker container with no proxy configuration as follows.

```
docker run --rm -it centos curl http://www.google.com
Expand All @@ -90,10 +92,30 @@ The document has moved
```

If your proxy doesn't support CONNECT method to DNS port, it cannot resolve public domain name transparently.
Fortunately, Google privides [DNS-over-HTTPS service](https://developers.google.com/speed/public-dns/docs/dns-over-https), so we can use this service as public DNS by adding `-dns-over-https-enabled` option instead of `-public-dns` option as below even if your proxy supports CONNECT method to 443 port only.
Fortunately, Google privides [DNS-over-HTTPS service](https://developers.google.com/speed/public-dns/docs/dns-over-https), so you can use this service as public DNS by adding `-dns-over-https-enabled` option instead of `-public-dns` option as below even if your proxy supports CONNECT method to 443 port only.

```
sudo go-transproxy -private-dns 192.168.0.100 -dns-over-https-enabled
sudo -E go-transproxy -private-dns 192.168.0.100 -dns-over-https-enabled
```

If you can resolve all domains directly from local LAN, run command without dns related options as below.
It disables DNS-Proxy.

```
sudo -E go-transproxy
```

If you need to use both public DNS and private DNS, and need to use public DNS directly, run command with `-dns-over-tcp-disabled` option as below.
It suppresses to insert a iptables OUTPUT rule for DNS over TCP.

```
sudo -E go-transproxy -private-dns 192.168.0.100 -public-dns 172.16.0.1 -dns-over-tcp-disabled
```

If you want to use an application which access to internet using port 5000, run command with `-tcp-proxy-dports` option as below.

```
sudo -E go-transproxy -private-dns 192.168.0.100 -public-dns 8.8.8.8 -tcp-proxy-dports 22,5000
```

## Current Limitation
Expand All @@ -108,5 +130,5 @@ Licensed under the [MIT](/LICENSE) license.

## Author

[wadahiro](https://github.com/wadahiro)
[Hiroyuki Wada](https://github.com/wadahiro)

19 changes: 15 additions & 4 deletions cmd/go-transproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ var (
"dns-proxy-listen", ":3131", "DNS Proxy listen address, as `[host]:port`",
)

dnsOverHTTPSEnabled = fs.Bool("dns-over-https-enabled", false,
"Use DNS-over-HTTPS service as public DNS")
dnsOverTCPDisabled = fs.Bool(
"dns-over-tcp-disabled", false, "Disable DNS-over-TCP for querying to public DNS")

dnsOverHTTPSEnabled = fs.Bool(
"dns-over-https-enabled", false, "Use DNS-over-HTTPS service as public DNS")

dnsOverHTTPSEndpoint = fs.String(
"dns-over-https-endpoint",
Expand Down Expand Up @@ -154,13 +157,18 @@ func main() {
tcpToPort := toPort(*tcpProxyListenAddress)
tcpDPorts := toPorts(*tcpProxyDestPorts)

outgoingPublicDNS := *publicDNS
if *dnsOverTCPDisabled {
outgoingPublicDNS = ""
}

t, err := tproxy.NewIPTables(&tproxy.IPTablesConfig{
DNSToPort: dnsToPort,
HTTPToPort: httpToPort,
HTTPSToPort: httpsToPort,
TCPToPort: tcpToPort,
TCPDPorts: tcpDPorts,
PublicDNS: *publicDNS,
PublicDNS: outgoingPublicDNS,
})
if err != nil {
log.Fatalf("IPTables: %s", err.Error())
Expand All @@ -184,7 +192,10 @@ func main() {
t.Stop()
log.Infoln("IPTables: iptables rules deleted.")

dnsProxy.Stop()
if dnsProxy != nil {
dnsProxy.Stop()
}

log.Infoln("go-transproxy exited.")
}

Expand Down
6 changes: 3 additions & 3 deletions dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func NewDNSProxy(c DNSProxyConfig) *DNSProxy {

func (s *DNSProxy) Start() error {
if !s.Enabled {
log.Infof("DNS-Proxy: Not enabled")
log.Infof("DNS-Proxy: Disabled")
return nil
}

Expand All @@ -86,10 +86,10 @@ func (s *DNSProxy) Start() error {
log.Infof("DNS-Proxy: Use DNS-over-HTTPS service as public DNS")
}
if !s.DNSOverHTTPSEnabled && s.PublicDNS != "" {
log.Infof("DNS-Proxy: Use public DNS %s via TCP-Proxy", s.PublicDNS)
log.Infof("DNS-Proxy: Use %s as public DNS", s.PublicDNS)
}
if s.PrivateDNS != "" {
log.Infof("DNS-Proxy: Use private DNS %s for %s domains", s.PrivateDNS, s.NoProxyDomains)
log.Infof("DNS-Proxy: Use %s as private DNS for %s domains", s.PrivateDNS, s.NoProxyDomains)
}

// Prepare external DNS handler
Expand Down

0 comments on commit a91aa71

Please sign in to comment.