Hyper-v中CentOS-7的静态/动态网络配置及SSH连接小记
需求
- 本地win10 hyper-v中安装centos7,centos7可连接外网通过yum下载各种包
- centos7拥有静态ip,可以稳定的通过ssh工具(例如xshell)链接
思路
使用双网卡,一个负责外网,一个负责内网:
- 使用hyper-v自带默认虚拟交换机default switch的网卡自动外网连接
- 新建内部虚拟交换机与新建网卡相关联,配置静态ip,供SSH连接
步骤
- 新建类型为“内部”的虚拟交换机
![xshell怎样连接交换机_xshell无法连接22端口插图2 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/S6n2o4OD.png)
![xshell怎样连接交换机_xshell无法连接22端口插图3 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
![xshell怎样连接交换机_xshell无法连接22端口插图4 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/k7DYkh.png)
![xshell怎样连接交换机_xshell无法连接22端口插图5 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
![xshell怎样连接交换机_xshell无法连接22端口插图6 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/k7DYkh.png)
![xshell怎样连接交换机_xshell无法连接22端口插图7 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
2. 在“控制面板-网络连接”中设置此交换机地址,名字:ssh-connect
![xshell怎样连接交换机_xshell无法连接22端口插图8 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/22cYyv47.png)
![xshell怎样连接交换机_xshell无法连接22端口插图9 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
![xshell怎样连接交换机_xshell无法连接22端口插图10 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/22cYyv47.png)
![xshell怎样连接交换机_xshell无法连接22端口插图11 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
在进行这一步时,如果之前配置过hyper-v虚拟网卡,可能保存不上,提示:
![xshell怎样连接交换机_xshell无法连接22端口插图12 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/KA7fOEC6K.png)
![xshell怎样连接交换机_xshell无法连接22端口插图13 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
![xshell怎样连接交换机_xshell无法连接22端口插图14 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/KA7fOEC6K.png)
![xshell怎样连接交换机_xshell无法连接22端口插图15 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
参考这篇文章,删除对应注册表内的内容并重启即可:
networking – IP address assigned to non-existent adapter – Super User
简言之:
- 在注册表HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces中搜索报错提示的这个关联IP地址,找到这个节点的GUID:{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}并删除
- 删除HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Adapters\{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
- 删除HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces\{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
- 重启
3. 虚拟机关机前提下,为虚拟交换机新建网卡。(右键虚拟机-设置)
![xshell怎样连接交换机_xshell无法连接22端口插图16 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/o2tW21o9.png)
![xshell怎样连接交换机_xshell无法连接22端口插图17 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
![xshell怎样连接交换机_xshell无法连接22端口插图18 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/o2tW21o9.png)
![xshell怎样连接交换机_xshell无法连接22端口插图19 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
4. 第一块网卡关联default switch,第二块关联新建的虚拟交换机
![xshell怎样连接交换机_xshell无法连接22端口插图20 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/u2RGf.png)
![xshell怎样连接交换机_xshell无法连接22端口插图21 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
![xshell怎样连接交换机_xshell无法连接22端口插图22 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/u2RGf.png)
![xshell怎样连接交换机_xshell无法连接22端口插图23 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
5. 打开虚拟机,虚拟机内设置两块网卡的网络
配置eth0
在虚拟机中编辑/etc/sysconfig/network-scripts/ifcfg-eth0,把BOOTPROTO改为dhcp,ONBOOT改为yes:
![xshell怎样连接交换机_xshell无法连接22端口插图24 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/lk93K.png)
![xshell怎样连接交换机_xshell无法连接22端口插图25 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
![xshell怎样连接交换机_xshell无法连接22端口插图26 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/lk93K.png)
![xshell怎样连接交换机_xshell无法连接22端口插图27 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
配置eth1
拷贝ifcfg-eth0,并改名为ifcfg-eth1。修改BOOTPROTO为static,把NAME和DEVICE改为eth1,删除UUID(不能和eth0相同)。
加上IPADDR=192.168.218.2和NETMASK=255.255.255.0,IP必须与ssh-connect一个网段,不用设置GATEWAY
![xshell怎样连接交换机_xshell无法连接22端口插图28 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/8WtGN.png)
![xshell怎样连接交换机_xshell无法连接22端口插图29 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
![xshell怎样连接交换机_xshell无法连接22端口插图30 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/8WtGN.png)
![xshell怎样连接交换机_xshell无法连接22端口插图31 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
6. 重启网络或者reboot:service network restart,之后就可以ping通http://baidu.com和ssh-connetc地址使用xshell链接
![xshell怎样连接交换机_xshell无法连接22端口插图32 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/S59eg901o.png)
![xshell怎样连接交换机_xshell无法连接22端口插图33 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
![xshell怎样连接交换机_xshell无法连接22端口插图34 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/S59eg901o.png)
![xshell怎样连接交换机_xshell无法连接22端口插图35 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
![xshell怎样连接交换机_xshell无法连接22端口插图36 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/4DjD0.png)
![xshell怎样连接交换机_xshell无法连接22端口插图37 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
![xshell怎样连接交换机_xshell无法连接22端口插图38 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/4DjD0.png)
![xshell怎样连接交换机_xshell无法连接22端口插图39 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
另:
1. 如果xshell连接不上,需确保CentOS7安装了 openssh-server
yum list installed | grep openssh-server
![xshell怎样连接交换机_xshell无法连接22端口插图40 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/j6qS4fs.png)
![xshell怎样连接交换机_xshell无法连接22端口插图41 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
![xshell怎样连接交换机_xshell无法连接22端口插图42 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/j6qS4fs.png)
![xshell怎样连接交换机_xshell无法连接22端口插图43 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
2. 如果执行命令后无显示,则需安装openssh-server:
yum install openssh-server
3. 之后配置/etc/ssh/sshd_config
![xshell怎样连接交换机_xshell无法连接22端口插图44 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/6Dh2dg.png)
![xshell怎样连接交换机_xshell无法连接22端口插图45 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
![xshell怎样连接交换机_xshell无法连接22端口插图46 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/6Dh2dg.png)
![xshell怎样连接交换机_xshell无法连接22端口插图47 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
4. 开启ssh:
systemctl start sshd
5. ps -e | grep sshd 查看sshd服务是否启动
![xshell怎样连接交换机_xshell无法连接22端口插图48 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/tuk7zx1.png)
![xshell怎样连接交换机_xshell无法连接22端口插图49 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
![xshell怎样连接交换机_xshell无法连接22端口插图50 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/tuk7zx1.png)
![xshell怎样连接交换机_xshell无法连接22端口插图51 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
6. netstat -ntlp | grep :22 查看端口是否起开
![xshell怎样连接交换机_xshell无法连接22端口插图52 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/553k8M.png)
![xshell怎样连接交换机_xshell无法连接22端口插图53 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
![xshell怎样连接交换机_xshell无法连接22端口插图54 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/uploads/2024/04/553k8M.png)
![xshell怎样连接交换机_xshell无法连接22端口插图55 xshell怎样连接交换机_xshell无法连接22端口](https://sigusoft.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
至此,问题解决。
激活谷谷主为您准备了激活教程,为节约您的时间请移步至置顶文章:https://sigusoft.com/99576.html
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。 文章由激活谷谷主-小谷整理,转载请注明出处:https://sigusoft.com/12524.html