xshell如何连接交换机_xshell连接console的步骤

后端 (7) 2024-03-29 09:12

Hi,大家好,我是编程小6,很荣幸遇见你,我把这些年在开发过程中遇到的问题或想法写出来,今天说一说xshell如何连接交换机_xshell连接console的步骤,希望能够帮助你!!!。
Hyper-v中CentOS-7的静态/动态网络配置及SSH连接小记

需求

  1. 本地win10 hyper-v中安装centos7,centos7可连接外网通过yum下载各种包
  2. centos7拥有静态ip,可以稳定的通过ssh工具(例如xshell)链接

思路

使用双网卡,一个负责外网,一个负责内网:

  1. 使用hyper-v自带默认虚拟交换机default switch的网卡自动外网连接
  2. 新建内部虚拟交换机与新建网卡相关联,配置静态ip,供SSH连接

步骤

  1. 新建类型为“内部”的虚拟交换机

xshell如何连接交换机_xshell连接console的步骤_https://bianchenghao6.com/blog_后端_第2张

xshell如何连接交换机_xshell连接console的步骤_https://bianchenghao6.com/blog_后端_第4张

2. 在“控制面板-网络连接”中设置此交换机地址,名字:ssh-connect


xshell如何连接交换机_xshell连接console的步骤_https://bianchenghao6.com/blog_后端_第6张

在进行这一步时,如果之前配置过hyper-v虚拟网卡,可能保存不上,提示:


xshell如何连接交换机_xshell连接console的步骤_https://bianchenghao6.com/blog_后端_第8张

参考这篇文章,删除对应注册表内的内容并重启即可:

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连接console的步骤_https://bianchenghao6.com/blog_后端_第10张

4. 第一块网卡关联default switch,第二块关联新建的虚拟交换机


xshell如何连接交换机_xshell连接console的步骤_https://bianchenghao6.com/blog_后端_第12张

5. 打开虚拟机,虚拟机内设置两块网卡的网络

配置eth0

在虚拟机中编辑/etc/sysconfig/network-scripts/ifcfg-eth0,把BOOTPROTO改为dhcp,ONBOOT改为yes:


xshell如何连接交换机_xshell连接console的步骤_https://bianchenghao6.com/blog_后端_第14张

配置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连接console的步骤_https://bianchenghao6.com/blog_后端_第16张

6. 重启网络或者reboot:service network restart,之后就可以ping通baidu.com和ssh-connetc地址使用xshell链接


xshell如何连接交换机_xshell连接console的步骤_https://bianchenghao6.com/blog_后端_第18张

xshell如何连接交换机_xshell连接console的步骤_https://bianchenghao6.com/blog_后端_第20张

另:

1. 如果xshell连接不上,需确保CentOS7安装了 openssh-server

yum list installed | grep openssh-server

xshell如何连接交换机_xshell连接console的步骤_https://bianchenghao6.com/blog_后端_第22张

2. 如果执行命令后无显示,则需安装openssh-server:

yum install openssh-server  

3. 之后配置/etc/ssh/sshd_config


xshell如何连接交换机_xshell连接console的步骤_https://bianchenghao6.com/blog_后端_第24张

4. 开启ssh:

systemctl  start sshd 

5. ps -e | grep sshd 查看sshd服务是否启动


xshell如何连接交换机_xshell连接console的步骤_https://bianchenghao6.com/blog_后端_第26张

6. netstat -ntlp | grep :22 查看端口是否起开


xshell如何连接交换机_xshell连接console的步骤_https://bianchenghao6.com/blog_后端_第28张

至此,问题解决。

今天的分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。