---
title: "ubuntu server静态IP和DNS服务器设置"
author: "cduym"
date: "2012-12-22T22:46:40Z"
tags: []
categories: ["操作系统"]
slug: "ubuntu-server-ip-dns"
draft: false
lastmod: "2012-12-22T22:50:04Z"
id: 1752481
url: "https://cduym.iteye.com/blog/1752481"
---

Ubuntu的网络参数保存在文件 /etc/network/interfaces中，默认设置使用dhcp，动态IP获取。

设置静态ip的方法如下：  
1） 编辑 /etc/network/interfaces  
1.1）将dhcp 一行屏蔽

\# The primary network interface  
auto eth0  
#iface eth0 inet dhcp

 

1.2）添加和静态ip有关的参数

\# The primary network interface  
iface eth0 inet static  
address 192.168.1,151  
netmask 255.255.255.0  
gateway 192.168.1.1

2）编辑 /etc/resolv.conf，设置dns，如果重启还原，则还需要修改/etc/resolvconf/resolv.conf.d/base文件，两个内容一样

nameserver 192.168.1.1 #路由网关  
nameserver 8.8.8.8 #google的dns服务器

3）执行下面两个命令，启用新设置

$sudo ifdown eth0  
$sudo ifup eth0