瀏覽代碼

Support Windows Subsystem for Linux

Nick Peng 6 年之前
父節點
當前提交
9f3926e048
共有 7 個文件被更改,包括 219 次插入12 次删除
  1. 59 3
      ReadMe.md
  2. 60 3
      ReadMe_zh-CN.md
  3. 34 6
      install
  4. 21 0
      package/windows/install.bat
  5. 21 0
      package/windows/reload.bat
  6. 22 0
      package/windows/uninstall.bat
  7. 2 0
      package/windows/wsl-run.vbs

+ 59 - 3
ReadMe.md

@@ -85,8 +85,8 @@ From the comparison, smartdns found the fastest IP address to visit www.baidu.co
 5. **Domain name high performance rule filtering**  
    Support domain name suffix matching mode, simplify filtering configuration, filter 200,000 recording and take time <1ms.
 
-6. **Linux multi-platform support**  
-   Support standard Linux system (Raspberry Pi), openwrt system various firmware, ASUS router native firmware.
+6. **Linux/Windows multi-platform support**  
+   Support standard Linux system (Raspberry Pi), openwrt system various firmware, ASUS router native firmware. Support Windows 10 WSL (Windows Subsystem for Linux).
 
 7. **Support IPV4, IPV6 dual stack**  
    Support IPV4, IPV6 network, support query A, AAAA record, dual-stack IP selection.
@@ -114,7 +114,8 @@ Download the matching version of the SmartDNS installation package. The correspo
 |system |package|Description
 |-----|-----|-----
 |Standard Linux system (Raspberry Pi)| smartdns.xxxxxxxx.armhf.deb|Support Raspberry Pi Raspbian stretch, Debian 9 system.
-|Standard Linux system (x86_64)| smartdns.xxxxxxxx.x86_64.tar.gz|Support for x86_64 systems.
+|Standard Linux system (x86_64)| smartdns.xxxxxxxx.x86_64.tar.gz|Support for x86_64 Linux systems.
+|Windows 10 WSL (Ubuntu)| smartdns.xxxxxxxx.x86_64.tar.gz|Windows 10 WSL ubuntu.
 |Standard Linux system (x86)| smartdns.xxxxxxxx.x86.tar.gz|Support for x86_64 systems.
 |ASUS native firmware (optware)|smartdns.xxxxxxx.mipsbig.ipk|Systems that support the MIPS big-end architecture, such as RT-AC55U, RT-AC66U.
 |ASUS native firmware (optware)|smartdns.xxxxxxx.mipsel.ipk|System that supports the MIPS little endian architecture, such as the RT-AC68U.
