Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure CentOS7 network and ssh in virtual machine

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of how to configure CentOS7 network and ssh in the virtual machine, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to configure CentOS7 network and ssh in the virtual machine. Let's take a look.

1. Network configuration of centos7:

1. Modify the hostname:

Echo "hostname tshare365.localdomain" > > / etc/sysconfig/network

Then:

Reboot

It will take effect!

two。 View the mac address:

Ip addr

3. Modify the network configuration:

(1) find the required network configuration parameters:

Open the virtual machine network settings, the specific steps are as follows:

From the above steps, we get the following information:

Ip address: one between 192.168.222.128 and 192.168.222.254, for example, 192.168.222.129

Subnet mask: 255.255.255.0

Gateway: 192.168.222.2

Broadcast address: 192.168.222.254

Dns:8.8.8.8

(2) start modifying the network configuration file:

Cd / etc/sysconfig/network-scripts/ls

See if there's an ifcfg-eno16777736 or something like that.

If so:

Edit the file:

Vi ifcfg-eno16777736

Modify or add the following ():

Type=ethernet # type: profile interface type. There are a variety of network configuration files in the / etc/sysconfig/network-scripts/ directory, including ethernet, ipsec and other types, and the network interface type is ethernet. The device=eno16777736 # device name must be correct. The default device name for centos7 is eno16777736.hwaddr= # hwaddr/macaddr:mac address. Only one of them needs to be set, and the settings must not conflict with each other. Addr is available. This mac address can be found through the ip addr command. Bootproto=static # set the way for the network card to obtain the ip address, none: do not use the startup address protocol, bootp:bootp protocol, dhcp:dhcp dynamic address protocol, static: static address protocol ipaddr=192.168.222.129 # if you set the way for the network card to obtain the ip address, specify statically This field specifies the ip address netmask=255.255.255.0 # subnet mask gateway=192.168.222.2 # gateway broadcast=192.168.222.255 # subnet broadcast address onboot=yes # yes of the ipv4 corresponding to the network card, and peerdns=yes # peerdns: whether to specify dns when the network is enabled. If the dhcp protocol is used, the default is yes. Yes: if dns is set, modify the dns in / etc/resolv.conf. No: the dnsdns1=8.8.8.8 # dns {1,2}: dns address in / etc/resolv.conf is not modified. When peerdns is yes, it will be written to / etc/resolv.conf.

Set up the above items and you can basically access the network!

Here are a few additional options, as an increase in knowledge, I will not delete.

Nm_controlled= # nm_controlled: whether the network interface is controlled by network manager. The modification takes effect immediately after it is saved, and there is no need to restart it. After being cheated by it several times, it is recommended that it be generally set to no. Yes: controlled by network manager. No: not controlled by network manager userctl= # userctl: user rights control yes: non-root users are allowed to control the network interface. No: non-root users do not run to control the network interface ipv6init= # ipv6init: whether to execute ipv6. Yes: supports ipv6. No: ipv6 is not supported. Ipv6addr= # ipv6addr:ipv6 address / prefix length

(3) two commonly used commands:

Ifdown ifcfg-eno16777736 # (Network configuration for disabling ifcfg-eno16777736) ifup ifcfg-eno16777736 # (Network configuration for starting ifcfg-eno16777736)

(4) restart the network service:

Systemctl restart network.service

(5) check:

At this point, we can use the ping command:

Ping www.tshare365.com

4. Update centos7 to the latest version:

Yum-y update # upgrade all packages, change software settings and system settings, system version kernel upgrade yum-y upgrade # upgrade all packages, do not change software settings and system settings, system version upgrade, kernel does not change

Second, configure the ssh service and how to change the port!

1. Modify sshd_config:

Vi / etc/ssh/sshd_config

The modifications are as follows:

# port 22 / / remove the line # port 20000 / / add this line below

If necessary, you can:

Disable root login, add restrict user gino

Permitrootlogin noallowusers gino

two。 Modify selinux

Installation

Yum-y install policycoreutils-python

Use the following command to view the ssh ports allowed by the current selinux:

Semanage port-l | grep ssh

Add port 20000 to selinux

Semanage port-a-t ssh_port_t-p tcp 20000

(cancel the port by changing-a to-d. If you are not clear, you can use man.)

Then confirm whether to add it or not

Semanage port-l | grep ssh

If successful, it will output.

Ssh_port_t tcp 20000, 22

Prove that the setting is successful

3. Modify the firewall

Vi / etc/sysconfig/iptables

Increase

-an input-p tcp-m state-- state new-m tcp-- dport 20000-j accept

Then restart the firewall iptables and apply the rules:

Systemctl restart iptables.service

4. Set boot self-boot

Chkconfig sshd on # Boot

Restart ssh:

Systemctl restart sshd.service

At this point, the ssh port was modified successfully.

5. Use the ssh tool to connect.

Common ssh workers have, securecrt, xshell, etc., download by yourself, enter the user name and password!

This is the end of the article on "how to configure the CentOS7 network and ssh in the virtual machine". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to configure CentOS7 network and ssh in the virtual machine". If you want to learn more knowledge, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report