---
title: 在本机配置 CNAME
date: 2022-10-10T08:19:46.754Z
updated: 2022-10-10T08:19:46.754Z
tags:
  - article
  - linux
  - dns
---

1. 安装 dnsmasq

   ```bash
   sudo apt-get install dnsmasq
   ```

1. 配置 dnsmasq

   ```bash
   vi /etc/dnsmasq.d/test.conf # 随便开一个文件
   ```

   > 填入：

   ```ini
   cname=from.gaubee.com,to.gaubee.com
   ```

1. 修改本地 dns 配置：

   ```bash
   vi /etc/resolv.conf
   # 添加一行 nameserver 127.0.0.1
   ```

   > 最终我自己本地这个文件是这样的

   ```ini
   # This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
   # [network]
   # generateResolvConf = false
   nameserver 127.0.0.1
   nameserver 172.19.208.1
   ```

1. 最后启动 dnsmasq 即可：

   ```bash
   /etc/init.d/dnsmasq start
   ```

   > 它会监听本地 53 断开（DNS 服务的端口），如果报端口占用。那么查看一下占用程序

   ```bash
   sudo lsof -i -P -n | grep LISTEN
   ```
