ubuntu server设置静态IP和DNS

设置IP:

vim /etc/network/interfaces

将以下内容:

auto eth0
iface eth0 inet dhcp

修改为:

auto eth0
#iface eth0 inet dhcp
iface eth0 inet static
address xxx.xxx.xxx.xxx
netmask xxx.xxx.xxx.xxx
gateway xxx.xxx.xxx.xxx

把xxx.xxx.xxx设置为你要个性的信息既可,其中
auto eth0  #开机自动连接网络
iface eth0 inet static   #static表示使用固定ipdhcp表述使用动态ip
address 是本机IP地址
netmask 子网掩码
gateway 网关

如果使用nano编辑的话
ctrl+o  #保存配置
ctrl+x  #退出

设置DNS

linux系统的DNS信息是保存在/etc/resolv.conf , 但是在ubuntu中用vim打开这个文件你会发现有如下文字的提示

DO NOT EDIT THIS FILE BY HAND — YOUR CHANGES WILL BE OVERWRITTEN

所以不能直接个性这个文件,这个内容可能会被覆盖

在ubuntu中dns信息是放在/etc/resolvconf/resolv.conf.d/目录下

一般情况下这个目录下有base和head两个文件夹

vim /etc/resolvconf/resolv.conf.d/base

nameserver 8.8.8.8
nameserver 114.114.114.114

保存后执行

resolvconf -u

用以下命令使网络设置生效

service networking restart
sudo /etc/init.d/networking restart

  • 本文固定链接: http://piaoyun.cc/ubuntu-server-ip-dns.html

  • 转载请注明: 飘云 


你可能感兴趣的:(ubuntu server设置静态IP和DNS)