---
title: "ubuntu手动设置dns解析"
author: "keren"
date: "2017-05-04T11:27:59Z"
tags: []
categories: ["操作系统"]
slug: "ubuntu-dns"
draft: false
lastmod: "2017-05-04T11:27:38Z"
id: 2372575
url: "https://keren.iteye.com/blog/2372575"
---

/etc/resolv.conf中设置dns之后每次重启Ubuntu Server时该文件会被覆盖，针对这种情况找了一些个解决方法
防止/etc/resolv.conf被覆盖的方法
【方法一】
1.需要创建一个文件/etc/resolvconf/resolv.conf.d/tail

```java

sudo vi /etc/resolvconf/resolv.conf.d/tail

```

2.在该文件中写入自己需要的dns服务器，格式与/etc/resolv.conf相同

```java

nameserver 8.8.8.8 

```

 
3.重启下resolvconf程序

```java

sudo /etc/init.d/resolvconf restart 

```


再去看看/etc/resolv.conf文件,可以看到自己添加的dns服务器已经加到该文件中
【方法二】
在/etc/network/interfaces中

```java

###interfaces中#######     
auto eth0     
iface eth0 inet static     
address 192.168.3.250     
netmask 255.255.255.0                  #子网掩码     
gateway 192.168.3.1                      #网关     
dns-nameservers 8.8.8.8 8.8.4.4    #设置dns服务器  

```


参考：<http://www.linuxidc.com/Linux/2012-06/63054.htm >