计算机系统结构课的实验,记录一下。
配置
使用桥接模式可以很快的和宿主机ping通,但不勾选复制宿主机的连接。
/etc/sysconfig/network-scripts/ifcfg-eth0
ONBOOT改为yes;BOOTPROTO改成使用静态ip,并在IPADDR指定其ip与宿主机在同一网段;网关和子网掩码与宿主机相同;如要访问外网(为了后面用yum安装rsh),需要设置DNS。
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:5D:10:A2
TYPE=Ethernet
UUID=870109db-2c86-46d5-9acb-b33be0b271c2
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.1.123
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
[root@localhost ~]#
/etc/sysconfig/network
在这里增设网关。
[root@localhost ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost.localdomain
GATEWAY=192.168.1.1
[root@localhost ~]#
/etc/resolv.conf
在这里增设DNS。
[root@localhost ~]# cat /etc/resolv.conf
nameserver 8.8.8.8
[root@localhost ~]#
测试
rsh由于不安全,装好的CentOS基础服务器中没有,可以配好网后yum直接安装。
在宿主机使用SSH协议上传文件
在windows下可以使用putty系列的pscp工具,即可在命令行使用pscp命令仿linux的scp命令(按住shift右键在此处打开命令行),基于SSH跨机远程拷贝文件:
C:\Users\Shinelon\Downloads>pscp -P 22 C:\Users\Shinelon\Downloads\LZH.txt root@192.168.1.123:/tmp/
root@192.168.1.123's password:
C:\Users\Shinelon\Downloads>
在虚拟机CentOS中传输前后:
[root@localhost ~]# ls /tmp
yum.log
[root@localhost ~]# ls /tmp
LZH.txt yum.log
[root@localhost ~]#
如果SSH使用了默认的22端口,那么不需要写-P 22参数。
在宿主机使用SSH协议下载文件
C:\Users\Shinelon\Downloads>pscp -P 22 root@192.168.1.123:/root/install.log C:\Users\Shinelon\Downloads\
root@192.168.1.123's password:
install.log | 27 kB | 27.6 kB/s | ETA: 00:00:00 | 100%
C:\Users\Shinelon\Downloads>
ssh命令做命令传输
再开一个之前的RHEL虚拟机,在这个CentOS中用SSH命令向它发送命令。单引号中是要发给远程主机的命令:
[root@localhost ~]# ls /tmp
LZH.txt yum.log
[root@localhost ~]# ssh root@192.168.1.121 'ls /tmp'
root@192.168.1.121's password:
newname
yum.log
[root@localhost ~]#
ssh命令做文件传输
可以不使用跨机远程拷贝,而直接使用SSH做文件传输,利用管道符和加压解压,如使用tar包:
[root@localhost ~]# ls
anaconda-ks.cfg install.log install.log.syslog
[root@localhost ~]# ssh root@192.168.1.121 'cd / && tar -cv tmp' | tar -xv
root@192.168.1.121's password:
tmp/
tmp/yum.log
tmp/.ICE-unix/
tmp/newname
tmp/
tmp/yum.log
tmp/.ICE-unix/
tmp/newname
[root@localhost ~]# ls
anaconda-ks.cfg install.log install.log.syslog tmp
[root@localhost ~]#
就将RHEL中的整个/tmp文件夹复制到了CentOS的/root下。
rsh命令做命令传输
RHEL里不能免费用yum,所以在CentOS里配了DNS用yum安装了rsh命令。注意,yum install rsh
只是安装了rsh命令,可以去访问那些提供rsh服务的主机。如果要让本机提供rsh服务,要yum install rsh-server
。
现在这两个包都已经安装了:
[root@localhost ~]# rpm -aq |grep rsh
rsh-0.17-64.el6_9.1.x86_64
rsh-server-0.17-64.el6_9.1.x86_64
[root@localhost ~]#
在setup工具里就可以看到rsh服务了,为其打上*号即可:
[root@localhost ~]# echo rsh >>/etc/securetty
[root@localhost ~]# echo "192.168.1.123 root" >>.rhosts
[root@localhost ~]# echo rlogin >>/etc/securetty
[root@localhost ~]# echo rexec >>/etc/securetty
[root@localhost ~]# service xinetd start
正在启动 xinetd: [确定]
[root@localhost ~]# netstat -an | grep 514
tcp 0 0 :::514 :::* LISTEN
unix 3 [ ] STREAM CONNECTED 15145 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 15144
[root@localhost ~]#
关闭SELinux:
[root@localhost ~]# vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
打开514端口(参考的那篇博文把命令打错了):
[root@localhost ~]# iptables -A INPUT -p tcp --dport 514 -j ACCEPT
这时错误变成了权限不足:
[root@localhost ~]# rsh -l root 192.168.1.123 ls /tmp
Permission denied.
但是用小贤的网就可以了。