2017/02/24

[OpenWrt] 用dnsmasq在OpenVPN設計custom domain

在OpenWrt中,可以透過dnsmasq來設定custom domain,基本的設定可以參考官網

但是如果想要透過OpenVPN連線,也能夠使用custom domain的話,要如何設定呢?



首先,要跟原本一樣先設定dnsmasq
1. 先設定uci config: /etc/config/dhcp
config domain
        option ip '192.168.3.1'
        option name 'example.router'

2. 設定dnsmasq config: /etc/dnsmasq.config,加上local IP
# Provide an alias for a "local" DNS name. Note that this _only_ works
# for targets which are names from DHCP or /etc/hosts. Give host
# "bert" another name, bertrand
# The fields are ,
#cname=bertand,bert
listen-address=127.0.0.1,192.168.3.1,10.8.0.1

3. 接著重啟服務
/etc/init.d/dnsmasq restart

然後,設定OpenVPN的部分,要強迫clients端透過OpenVPN server端取得DNS,特別是要加上:
        list push 'redirect-gateway autolocal'
        list push 'dhcp-option DNS 10.8.0.1'

1. 設定/etc/config/openvpn
config openvpn 'sample_server'
        option port '1194'
        option proto 'udp'
        option dev 'tun'
        option ca '/etc/openvpn/ca.crt'
        option cert '/etc/openvpn/server.crt'
        option key '/etc/openvpn/server.key'
        option dh '/etc/openvpn/dh1024.pem'
        option server '10.8.0.0 255.255.255.0'
        option ifconfig_pool_persist '/tmp/ipp.txt'
        list push 'redirect-gateway autolocal'
        list push 'dhcp-option DNS 10.8.0.1'
        list push 'dhcp-option WINS 10.8.0.1'
        option keepalive '10 120'
        option comp_lzo 'yes'
        option persist_key '1'
        option persist_tun '1'
        option status '/tmp/openvpn-status.log'
        option verb '3'

2. 重啟服務
/etc/init.d/openvpn

取得opvn設定檔之後,放進client端config資料夾,然後連線
取得10.8.0.6的IP。

確認DNS伺服器是否為10.8.0.1。

nslookup也確認會由10.8.0.1回覆資訊。

OpenVPN未連線前,TTL為53。

連線之後,TTL為52,確認從client端發出去的封包都會透過OpenVPN server。

試著輸入10.8.0.1,成功連線到OpenWrt的網頁。

輸入custom domain(example.router),也可以成功連線到網頁。

大功告成。

沒有留言:

張貼留言