Ubuntu DNS配置与使用命令设置Ubuntu的ip地址

系统 Linux
设置Ubuntu DNS 修改/etc/resolv.conf,在其中加入nameserver DNS的地址1nameserver DNS的地址2完成。这样设置之后,下次开机时候似乎IP又会发生变化。

经过长时间学习Ubuntu DNS,你可能会遇到Ubuntu DNS中网络问题,这里将介绍Ubuntu DNS解决网络问题的方法,新装了Ubuntu,虽然使用图形界面明明已经设置好了ip,网关等等,但是不能上网。

一个朋友提醒说,也许是设置的问题,试试命令行的设置。于是搜索了一下怎么设置,结果还真的成功了。具体如下:
1. 检验是否可以连通,就使用ping命令ping 网关开始的时候总是现实unreachable
2. 设置IP sudo ifconfig eth0 133.133.133.190 netmask 255.255.255.0这样就算设置好了网卡eth0的IP地址和子网掩码
3. 设置网关 sudo route add default gw 133.133.133.40
4. ping 网关就可以ping通了
5. 设置Ubuntu DNS 修改/etc/resolv.conf,在其中加入
nameserver DNS的地址1
nameserver DNS的地址2完成。这样设置之后,下次开机时候似乎IP又会发生变化。

一、使用命令设置Ubuntu的ip地址

1. 设置IP sudo ifconfig eth0 203.171.239.155 netmask 255.255.255.224 这样就算设置好了网卡eth0的IP地址和子网掩码
2. 设置网关 sudo route add default gw 203.171.239.129
3. 设置DNS 修改/etc/resolv.conf,在其中加入 nameserver DNS的地址1 nameserver DNS的地址2 完成。不过,这样设置之后,下次开机时候似乎IP又不存在了。

二、直接修改系统配置文件

Ubuntu的网络配置文件是:/etc/network/interfaces
Ubuntu命令行修改网络配置方法/etc/network/interfaces打开后里面可设置DHCP或手动设置静态ip。前面auto eth0,让网卡开机自动挂载.

1. 以DHCP方式配置网卡
编辑文件/etc/network/interfaces:sudo vi /etc/network/interfaces.并用下面的行来替换有关eth0的行:

  1. # The primary network interface - use DHCP to find our address  
  2. auto eth0  
  3. iface eth0 inet dhcp 

用下面的命令使网络设置生效:sudo /etc/init.d/networking restart也可以在命令行下直接输入下面的命令来获取地址sudo dhclient eth0

2. 为网卡配置静态IP地址
编辑文件/etc/network/interfaces:sudo vi /etc/network/interfaces.并用下面的行来替换有关eth0的行:# The primary network interface

  1. auto eth0  
  2. iface eth0 inet static  
  3. address 192.168.3.90  
  4. gateway 192.168.3.1  
  5. netmask 255.255.255.0  
  6. #network 192.168.3.0  
  7. #broadcast 192.168.3.255 

将上面的ip地址等信息换成你自己就可以了.用下面的命令使网络设置生效:sudo /etc/init.d/networking restart

3. 设定第二个IP地址(虚拟IP地址)
编辑文件/etc/network/interfaces:sudo vi /etc/network/interfaces.在该文件中添加如下的行:

  1. auto eth0:1  
  2. iface eth0:1 inet static  
  3. address 192.168.1.60  
  4. netmask 255.255.255.0  
  5. network x.x.x.x  
  6. broadcast x.x.x.x  
  7. gateway x.x.x.x 

根据你的情况填上所有诸如address,netmask,network,broadcast和gateways等信息.用下面的命令使网络设置生效:sudo /etc/init.d/networking restart

4. 设置主机名称(hostname)
使用下面的命令来查看当前主机的主机名称:sudo /bin/hostname
使用下面的命令来设置当前主机的主机名称:sudo /bin/hostname newname
系统启动时,它会从/etc/hostname来读取主机的名称.
关于设置主机名称的更多信息,请访问这里

5. 配置Ubuntu DNS
首先,你可以在/etc/hosts中加入一些主机名称和这些主机名称对应的IP地址,这是简单使用本机的静态查询.要访问Ubuntu DNS 服务器来进行查询,需要设置/etc/resolv.conf文件.假设Ubuntu DNS服务器的IP地址是192.168.3.2, 那么/etc/resolv.conf文件的内容应为:
search test.com
nameserver 192.168.3.2
/etc/network/interfaces
打开后里面可设置DHCP或手动设置静态ip。前面auto eth0,让网卡开机自动挂载.

1. 以DHCP方式配置网卡

