ubuntu server IP 及DNS设置

来源:互联网 发布:c语言编程培训线上课程 编辑:程序博客网 时间:2024/05/16 11:32
装完ubuntu 第一件事情就是连上网,换个源,进行更新操作,但前提条件是要配好ip和dns。
下面把自己配置的过程记录下来,权且当作一份备份,以便不时之需。
 
一、配置ip
ubuntu的网络配置信息放在/etc/network/interfaces 中,
 
 
 
操作:
 
sudo vim /etc/network/interfaces
 
vim是一个类似DOS下edit的文本编辑软件。和前面介绍过的软件vi用法类似
 
如果配置动态获取ip,则在上述文件中加入以下内容:(注:服务器通常不用动态IP)
auto eth0
iface eth0 inet dhcp
 
如果配置静态ip,则添加如下内容:
auto eth0
iface eth0 inet static
  address 192.168.1.201
netmask 255.255.255.0
  gateway 192.168.1.1
 
要是配置生效,需要重启网卡:
ifconfig eth0 down
ifconfig eth0 up
 
   
 
  接着用ifconfig命令查看ip是否配置成功
 
   
若还有没有配置成功,则需重启下网络服务
/etc/init.d/networking restart
 
二、配置dns服务器
ubuntu 的dns服务器信息,放在/etc/resolv.conf中,
添加dns服务器地址,如202.112.125.53,则在上述文件中加入

nameserver 202.112.125.53

由于该文件会在重启后被系统更改,需要运行下面命令来防止系统重启后修改。
sudo chattr +i /etc/resolv.conf


小结:
只要按上面的步骤配置完,就能上网了,如果还不行就重启下机器试试。
NOTE: in ubuntu12.04, don't support chattr for such file, need update the resolve.conf with the following steps:-
(1) sudo resolvconf -u
(2) vi /etc/resolvconf/resolv.conf.d/base
nameserver 192.168.11.189
(3) sudo resolvconf -u
The /etc/resolv.conf will be updated based on the base file in step 2.


0 0
原创粉丝点击