1.配置桥接
1.给虚拟机添加一个网卡,配置
//创建一个桥接设备和会话,并配置IP地址及网关
[root@localhost ~]# nmcli c add type bridge con-name br1 ifname br1 ipv4.addresses 192.168.75.111/24 ipv4.gateway 192.168.75.2 ipv4.method manual
Connection 'br1' (9d043ecc-4565-4d40-876d-b8d0c4594ac2) successfully added.
//将ens224网卡,连接在网桥上
//数据包流向 -> 网桥 -> ens224
[root@localhost ~]# nmcli c add type bridge-slave con-name br1-port1 ifname ens224 master br1
Connection 'br1-port1' (a7594b29-dff1-4659-9762-23494dc637dd) successfully added.
//启动桥接会话
[root@localhost ~]# nmcli connection up br1
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9)
//启动从设备会话
[root@localhost ~]# nmcli connection up br1-port1
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/14)
2.查看
3.测试:用windows来ping虚拟机的桥接会话
?2.ssh:拒绝用户远程登录
[root@localhost ~]# vim /etc/ssh/sshd_config
[root@localhost ~]# systemctl restart sshd
?
3.ssh免密登录
1. 开启两个虚拟机,两个虚拟机都输出下面的命令,获得公钥
[root@localhost ~]# ssh-keygen -t rsa
2. 两个虚拟机都进入.ssh/,用下面的命令登录对方的虚拟机,第一次需要输入密码
[root@localhost ~]# cd .ssh/
[root@localhost .ssh]# ssh -p 22 root@192.168.75.130
?
3. 将公钥写入authorized_keys => 将公钥传递给远端的服务器
ssh-copy-id 用户名 => 将id_rsa.pub的内容写入authorized_keys文件中
等价于== cat id_rsa.pub >> authorized_keys中
[root@localhost .ssh]# ssh-copy-id localhost
4.将authorized_keys拷贝到远端: /root/.ssh/
[root@localhost .ssh]# scp authorized_keys 192.168.75.130:~/,ssh/
?测试结果:
?
|