Ubuntu使用技巧

1. 设置软件更新源:

     默认的软件更新源是美国的,速度较慢,可以切换到国内的镜像源:

     a. 打开Ubuntu Software Center;

     b. 选择Edit-->Software Sources;

     c. 在Ubuntu Software的Download from中选择Other,然后选择一个中国的镜像源;

     d. 执行sudo apt-get update更新源。

 

2. 为ubuntu虚拟机设置静态IP:

    a. 获取有用信息(IP范围,网关和子网掩码):

        在VMware主界面,点击Edit-->Virtual Network Editor,选择VMnet8,点击NAT Setting,可以看到子网掩码和网关的设置:

  Ubuntu使用技巧_第1张图片

    在VMware主界面,点击Edit-->Virtual Network Editor,选择VMnet8,点击DHCP Setting,可以看到IP范围:

Ubuntu使用技巧_第2张图片

  因此,我们需要的信息汇总为:

   IP可用范围: 192.168.41.128 ~ 192.168.41.254

   子网掩码:     255.255.255.0

   网关:            192.168.41.2

 

b. 在ubuntu中设置静态IP:

    启动虚拟机,按CTRL+ALT+T打开终端,使用如下命令打开并编辑网络接口配置文件:

sudo vi /etc/network/interfaces

   编辑文件内容如下:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.41.200  #change to your static IP
netmask 255.255.255.0   #change to your netmask
gateway 192.168.41.2    #change to your getway

#We must specify dns-nameserver here in order to get internet access from host
dns-nameservers 192.168.41.2

 

c. 重启ubuntu的网卡:

sudo /etc/init.d/networking restart

d. 测试互联网连通性:

ping www.baidu.com
如果ping有响应,那么虚拟机静态IP设置成功,并且也已连入互联网。

备注: 我的虚拟机需要重启才能通过ifconfig看到IP已设置为指定的IP,不知为何。

参考资料: http://www.cnblogs.com/objectorl/archive/2012/09/27/vmware-ubuntu-nat-static-ip-settings.html

3. 使用secureCRT连接ubuntu虚拟机:

3.1 端口映射:

  通过2中设置了静态IP后,宿主机可以通过该IP地址连接到虚拟机,但是网络中的其它电脑要连接该虚拟机,还需要设置端口映射,通过本机IP连接虚拟机,端口映射方法为:

 在VMware主界面,点击Edit-->Virtual Network Editor,选择VMnet8,点击NAT Setting,点击Add,增加端口映射:

Host port设置为主机某个未使用的端口,Virtual machine IP address设置为2中设置的静态IP,virtual machin port设置为22(SSH2所用端口)。


3.2  默认情况下ubuntu安装了ssh client,但未安装ssh server,因此,使用以下命令安装ssh server:

sudo apt-get install openssh-server
 如果找不到安装包,请先使用 sudo apt-get update更新软件源;

 安装成功后,可以使用 ps -e |  grep ssh查看ssh服务,若有sshd,则安装成功并且服务已经启动;

3.3 在SecureCRT中通过SSH2连接ubuntu虚拟机,注意输入正确的hostname,username及password。

 

 

你可能感兴趣的:(Ubuntu使用技巧)