Background
In a formal production environment, it is usually necessary to use terminal software such as Xshell to manage the production server remotely through a fixed IP address, so the production server needs to be assigned a static IP address to facilitate remote connection of the local computer.
Objective
The purpose of this article is to mimic the production environment, set up a static IP address for the server, and connect using Xshell.
is divided into two steps:
1. Set the static IP address;
2. Use Xshell for remote connection;
Preparatory work:
Virtual Box;
CentOS 7.3.1611;
Vi/vim;
Xshell;
Begin:
This article mainly discusses static IP settings, Virtual box installation of CentOS 7 process is not to do this demonstration, if necessary, Baidu for your own reference.
1. Set the static IP address
Preferred access to Network manager profile when/etc/sysconfig/network-scripts/
Using Vi/vim to open the Ifcfg-enp0s3 file, it is possible that the file name under your directory will be ifcfg-xxxxx;
Modify the value of the Bootproto configuration item from "DHCP" to "Static";
The value of the Onboot configuration item is modified to "yes"
and add four item configuration values
Ipaddr= "192.168.3.105" #要分配给机器的静态IP地址 because it is in the virtual machine, so I set it to the same network segment as my machine
Gateway= "192.168.3.1" #网关 set to be the same as your own machine.
netmask= "255.255.255.0" #子网掩码
Nm_controlled= "No" #这个配置项值为no, which means the configuration file is not controlled by the network controller interface
After the addition is complete, the content is as follows:
After editing is completed, make: Wq save and exit;
Use CD: Return to upper directory, edit Network file, add Dns:vim Network
Add two item configuration values:
dns1=192.168.1.1
dns2=8.8.8.8
When finished,: Wq save exit
The next step is to restart the network service, make the changes effective, and use sudo systemctl restart Network.service to restart the network service
There is no prompt to restart the success, and then make the command IP addr see if the changes take effect
To prove that our modifications are in effect and that the static IP address is set to complete.
2. Connect using the Xshell
To connect to a server remotely using Xshell, you need to open the server's 22 port and use the following command:
sudo firewall-cmd--zone=public--add-port=22/tcp--permanent #开放22端口
sudo systemctl restart Firewalld.service #重启防火墙服务
After the port setting is complete, you need to set the virtual box network mode
Select Set-Up network, select Bridge Network card, and then restart the virtual machine.
Wait for reboot complete, open Xshell, ready to connect
Click "New", reset name, host, press "OK"
Setup is complete, and the next step is to connect by entering the user name and password as soon as the connection is made.
Well, then we can happily in the Xshell command operation server.
CentOS 7 Set static IP, use Xshell remote connection