日期:2014-05-16  浏览次数:20757 次

本机访问虚拟机上的linux
第一步:虚拟机配置

第二部:linux配置
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0                    #网络设备名称,与ifcfg-eth0对应
#BOOTPROTO=dhcp                #启动eth0接口时使用动态IP地址分配                                                                 
                               #这里使用的是静态IP地址,因此将这句屏蔽掉
BOOTPROTO=static               #启动eth0接口时使用静态IP地址分配
HWADDR=00:E0:4C:61:71:E3       #MAC地址
IPADDR=219.246.177.160         #设置IP地址
NETMASK=255.255.255.0          #设置子王掩码
GATEWAY=219.246.177.1          #设置网关
ONBOOT=yes                     #开机时启动

修改好后,要想将修改的配置不用重启而生效。输入命令
[root@localhost ~]# ifdown eth0
将eth0网络接口关闭,再输入下面的命令将eth0接口重新启动
[root@localhost ~]# ifup eth0
这个命令会到 /etc/sysconfig/network-scripts/下读取相应参数,使刚配置内容生效。
或者输入
[root@localhost ~]# /etc/init.d/network restart
重新启动整个网络的参数。/etc/init.d/network这个文件也是开机时加载的文件。
这样就可以解决IP设置的问题拉。如果需要设置DNS,则编辑/etc/resolv.conf文件
[root@localhost ~]# vi /etc/resolv.conf
nameserver 202.201.0.131
nameserver 202.201.0.132
nameserver 202.201.89.131
search lzu.edu.cn
~
配置好后当然还得输入[root@localhost ~]# /etc/init.d/network restart,重新启动整个网络的参数。才能生效。
第三步:本机配置
然后,在本机下载SSH。
如果linux重启后,eth0无法自动启动,使用一下方法。
[root@localhost ~]# more /etc/rc.local   //我在网上搜到的,把那个ifup命令加了进去
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
ifup eth0

重启后就网卡就自动激活了