centos7 text mode to set a static ip address, use xshell to link centOS 7 to set a static IP, use Xshell to connect remotely

centOS 7 set static IP, use Xshell to connect remotely

 

background

In a formal production environment, it is usually necessary to use terminal software such as Xshell to remotely connect to the production server for management through a fixed IP address. Therefore, it is necessary to assign a static IP address to the production server to facilitate the remote connection of the local computer.

Purpose

The purpose of this article is to simulate a production environment, set a static IP address for the server, and use Xshell to connect.

Divided into two steps:

1. Set a static IP address;

2. Use Xshell for remote connection;

Ready to work:

Virtual Box;

centOS 7.3.1611;

saw/came;

Xshell;

Start:

This article mainly discusses static IP settings. The process of installing CentOS 7 in Virtual Box will not be demonstrated here. If necessary, you can refer to Baidu by yourself.

1. Set a static IP address

The preferred way to enter the network manager configuration file directory is /etc/sysconfig/network-scripts/

Use vi/vim to open the ifcfg-enp0s3 file, maybe the file name in your directory will be ifcfg-xxxxx;

Change the value of the BOOTPROTO configuration item from "dhcp" to "static";

Change the value of the ONBOOT configuration item to "yes"

and add four configuration values 

IPADDR="192.168.3.105" #The static IP address to be assigned to the machine is in a virtual machine, so I set it to the same network segment as my machine
GATEWAY="192.168.3.1" #The gateway is set to be the same as my own machine. OK
NETMASK="255.255.255.0" #Subnet mask
NM_CONTROLLED="no" #The value of this configuration item is no, which means that it is not controlled by the network controller interface, but the configuration file is used

After the addition is complete, the content is as follows:

After editing, make :wq save and exit;

Use cd .. to return to the upper directory, edit the network file, and add DNS:vim network

Add two configuration values:

DNS1=192.168.1.1
DNS2=8.8.8.8

When finished, :wq save and exit

Next, you need to restart the network service to make the changes take effect, use sudo systemctl restart network.service to restart the network service

If there is no prompt, the restart is successful, and then use the command ip addr to check whether the modification takes effect.

As shown in the figure, it proves that our modification has taken effect, and the static IP address setting is completed.

 

2. Use Xshell to connect

To use Xshell to connect to the server remotely, you need to open port 22 of the server, use the following command:

sudo firewall-cmd --zone=public --add-port=22/tcp --permanent #Open port 22

sudo systemctl restart firewalld.service #Restart firewall service

After the port setting is completed, you need to set the network mode of the virtual box

Select Settings --> Network as shown, select "Bridged NIC", and restart the virtual machine.

Wait for the restart to complete, open Xshell, and prepare to connect

Click "New", set the name, host, and press "OK"

The setting is complete, then just enter the user name and password when connecting to connect.

Well, then we can happily run commands in Xshell to operate the server.

background

In a formal production environment, it is usually necessary to use terminal software such as Xshell to remotely connect to the production server for management through a fixed IP address. Therefore, it is necessary to assign a static IP address to the production server to facilitate the remote connection of the local computer.

Purpose

The purpose of this article is to simulate a production environment, set a static IP address for the server, and use Xshell to connect.

Divided into two steps:

1. Set a static IP address;

2. Use Xshell for remote connection;

Ready to work:

Virtual Box;

centOS 7.3.1611;

saw/came;

Xshell;

Start:

This article mainly discusses static IP settings. The process of installing CentOS 7 in Virtual Box will not be demonstrated here. If necessary, you can refer to Baidu by yourself.

1. Set a static IP address

The preferred way to enter the network manager configuration file directory is /etc/sysconfig/network-scripts/

Use vi/vim to open the ifcfg-enp0s3 file, maybe the file name in your directory will be ifcfg-xxxxx;

Change the value of the BOOTPROTO configuration item from "dhcp" to "static";

Change the value of the ONBOOT configuration item to "yes"

and add four configuration values 

IPADDR="192.168.3.105" #The static IP address to be assigned to the machine is in a virtual machine, so I set it to the same network segment as my machine
GATEWAY="192.168.3.1" #The gateway is set to be the same as my own machine. OK
NETMASK="255.255.255.0" #Subnet mask
NM_CONTROLLED="no" #The value of this configuration item is no, which means that it is not controlled by the network controller interface, but the configuration file is used

After the addition is complete, the content is as follows:

After editing, make :wq save and exit;

Use cd .. to return to the upper directory, edit the network file, and add DNS:vim network

Add two configuration values:

DNS1=192.168.1.1
DNS2=8.8.8.8

When finished, :wq save and exit

Next, you need to restart the network service to make the changes take effect, use sudo systemctl restart network.service to restart the network service

If there is no prompt, the restart is successful, and then use the command ip addr to check whether the modification takes effect.

As shown in the figure, it proves that our modification has taken effect, and the static IP address setting is completed.

 

2. Use Xshell to connect

To use Xshell to connect to the server remotely, you need to open port 22 of the server, use the following command:

sudo firewall-cmd --zone=public --add-port=22/tcp --permanent #Open port 22

sudo systemctl restart firewalld.service #Restart firewall service

After the port setting is completed, you need to set the network mode of the virtual box

Select Settings --> Network as shown, select "Bridged NIC", and restart the virtual machine.

Wait for the restart to complete, open Xshell, and prepare to connect

Click "New", set the name, host, and press "OK"

The setting is complete, then just enter the user name and password when connecting to connect.

Well, then we can happily run commands in Xshell to operate the server.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325164465&siteId=291194637