@@ -369,6 +370,61 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
     \\192.168.1.1\sda1\asusware.mipsbig\etc\init.d
     ```
 
+### Windows 10 WSL Installation(WSL ubuntu)
+
+--------------
+
+1. Install Windows 10 WSL ubuntu
+
+   Install the Windows 10 WSL environment and select Ubuntu as default distribution. Please refer to [WSL installation instructions](https://docs.microsoft.com/en-us/windows/wsl/install-win10) for installation steps
+
+1. Install smartdns
+
+    download install package `smartdns.xxxxxxxx.x86_64.tar.gz`,and unzip to the `D:\` directory, after decompression, the directory is as follows: 
+
+    ```shell
+    D:\SMARTDNS
+    ├─etc
+    │  ├─default
+    │  ├─init.d
+    │  └─smartdns
+    ├─package
+    │  └─windows
+    ├─src
+    └─systemd
+
+    ```
+
+    Double-click `install.bat` in the `D:\smartdns\package\windows` directory for installation. Please enter the password for `WLS ubuntu` when input password.
+
+1. Configuration
+
+    Edit `smartdns.conf` configuration file in `D:\smartdns\etc\smartdns` directory, you can configure the upstream server to  smartdns. Refer to the `Configuration Parameters` for specific configuration parameters.  
+    In general, you only need to add `server [IP]:port`, `server-tcp [IP]:port` configuration items.  
+    Configure as many upstream DNS servers as possible, including servers at home and abroad. Please refer to the `Configuration Parameters` section for configuration parameters.  
+
+1. Start Service
+
+    Double-click `reload.bat` in the `D:\smartdns\package\windows` directory for reload. 
+
+1. Forwarding DNS request to SmartDNS
+
+    Modify the default DNS server for Windows to `127.0.0.1`, with these steps referred to [IP configuration](https://support.microsoft.com/en-us/help/15089/windows-change-tcp-ip-settings)
+
+1. Check if the service is configured successfully
+
+    Query domain name with `nslookup -querytype=ptr 0.0.0.0`  
+    Check if the `name` item in the command result is displayed as `smartdns` or `hostname`, such as `smartdns`
+
+    ```shell
+    pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 0.0.0.0
+    Server:         192.168.1.1
+    Address:        192.168.1.1#53
+
+    Non-authoritative answer:
+    0.0.0.0.in-addr.arpa  name = smartdns.
+    ```
+
 ## Configuration parameter
 
 |parameter|Parameter function|Default value|Value type|Example|

+ 60 - 3
ReadMe_zh-CN.md

@@ -85,8 +85,8 @@ rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
 5. **域名高性能后缀匹配**  
    支持域名后缀匹配模式,简化过滤配置,过滤20万条记录时间<1ms
 
-6. **Linux多平台支持**  
-   支持标准Linux系统(树莓派),openwrt系统各种固件,华硕路由器原生固件。
+6. **Linux/Windows多平台支持**  
+   支持标准Linux系统(树莓派),openwrt系统各种固件,华硕路由器原生固件。以及支持Windows 10 WSL (Windows Subsystem for Linux)。
 
 7. **支持IPV4, IPV6双栈**  
    支持IPV4,IPV6网络,支持查询A, AAAA记录,支持双栈IP速度优化。
@@ -114,7 +114,8 @@ rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
 |系统 |安装包|说明
 |-----|-----|-----
 |标准Linux系统(树莓派)| smartdns.xxxxxxxx.armhf.deb|支持树莓派Raspbian stretch,Debian 9系统。
-|标准Linux系统(x86_64)| smartdns.xxxxxxxx.x86_64.tar.gz|支持x86_64系统。
+|标准Linux系统(x86_64)| smartdns.xxxxxxxx.x86_64.tar.gz|支持x86_64 Linux 系统。
+|Windows 10 WSL (ubuntu)| smartdns.xxxxxxxx.x86_64.tar.gz|支持Windows 10 WSL ubuntu系统。
 |标准Linux系统(x86)| smartdns.xxxxxxxx.x86.tar.gz|支持x86系统。
 |华硕原生固件(optware)|smartdns.xxxxxxx.mipsbig.ipk|支持MIPS大端架构的系统,如RT-AC55U, RT-AC66U.
 |华硕原生固件(optware)|smartdns.xxxxxxx.mipsel.ipk|支持MIPS小端架构的系统,如RT-AC68U。
@@ -369,6 +370,62 @@ rtt min/avg/max/mdev = 5.954/6.133/6.313/0.195 ms
     \\192.168.1.1\sda1\asusware.mipsbig\etc\init.d
     ```
 
