开发者社区 > 域名解析DNS > 云解析DNS > 正文

云服务器 ECS Linux Ubuntu 系统修改 resolv 文件中的 DNS信息后重启自动还

云服务器 ECS Ubuntu系统修改 resolv.conf 文件后,重启系统后,自动还原了之前的 DNS 配置信息。如下图所示:

image.png

展开
收起
开发者说 2019-08-01 16:15:16 1583 0
1 条回答
写回答
取消 提交回答
  • 问题原因

    Ubuntu 系统中 /etc/resolv.conf 其实是一个软连接(Link),它其实指向的是 /run/resolvconf/resolv.conf。如果需求开机不进行自动还原,需要修改上述文件。

    也可以直接修改网卡配置文件,或者修改 /etc/resolvconf/resolv.conf.d/tail 文件后通过 resolvconf -u 命令进行更新。

    解决方案

    可以参阅如下步骤进行修改和调整:

    1、修改 /run/resolvconf/resolv.conf

    $ vi /run/resolvconf/resolv.conf
    # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
    #     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
    options timeout:1 attempts:1 rotate
    nameserver 223.5.5.5
    nameserver 223.6.6.6
    
    

    2、在网卡配置文件 /etc/network/interfaces 里面添加相应 DNS 服务器地址,比如:dns-nameservers 223.5.5.5 223.6.6.6

    $ vi /etc/network/interfaces
    auto lo
    iface lo inet loopback
    auto eth1
    iface eth1 inet static
    address 112.*.*.131
    netmask 255.255.252.0
    dns-servers 223.5.5.5 223.6.6.6
    up route add -net 0.0.0.0 netmask 0.0.0.0 gw 112.*.*.247 dev eth1
    auto eth0
    iface eth0 inet static
    address 10.*.*.214
    netmask 255.255.240.0
    up route add -net 172.16.0.0 netmask 255.240.0.0 gw 10.*.*.247 dev eth0
    up route add -net 100.64.0.0 netmask 255.192.0.0 gw 10.*.*.247 dev eth0
    up route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.*.*.247 dev eth0
    ~
    
    

    3、修改 /etc/resolvconf/resolv.conf.d/tail ,然后通过 resolvconf -u 命令进行更新:

    $ vi /etc/resolvconf/resolv.conf.d/tail 
    options timeout:1 attempts:1 rotate
    nameserver 223.5.5.5
    nameserver 223.6.6.6
    root@iZ28ig469cdZ:~# resolvconf -u
    
    Stopped Name Service Cache Daemon: nscd.
    
    
    
    Starting Name Service Cache Daemon nscd
    
    ...done.
    
    2019-08-01 16:16:27
    赞同 展开评论 打赏

阿里云云解析DNS产品相关资讯

相关产品

  • 云解析DNS
  • 相关电子书

    更多
    神龙云服务器产品及技术深度解析 立即下载
    弹性创造价值:基于ECS的最佳性价比实践解析 立即下载
    又快又稳:阿里云下一代虚拟交换机解析 立即下载