Record the process of connecting to the local Linux virtual machine via SSH

Record the process of connecting to the local Linux virtual machine via SSH

Experimental environment:
Physical machine Windows 10 x64

Physical NIC information
IPv4 address: 192.168.123.205
Subnet mask: 255.255.255.0
Default Gateway: 192.168.123.1

Virtual Machine VMware Workstation14 Cent OS 6.7 x64

VMnet8 Information:
IPv4 address: 192.168.21.0
Subnet mask: 255.255.255.0
Default Gateway: 192.168.21.2

1. Modify VMware's network settings

Location: Toolbar -> Edit -> Virtual Network Editor [Administrator]

NAT Settings->Change Gateway IP(G): Change 192.168.21.2 to 192.168.123.2

Subnet IP (I): Change 192.168.21.0 to 192.168.123.0

Subnet mask (M): default 255.255.255.0

2. Enter Linux to modify network configuration

Enter ip addr to view the network card information

[root@localhost Desktop]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host 
 valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:3b:64:33 brd ff:ff:ff:ff:ff:ff
inet 192.168.31.31/24 brd 192.168.31.255 scope global eth0
inet6 fe80::20c:29ff:fe3b:6433/64 scope link 
 valid_lft forever preferred_lft forever
3: pan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN 
link/ether 1a:76:3b:91:89:e6 brd ff:ff:ff:ff:ff:ff

<BROADCAST,MULTICAST,UP,LOWER_UP> The network card number eth0 before the mtu section is the NAT network card set up previously

Adjust the network card script and enter the command vi /etc/sysconfig/network-scripts/ifcfg-對應網卡編號
Here we take eth0 as an example, enter vi /etc/sysconfig/network-scripts/ifcfg-eth0 , and output the vi editing mode:

DEVICE="eth0"
BOOTPROTO="dhcp"
HWADDR="00:0C:29:3B:64:33"
IPV6INIT="yes"
NM_CONTROLLED="yes"
ONBOOT="no"
TYPE="Ethernet"
UUID="d2818ab1-7ee1-44bf-b8b9-5bbecc6880f0"

Static IP mode: BOOTPROTO="static"

Auto-start: ONBOOT="yes"

Static IP information: IPADDR=192.168.123.123 //Select a non-conflicting IP in the network segment 192.168.123.x of the physical network card

Subnet mask: NETMASK=255.255.255.0

Subnet gateway GATEWAY=192.168.163.2

Save after modification as follows

DEVICE="eth0"
BOOTPROTO="static"
HWADDR="00:0C:29:3B:64:33"
IPV6INIT="yes"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="d2818ab1-7ee1-44bf-b8b9-5bbecc6880f0"
IPADDR=192.168.123.123
NETMASK=255.255.255.0
GATEWAY=192.168.123.2

3. Restart the network card and check the status of the NAT network card in the Window network adapter

Restart command: service network restart restart

The previous automatic acquisition mode setting of VMnet8 properties has been (automatically) changed to the following state

Note: Check whether the IP address is in the same network segment as the physical network card, and do not confuse this IP with the previous 192.168.123.123. The default xxx1 is fine. The default subnet mask is 255.255.255.0. If there is no default gateway, you can add it manually: 192.168.123.2

4. Make an SSH connection and fix the problem of being unable to access the external network

Local execution: ssh [email protected] prompts for password and successfully enters the system

Test whether the external network is available after changing the static IP

[root@localhost ~]# ping baidu.com
ping: unknown host baidu.com

Modify the DNS configuration information sudo vim /etc/resolv.conf and add the virtual network card gateway address to the end of the DNS configuration:

search localdomain
nameserver 192.168.123.2

After saving, wait a moment and ping again

[root@localhost ~]# ping baidu.com
PING baidu.com.localdomain (220.181.38.148) 56(84) bytes of data.
64 bytes from 220.181.38.148: icmp_seq=1 ttl=128 time=45.5 ms
64 bytes from 220.181.38.148: icmp_seq=2 ttl=128 time=44.9 ms
64 bytes from 220.181.38.148: icmp_seq=3 ttl=128 time=45.4 ms
64 bytes from 220.181.38.148: icmp_seq=4 ttl=128 time=45.1 ms
64 bytes from 220.181.38.148: icmp_seq=5 ttl=128 time=45.2 ms
64 bytes from 220.181.38.148: icmp_seq=6 ttl=128 time=45.0 ms

If the network card is restarted or the system allows DHCP to automatically obtain DNS, the previously modified DNS configuration will become invalid. Therefore, you need to add NM_CONTROLLED="no" [Whether to allow Network Manager management, set to no] in the network card configuration vi /etc/sysconfig/network-scripts/ifcfg-eth0 Restart the network card and configure and modify the DNS configuration again. sudo vim /etc/resolv.conf add nameserver 192.168.123.2

After the modification is completed, restart the network card service network restart , and the DNS configuration is still valid

References:

*Detailed explanation of the solution to resolv.conf being reset after CentOS restart

*Use xshell to connect to Linux in VMware

Xshell 5 connects to the Linux system in the local virtual machine

Solution to the problem that the VMware virtual machine cannot ping the external network after changing the static IP and eth0 is missing*

*CentOS7 sets static IP and Windows can not ping the virtual machine, the virtual machine can not ping the external network solution

Note: After the setting is successful, the NAT network card network segment and the physical network card network segment are inconsistent after the physical machine changes the IP, which will not affect the use

This is the end of this article about the process of connecting to a local Linux virtual machine via SSH. For more relevant content about connecting to a local Linux via SSH, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Tutorial on configuring SSH and Xshell to connect to the server in Linux (with pictures)
  • How to solve the problem of Linux ssh remote connection disconnection
  • Paramiko module under Python implements ssh connection to log in to Linux server

<<:  NodeJS realizes image text segmentation

>>:  MySQL 8.0.20 installation and configuration detailed tutorial

Recommend

A brief analysis of the count tracking of a request in nginx

First, let me explain the application method. The...

A summary of some of the places where I spent time on TypeScript

Record some of the places where you spent time on...

An example of how to implement an adaptive square using CSS

The traditional method is to write a square in a ...

Detailed analysis of MySQL 8.0 memory consumption

Table of contents 1. innodb_buffer_pool_size 2. i...

Discuss the development trend of Baidu Encyclopedia UI

<br />The official version of Baidu Encyclop...

Setting up a proxy server using nginx

Nginx can use its reverse proxy function to imple...

jQuery combined with CSS to achieve the return to top function

CSS Operations CSS $("").css(name|pro|[...

A brief discussion on the three major issues of JS: asynchrony and single thread

Table of contents Single thread asynchronous Sing...

Details of MutationObServer monitoring DOM elements in JavaScript

1. Basic Use It can be instantiated through the M...

How to safely shut down a MySQL instance

This article analyzes the process of shutting dow...

SQL implementation of LeetCode (177. Nth highest salary)

[LeetCode] 177.Nth Highest Salary Write a SQL que...

Vue2 implements provide inject to deliver responsiveness

1. Conventional writing in vue2 // The parent com...

Determine the direction of mouse entry based on CSS

In a front-end technology group before, a group m...

How to use bar charts in Vue and modify the configuration yourself

1. Import echart in HTML file <!-- Import echa...