Dnsmasq MacOS使用介绍

问题:

pc端开发时,需要在/etc/hosts里配置各种本地环境;当开发移动的界面时,除了使用浏览器的"手机模式"查看效果,还可以直接使用手机进行查看。但是修改手机的/etc/hosts就比较麻烦了。

解决办法:
  1. 使用dnsmasq在pc上搭建dns服务器
  2. 设置dnsmasq,使其dns解析时,先读取/etc/hosts,然后读取/etc/resolv.conf里配置,使用其配置的dns server做为上有dns server
  3. 在手机上设置wifi网络的dns服务器地址为上步搭建的dns地址(建议设置为唯一的一个dns server地址,避免干扰)

dnsmasq安装

  1. brew install dnsmasq

  2. 配置文件位置:/usr/local/etc/dnsmasq.conf

    端口
    
    port=53(默认值)
    
    上游dns服务配置读取
    
    resolv-file=/etc/resolv.conf
    
    读取/etc/hosts里的配置
    
    addn-hosts=/etc/hosts
    
    监听地址,127.0.0.1和局域网地址都必须设置;这两个都是dnsmasq的dns服务器地址,127.0.0.1是方便本地测试使用的
    
    listen-address=127.0.0.1,x.x.x.x(本机的局域网地址)
    
  3. sudo brew services start/stop/restart dnsmasq(macOS 使用sudo 启动,不然无法生效)

参考

  1. https://www.jianshu.com/p/16323a7f2ecd
  2. https://www.jianshu.com/p/6c56cc5c51e5
  3. https://blog.csdn.net/hxpjava1/article/details/80228118

相关文章:

  • 2021-10-06
  • 2021-07-25
  • 2022-12-23
  • 2021-11-17
  • 2021-11-27
  • 2021-08-09
  • 2021-11-07
  • 2022-01-02
猜你喜欢
  • 2021-10-29
  • 2021-12-22
  • 2022-02-16
  • 2021-06-16
  • 2022-12-23
相关资源
相似解决方案