执子之手

与子偕老


  • 首页

  • 分类

  • 归档

  • 标签

  • 关于

  • 搜索
close

如何修改Ubuntu服务器上的DNS设置

时间: 2020-07-10   |   分类: 运维     |   阅读: 620 字 ~2分钟   |   访问: 0

公司的几台服务器安装的时候设置了联通的DNS服务器,由于公司网络切换到了电信,最近经常出现解析服务器IP失败的情况。所以想着要更换一下DNS服务器,以提高网络访问速度。

因为历史原因,服务器操作系统主要有 Ubuntu 16.04 LTS 和 Ubuntu 18.04 LTS 两种。实际修改中发现,他们的配置方法是不一样的,特此记录一下。

1. Ubuntu 16.04 LTS

16.04 LTS上主要修改两个文件。

2.1 更新resolv.conf

首先修改文件:/etc/resolvconf/resolv.conf.d/base文件,内容如下:

1nameserver 114.114.114.114
2nameserver 223.5.5.5

然后执行:resolvconf -u命令就可以更新dns服务器了。

2.2 network/interfaces

然后修改文件:/etc/network/interfaces文件,删除其中的dns-nameservers配置项:

 1# This file describes the network interfaces available on your system
 2# and how to activate them. For more information, see interfaces(5).
 3
 4source /etc/network/interfaces.d/*
 5
 6# The loopback network interface
 7auto lo
 8iface lo inet loopback
 9
10# The primary network interface
11auto ens33
12#iface ens33 inet dhcp
13iface ens33 inet static
14address 192.168.2.231
15netmask 255.255.255.0
16gateway 192.168.2.1
17#dns-nameservers 202.102.134.68 202.102.128.68                                               

然后重启network服务:/etc/init.d/networking restart,这样就可以了。

实际修改中,大部分服务器修改第一个就可以起效了,只有个别的需要修改两个。为了防止歧义,推荐两个都修改。

2. Ubuntu 18.04 LTS

对 18.04 LTS 来说,配置文件变更为:/etc/netplan/*.yaml。例如:

 1# This file is generated from information provided by
 2# the datasource.  Changes to it will not persist across an instance.
 3# To disable cloud-init's network configuration capabilities, write a file
 4# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
 5# network: {config: disabled}
 6network:
 7    ethernets:
 8        ens160:
 9            addresses:
10            - 192.168.2.237/24
11            dhcp4: false
12            gateway4: 192.168.2.1
13            nameservers:
14                addresses:
15#                - 202.102.134.68
16#                - 202.102.128.68
17                - 114.114.114.114
18                - 223.5.5.5
19                search: []
20    version: 2

修改完成之后使用:sudo netplan apply生效。

#Ubuntu# #DNS#
使用KeepAlived配置Nginx高可用
在Mac上编译RedisDesktopManager(1)国际化处理
  • 文章目录
  • 站点概览
Orchidflower

Orchidflower

Do one thing at a time, and do well.

77 日志
6 分类
84 标签
GitHub 知乎 OSC 豆瓣
  • 1. Ubuntu 16.04 LTS
    • 2.1 更新resolv.conf
    • 2.2 network/interfaces
  • 2. Ubuntu 18.04 LTS
© 2009 - 2024 执子之手
Powered by - Hugo v0.113.0
Theme by - NexT
ICP - 鲁ICP备17006463号-1
0%