欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

VMware Workstation下centOS互联

程序员文章站 2022-07-13 10:17:10
...

目标

  1. 修改配置文件,使之可以与主机及外网互联
  2. 启用sshd服务,使用SecureCRT连接centOS

VMware Workstation网络配置

点击菜单 Edit > Preferences,点击NAT Settings
VMware Workstation下centOS互联
配置网关IP,一般默认即可,也可以自己修改
VMware Workstation下centOS互联

注:下面的CentOS中会用这里配置的网关、子网掩码

查看本机的DNS IP
VMware Workstation下centOS互联

注:下面的CentOS中会用这里DNS IP

CentOS网络配置

[aaa@qq.com /]# cd /etc/sysconfig/network-scripts/ #切换至network-scripts目录下
[aaa@qq.com network-scripts]# vi ifcfg-ens33 #编辑ifcfg打头的文件

修改

BOOTPROTO=static #动态为dhcp
ONBOOT=yes #原先为no

添加

IPADDR=192.168.123.130 #设置IP地址
GATEWAY=192.168.123.2 #设置网关
NETMASK=255.255.255.0 #设置子网掩码
DNS1=192.168.0.1 #设置DNS
DNS2=8.8.8.8 #google提供的免费DNS服务器的IP地址
DNS3=8.8.4.4 #google提供的另一个免费DNS服务器的IP地址
[aaa@qq.com network-scripts]# service network restart #重启网络服务
[aaa@qq.com network-scripts]# ping www.baidu.com #ping外网
PING www.a.shifen.com (119.75.213.61) 56(84) bytes of data.
64 bytes from 119.75.213.61 (119.75.213.61): icmp_seq=1 ttl=128 time=30.3 ms
64 bytes from 119.75.213.61 (119.75.213.61): icmp_seq=2 ttl=128 time=30.8 ms
64 bytes from 119.75.213.61 (119.75.213.61): icmp_seq=3 ttl=128 time=31.3 ms
[aaa@qq.com network-scripts]# yum install net-tools #安装网络工具,如果不安装无法使用ifconfig等工具
[aaa@qq.com network-scripts]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.123.131  netmask 255.255.255.0  broadcast 192.168.123.255
        inet6 fe80::97b8:f5ed:5cf4:6b9d  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:83:9b:ed  txqueuelen 1000  (Ethernet)
        RX packets 2203  bytes 269053 (262.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1678  bytes 412661 (402.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[aaa@qq.com network-scripts]#  yum list installed | grep openssh-server #如果运行如下,则说明已经安装了ssh服务
openssh-server.x86_64                 7.4p1-16.el7                     @anaconda

[aaa@qq.com network-scripts]# yum install openssh-server #如果没有,则运行此命令安装
[aaa@qq.com network-scripts]# cd /etc/ssh/
[aaa@qq.com ssh]# ls
moduli  ssh_config  sshd_config  ssh_host_ecdsa_key  ssh_host_ecdsa_key.pub  ssh_host_ed25519_key  ssh_host_ed25519_key.pub  ssh_host_rsa_key  ssh_host_rsa_key.pub
[aaa@qq.com ssh]# vi sshd_config #编辑ssh配置,去掉如下属性的注释
Port 22
ListenAddress 0.0.0.0
ListenAddress ::
PermitRootLogin yes
PasswordAuthentication yes

[aaa@qq.com ssh]# sudo service sshd start #启动sshd服务
[aaa@qq.com ssh]# ps -ef | grep sshd #检查sshd服务是否已经开启
[aaa@qq.com ssh]# netstat -an | grep 22 #检查22号端口是否开启监听

一切正常后,便可以通过远程工具SecureCRT连接centOS。

如何在VMware Workstation下安装centOS可以参照 VMware Workstation 14安装Centos 7