---
title: "Ubuntu12.04 Server版 配置记录"
author: "wenqxin"
date: "2013-07-16T23:28:35Z"
tags: []
categories: ["操作系统"]
slug: "ubuntu12-04-server"
draft: false
lastmod: "2013-07-16T23:31:02Z"
id: 1908135
url: "https://sectioncc.iteye.com/blog/1908135"
---

**1.单网卡配单IP（普遍）**

 

```

```

1. vi /etc/network/interface
2. auto eth0
3. iface eth0 inet static
4. address IP
5. netmask 子网掩码
6. gateway 网关

<!--THE END-->

1. 打开文件/etc/network/interfaces ，确保Network Manager 处于未开启状态（见上），同时配置以下内容：
   
   - **\[html]** [view plain](http://blog.csdn.net/tlh3930101/article/details/7525628 "view plain")[copy](http://blog.csdn.net/tlh3930101/article/details/7525628 "copy")
     
     01. # The loopback network interface（配置环回口）
     02. auto lo                                    # 开机自动激lo接口
     03. iface lo inet loopback                     # 配置lo接口为环回口
     04. # The primary network interface （配置主网络接口）
     05. auto eth0                                  #开机自动激活eth0接口
     06. iface eth0 inet static                     #配置eth0接口为静态设置IP地址
     07. address 10.16.3.99
     08. netmask 255.255.255.0
     09. network 10.16.3.0
     10. broadcast 10.16.3.255
     11. gateway 10.16.3.1
     
     方法一（推荐）：命令行安装
     
     只需要一条命令：
     
     ```
     sudo apt-get install openssh-server
     ```
     
     随后，Ubuntu 会自动下载并安装 openssh server，并一并解决所有的依赖关系。
     
     想了解更详细的内容，请查看：http://www.[linuxidc.com/Linux/2011-04/34588p3.htm](http://linuxidc.com/Linux/2011-04/34588p3.htm)
     
     方法二 ：通过 Ubuntu Software Center 安装
     
     首先进入 Ubuntu Software Center，然后在搜索栏里输入“openssh-server”；
     
     随后会看到搜索结果里有openssh-server；
     
     接着点击“Install”就可安装。
   - ```
     sudo /etc/init.d/ssh start
     ```
     
     2\. 然后通过下面的命令查看[IP地址](http://finger.blog.51cto.com/211738/57990)：
     
     ```
     ifconfig
     ```
     
     .设置IP，终端输入 sudo gedit /etc/network/interfaces
     
     假设实用的是网卡0，如果是其它网卡就将eth0改为对应的值。
     
     auto loiface lo inet loopback#使用网卡0auto eth0#使用静态IPiface eth0 inet static #设置IPaddress 172.32.1.11#设置子网掩码，不要弄错了，可以自己算的，具体可能不一样的，由IP决定！netmask 255.255.0.0#设置网关gateway 172.32.1.2152.
     
     配置DNS
     
     如果需要手动配置DNS终端输入sudo  vi /etc/resolv.conf  在其中加入以下代码（211.153.31.2换为你的DNS）nameserver 211.153.31.23.
     
     重启网络sudo /etc/init.d/networking restart提示ok之后可以试试能否ping到网关和局域网内的其它机器，然后再试试能否上网！ 
     
      
     
     **注意双网卡的端口的差别，安装的问题即由网口的插法有错，与技术无关。。**
     
      
     
      
     
     安装完Ubuntu后忽然意识到没有设置root密码，不知道密码自然就无法进入根用户下。到网上搜了一下，原来是这麽回事。Ubuntu的默认root密码是随机的，即每次开机都有一个新的root密码。我们可以在终端输入命令 sudo passwd，然后输入当前用户的密码，enter，终端会提示我们输入新的密码并确认，此时的密码就是root新密码。修改成功后，输入命令 su root，再输入新的密码就ok了。
     
      
     
      
     
     service networking restart 中，需要提前加入sudo
     
      
     
     * * *
     
     ubuntu12.04重置root密码 
     
           使用ubuntu的时候忘记了root密码该如何重置
     
            先说进入grub的方法，ubuntu最近的版本默认进入grub的方法是刚开机的时候按住shift键。
     
            我之前使用的版本ubuntu11.10修改root重置root密码的方法：
     
      
     
           #1、开机进入grub时(开机按住esc进入grub)，用上下键移到第二行的恢复模式，按e(注意不是回车)）
     
           #2、在linux /boot/vmlinuz 最后一行加入 rw init=/bin/bash，也或者叫做（rw single  init=/bin/bash）(总之去掉ro 后面的，) 然后按ctrl+x或者按F10进入；
     
      
     
            #3、进入 单用户模式，进去干什么都行了， (修改root密码的命令是passwd root，然后键入你的新密码即可， 完成后，按”ctrl+alt+delete“组合神键重启(我试过用命令关机，重启都不行，只能用这个)。
     
      
     
          而ubuntu的最新版本12.04的方法是：（此方法理论可行，但在12.04服务器版本不通过，报give root password for maintainer）
     
      
     
         #1、和上面的第一步一样。
     
        
     
         #2、直接按Ctrl+x进入**recovery menu，**选择**drop to root shell，**然后修改root密码。
     
         
     
         修改root密码的时候可能会提示：Authentication Manipulation error，这时候键入以下命令：
     
           mount -rw -o remount /，然后再修改一次密码
     
     * * *
     
     ubuntu忘记密码或者密码修改坏了怎么解决恢复 （（**此方法在此版本上验证确实可行**））
     
     1，开机当出现Grub 界面时，按“Esc”进入grub:      ubunt 8.04.1, kernel 2.6.24-19-generic 
     
          ubunt 8.04.1, kernel 2.6.24-19-generic (recovery mode)      ubunt 8.04.1, MeMtest86+  
     
     2，选择第二行"ubunt 8.04.1, kernel 2.6.24-19-generic (recovery mode)"，按“Enter”进入Recovery Menu:  
     
         resume  resume normal boot     dpkg    repair broken packages     root    drop to root shell prompt     xfix    try to fix x server 
     
     3，选择"root    drop to root shell prompt",按“Enter”  
     
        接着就提示：    root@QA-desktop:~#  
     
        于是可以使用passwd生成新密码了.    root@QA-desktop:~# passwd root    Enter new password:    Retype new password: 
     
        passwd: password updated successfully    root@QA-desktop:~#     然后reboot就生效了。