编辑文件/etc/network/interfaces:sudo vi /etc/network/interfaces并用下面的行来替换有关eth0的行:

  1. # The primary network interface - use DHCP to find our address  
  2. auto eth0  
  3. iface eth0 inet dhcp 

用下面的命令使网络设置生效:sudo /etc/init.d/networking restart也可以在命令行下直接输入下面的命令来获取地址sudo dhclient eth0

2. 为网卡配置静态IP地址
编辑文件/etc/network/interfaces:sudo vi /etc/network/interfaces
并用下面的行来替换有关eth0的行:# The primary network interface

  1. auto eth0  
  2. iface eth0 inet static  
  3. address 192.168.3.90  
  4. gateway 192.168.3.1  
  5. netmask 255.255.255.0  
  6. #network 192.168.3.0  
  7. #broadcast 192.168.3.255 

将上面的ip地址等信息换成你自己就可以了.用下面的命令使网络设置生效:sudo /etc/init.d/networking restart

3. 设定第二个IP地址(虚拟IP地址)
编辑文件/etc/network/interfaces:sudo vi /etc/network/interfaces在该文件中添加如下的行:

  1. auto eth0:1  
  2. iface eth0:1 inet static  
  3. address 192.168.1.60  
  4. netmask 255.255.255.0  
  5. network x.x.x.x  
  6. broadcast x.x.x.x  
  7. gateway x.x.x.x 

根据你的情况填上所有诸如address,netmask,network,broadcast和gateways等信息.用下面的命令使网络设置生效:sudo /etc/init.d/networking restart

4. 设置主机名称(hostname)
使用下面的命令来查看当前主机的主机名称:sudo /bin/hostname
使用下面的命令来设置当前主机的主机名称:sudo /bin/hostname newname
系统启动时,它会从/etc/hostname来读取主机的名称.关于设置主机名称的更多信息,请访问这里

5. 配置Ubuntu DNS
首先,你可以在/etc/hosts中加入一些主机名称和这些主机名称对应的IP地址,这是简单使用本机的静态查询.要访问Ubuntu DNS 服务器来进行查询,需要设置/etc/resolv.conf文件.假设Ubuntu DNS服务器的IP地址是192.168.3.2, 那么/etc/resolv.conf文件的内容应为:

  1. search test.com  
  2. nameserver 192.168.3.2 

解决Ubuntu重启Ubuntu DNS重新设置的问题作者: wynlchae 发布日期: 2008-4-09 查看数: 256 出自: http://www.linuxdiyf.com在Ubuntu下设置静态IP,“主菜单”,“系统”,“系统管理”,“网络”,在“Ubuntu DNS”里删掉原来的Ubuntu DNS,填上静态的Ubuntu DNS的服务器,不过这样重启后就恢复,下次开机开得重新设置一次。

先备份:sudo cp /etc/resolv.conf /etc/resolv.conf.bak然后编辑sudo gvim /etc/dhcp3/dhclient.conf将以下行添加到末尾,就是Ubuntu DNS的2个服务器啦prepend domain-name-servers 208.67.222.222,208.67.220.220;#这两个服务器根据自己的Ubuntu DNS填上。

【编辑推荐】

  1. Ubuntu DNS服务器设置静态
  2. Ubuntu DNS服务器启动配置
  3. 编辑Ubuntu DNS服务器配置
  4. Ubuntu samba安装创建共享目录及使用
  5. Ubuntu配置文件系统环境初始化
责任编辑:佚名 来源: CSDN
相关推荐

2010-01-04 10:10:00

2010-02-05 12:59:19

Ubuntu IP

2010-03-05 15:05:46

Ubuntu网络配置

2010-02-07 14:41:28

Ubuntu 8.10

2010-01-04 13:29:37

2010-01-07 14:22:17

Ubuntu IP地址

2011-04-14 11:41:41

UbuntuIP

2010-01-04 15:49:11

Ubuntu Serv

2018-12-09 13:50:47

UbuntuLinux IP地址

2010-02-24 14:50:33

Ubuntu vim

2010-01-08 14:25:54

Ubuntu sudo

2011-09-06 16:17:50

Ubuntu

2010-02-06 15:35:31

Ubuntu DNS

2009-12-30 17:47:54

Ubuntu常用命令

2010-01-07 17:59:50

Ubuntu APT

2019-09-08 15:43:19

UbuntuLinuxIP地址

2010-01-04 16:54:00

Ubuntu DNS

2010-01-04 16:46:44

Ubuntu DNS

2016-01-07 14:02:55

Ubuntu 15.1网卡 IP地址

2022-10-27 10:02:58

UbuntuLinux
点赞
收藏

51CTO技术栈公众号