+### Windows 10 WSL安装(WSL ubuntu)
+
+--------------
+
+1. 安装Windows 10 WSL ubuntu系统
+
+    安装Windows 10 WSL运行环境,发行版本选择ubuntu系统。安装步骤请参考[WSL安装说明](https://docs.microsoft.com/en-us/windows/wsl/install-win10)
+
+1. 安装smartdns
+
+    下载安装包`smartdns.xxxxxxxx.x86_64.tar.gz`,并解压到D盘根目录。解压后目录如下:
+
+    ```shell
+    D:\SMARTDNS
+    ├─etc
+    │  ├─default
+    │  ├─init.d
+    │  └─smartdns
+    ├─package
+    │  └─windows
+    ├─src
+    └─systemd
+
+    ```
+
+    双击`D:\smartdns\package\windows`目录下的`install.bat`进行安装。要求输入密码时,请输入`WLS ubuntu`的密码。
+
+1. 修改配置
+
+    记事本打开`D:\smartdns\etc\smartdns`目录中的`smartdns.conf`配置文件配置smartdns。具体配置参数参考`配置参数`说明。  
+    一般情况下,只需要增加`server [IP]:port`, `server-tcp [IP]:port`配置项,
+    尽可能配置多个上游DNS服务器,包括国内外的服务器。配置参数请查看`配置参数`章节。
+
+1. 重新加载配置
+
+    双击`D:\smartdns\package\windows`目录下的`reload.bat`进行安装。要求输入密码时,请输入`WLS ubuntu`的密码。
+
+1. 将DNS请求转发的SmartDNS解析。
+
+    将Windows的默认DNS服务器修改为`127.0.0.1`,具体步骤参考[IP配置](https://support.microsoft.com/zh-cn/help/15089/windows-change-tcp-ip-settings)
+
+1. 检测服务是否配置成功。
+
+    使用`nslookup -querytype=ptr 0.0.0.0`查询域名  
+    看命令结果中的`name`项目是否显示为`smartdns`或`主机名`,如`smartdns`则表示生效  
+
+    ```shell
+    pi@raspberrypi:~/code/smartdns_build $ nslookup -querytype=ptr 0.0.0.0
+    Server:         192.168.1.1
+    Address:        192.168.1.1#53
+
+    Non-authoritative answer:
+    0.0.0.0.in-addr.arpa  name = smartdns.
+    ```
+
+
 ## 配置参数
 
 |参数|功能|默认值|配置值|例子|

+ 34 - 6
install

@@ -4,6 +4,7 @@
 #
 
 INST_DIR=$(cd $(dirname $0);pwd)
+ISWSL=1 # 1 means not WSL, 0 means wsl 
 
 showhelp()
 {
@@ -18,7 +19,7 @@ showhelp()
 start_service()
 {
 	if [ $ISSYSTEMD -ne 0 ]; then
-		chkconfig smartdns on
+		chkconfig smartdns on >/dev/null 2>&1
 		service smartdns start
 		return $?
 	fi
@@ -32,7 +33,7 @@ stop_service()
 {
 	if [ $ISSYSTEMD -ne 0 ]; then
 		service smartdns stop
-		chkconfig smartdns off
+		chkconfig smartdns off >/dev/null 2>&1
 		return 0
 	fi
 
@@ -101,13 +102,17 @@ install_files()
 uninstall_smartdns()
 {
 	if [ -z "$PREFIX" ]; then
-		stop_service
+		stop_service 2>/dev/null
 	fi	
 	rm -f $PREFIX$SMARTDNS_CONF_DIR/smartdns.conf
-	rmdir $PREFIX$SMARTDNS_CONF_DIR
+	rmdir $PREFIX$SMARTDNS_CONF_DIR 2>/dev/null
 	rm -f $PREFIX/usr/sbin/smartdns
 	rm -f $PREFIX/etc/default/smartdns
 
+	if [ $ISWSL -eq 0 ]; then
+		sed -i '\#%sudo ALL=NOPASSWD: /etc/init.d/smartdns#d' /etc/sudoers 2>/dev/null
+	fi
+
 	if [ $ISSYSTEMD -eq 0 ]; then
 		SYSTEM_UNIT_PATH="`get_systemd_path`"
 		if [ ! -z "$SYSTEM_UNIT_PATH" ]; then
@@ -125,6 +130,12 @@ install_smartdns()
 {
 	local ret
 
+	which smartdns >/dev/null 2>&1
+	if [ $? -eq 0 ]; then
+		echo "Already installed."
+		return 1
+	fi
+
 	install_files
 	ret=$?
 	if [ $ret -ne 0 ]; then
@@ -136,17 +147,34 @@ install_smartdns()
 		start_service
 	fi
 
+	if [ $ISWSL -eq 0 ]; then
+		grep "%sudo ALL=NOPASSWD: /etc/init.d/smartdns" /etc/sudoers >/dev/null 2>&1
+		if [ $? -ne 0 ]; then
+			echo "%sudo ALL=NOPASSWD: /etc/init.d/smartdns" >> /etc/sudoers
+		fi
+	fi
+
 	return 0
 }
 
-
-
 init_dir()
 {
+	local ID=`id -u`
+	if [ $ID -ne 0 ]; then
+		echo "Please run as root."
+		return 1
+	fi
+
 	SMARTDNS_CONF_DIR=$PREFIX/etc/smartdns
 	SMARTDNS_INIT_DIR=$PREFIX/etc/init.d
 	which systemctl >/dev/null 2>&1
 	ISSYSTEMD="$?"
+	# Running under WSL (Windows Subsystem for Linux)?
+	cat /proc/version | grep Microsoft >/dev/null 2>&1; 
+	if [ $? -eq 0 ]; then
+		ISSYSTEMD=1
+		ISWSL=0
+	fi
 
 	cd $INST_DIR
 }

+ 21 - 0
package/windows/install.bat

@@ -0,0 +1,21 @@
+@echo off
+set "CURR_PATH=%~dp0"
+set "STARTUP_PATH=%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
+FOR /F %%i IN ('wsl pwd') DO @set DIR_IN_WSL=%%i
+
+wsl sudo %DIR_IN_WSL%/../../install -i
+IF NOT %ERRORLEVEL% == 0 (
+  echo Install smartdns failed.
+  pause
+  exit 1
+)
+
+copy %CURR_PATH%\wsl-run.vbs "%STARTUP_PATH%/"
+IF NOT %ERRORLEVEL% == 0 (
+  echo Install startupt script failed.
+  pause
+  exit 1
+)
+
+echo Install smartdns success
+pause

+ 21 - 0
package/windows/reload.bat

@@ -0,0 +1,21 @@
+@echo off
+set "CURR_PATH=%~dp0"
+set "STARTUP_PATH=%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
+FOR /F %%i IN ('wsl pwd') DO @set DIR_IN_WSL=%%i
+
+wsl sudo cp -avf %DIR_IN_WSL%/../../etc/smartdns/* /etc/smartdns/ 
+IF NOT %ERRORLEVEL% == 0 (
+  echo copy smartdns configuration file failed.
+  pause
+  exit 1
+)
+
+wsl sudo /etc/init.d/smartdns restart
+IF NOT %ERRORLEVEL% == 0 (
+  echo reload smartdns failed.
+  pause
+  exit 1
+)
+
+echo reload smartdns success
+pause

+ 22 - 0
package/windows/uninstall.bat

@@ -0,0 +1,22 @@
+@echo off
+set "CURR_PATH=%~dp0"
+set "STARTUP_PATH=%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
+FOR /F %%i IN ('wsl pwd') DO @set DIR_IN_WSL=%%i
+
+wsl sudo %DIR_IN_WSL%/../../install -u
+IF NOT %ERRORLEVEL% == 0 (
+  echo Uninstall smartdns failed.
+  pause 
+  exit 1
+)
+
+del "%STARTUP_PATH%\wsl-run.vbs"
+IF NOT %ERRORLEVEL% == 0 (
+  echo Uninstall startup script failed.
+  pause 
+  exit 1
+)
+
+echo uninstall success
+
+pause

+ 2 - 0
package/windows/wsl-run.vbs

@@ -0,0 +1,2 @@
+Set ws = WScript.CreateObject("WScript.Shell")
+ws.run "wsl sudo /etc/init.d/smartdns restart", vbhide