Windows10 玩SmartDNS告别污染

GitHub项目:SmartDns4Win

WSL安装

Win10需要用linux子系统WSL支持,WSL的开启方法如下:
PowerShell 下执行以下命令开启WSL功能:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux /all

普通命令行cmd下执行:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

如果你像我一样用的是精简过的Win10系统的话,上面的命令会出错,需要用到功能恢复包,我下面度盘分享提供了1809和1903两个版本的功能恢复包,自行选择即可。功能恢复包使用后需要重启才能生效。

参考下图的操作修改一下cmd的属性,不然安装WSL子系统实例会出错


命令行工具属性修改

参考微软官方《手动下载适用于 Linux 的 Windows 子系统发行版包》下载Debian包,修改文件类型为 *.zip,解压至你想要安装的路径,比如: D:\Program Files\Debian,执行debian.exe安装,按需设置新用户名称和密码...

更换清华源, 参考;遇到无法拉取 https 源的情况, 参考

/etc/apt/sources.list
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free

Smartdns安装

将我分享的smartdns压缩包解压至不含空格的路径中,比如: D:\Tools\smartdns,从原项目的Release下载Debian适用的包:smartdns.1.***.x86_64-debian-all.deb,放入上面的目录中,管理员权限执行批处理文件 init.bat,中间有停顿需要输入上面刚刚新建的用户密码,一路回车即可...

手动设置本地连接DNS ,如下图,首选填127.0.0.1,备用选填:

DNS Setting

打开命令行窗口测试一下,nslookup www.google.com,出现类似下面的结果就说明成功了!

C:\>nslookup www.google.com
服务器:  localdomain
Address:  127.0.0.1

非权威应答:
DNS request timed out.
    timeout was 2 seconds.
名称:    www.google.com
Address:  69.63.184.14

工具包度盘链接: https://pan.baidu.com/s/1_WakgCRpOjahlw760igYNg 提取码: 2333

感谢:

GitHub用户 rufengsuixing 分享的Win10一键安装脚本

升级WSL2

WSL 2 仅适用于 Windows 10 版本 18917 或更高版本,参考

通过运行(Win+R) winver查看

查看版本号

你需要确保同时安装了”适用于 Linux 的 Windows 子系统”和”虚拟机平台”可选组件。 可以通过在 PowerShell 中运行以下命令来执行该操作:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

或者控制面板启用系统功能:

启用系统功能

完成后重启系统。
更新 WSL 2 Linux 内核下载补丁
命令行执行wsl --set-version Debian 2即可将已安装的Debian升级到WSL2版。

Debian in WSL 安装python

apt安装方式

sudo apt-get install python3
python3 -V    # check version of python3
sudo apt-get install python3-pip

安装Miniconda 参考

下载Linux下的安装包:64位32位

sudo bash Miniconda3-latest-Linux-x86_64.sh
#一路Enter,一路yes... 
#最后选择路径时注意,默认的/root/anaconda3可能权限问题,装完了无法使用
Miniconda3 will now be installed into this location:
/root/miniconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

[/root/miniconda3] >>>/home/$USER/anaconda3    #自定义安装路径
#装完后编辑/home/$USER/.bashrc,追加一行
echo 'export PATH="$PATH:/home/$USER/anaconda3/bin"' >> /home/$USER/.bashrc
#软连接
sudo ln -s /opt/anaconda3/bin/python /usr/bin/python
sudo ln -s /opt/anaconda3/bin/pip /usr/bin/pip
sudo ln -s /opt/anaconda3/bin/conda /usr/bin/conda

重新启动shell,设置conda源;批量更新 conda update conda

软连接的操作是为了解决sudo python提示找不到命令的错误,参考

折腾SageMath

SageMath的deb包下载

解决deb包的依赖问题

  1. 执行完dpkg命令后,执行sudo apt-get -f install
  2. 安装gdebi,之后执行sudo gdebi package.deb会自动安装上依赖文件

apt-get安装和卸载命令

apt-get update:更新安装列表
apt-get upgrade:升级软件
apt-get install software_name :安装软件
apt-get --purge remove software_name :卸载软件及其配置
apt-get autoremove software_name:卸载软件及其依赖的安装包
dpkg --list:罗列已安装软件

WSL升级Debian到10(Buster)

补足WSL中的ps命令

直接运行sudo apt-get install procps 会遇到各种依赖版本不适用的问题,所以采用安装deb包的方式补足:procps_3.3.15-2_amd64.deb,依赖libprocps7_3.3.15-2_amd64.deb
使用sudo gdebi package.deb依次安装libprocps7procps即可补足。
补足后测试效果:ps aux|grep python

安装SSH

参考

#  - 修改SSH Server的监听端口,这里修改为33
sudo sed -i '/Port /c Port 33' /etc/ssh/sshd_config
#  - 修改SSH Server的监听地址
sudo sed -i '/ListenAddress 0.0.0.0/c ListenAddress 0.0.0.0' /etc/ssh/sshd_config
#  - 修改SSH Server允许使用用户名密码的方式登录
sudo sed -i '/PasswordAuthentication /c PasswordAuthentication yes' /etc/ssh/sshd_config
#  - 修改SSH Server允许远程root用户登录
sudo sed -i '/PermitRootLogin /c PermitRootLogin yes' /etc/ssh/sshd_config
# - 重启ssh服务
sudo service ssh restart

免密sudo

username自行修改

# 编辑文件/etc/sudoers.d/passwordless
sudo vi /etc/sudoers.d/passwordless
# 文件内容
username    ALL=(ALL) NOPASSWD:ALL 

SSH自动启动

sudo vi ~/.profile
# 文件末插入
sudo service ssh start

WinSCP提权

# 查看sftp-server执行文件目录:
cat /etc/ssh/sshd_config|grep sftp
Subsystem       sftp    /usr/lib/openssh/sftp-server
# 编辑/etc/sudoers为特定用户添加执行sftp sudo权限:
# 修改为可写
chmod +w /etc/sudoers
vi /etc/sudoers
# 添加如下字段
username    ALL=NOPASSWD:  /usr/lib/openssh/sftp-server
# 再次修改为只读
chmod -w /etc/sudoers
WinSCP会话-高级设置

End

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。