Connect to Virtual Machine and Network Setting
Sungwa Yu

Lookup Host IP Address

Command: ipconfig getifaddr en0

Or ifconfig and find it after “en0:”

Mine is: 10.0.0.3.

Problems

  • After installed the system image

  • OS: Mac

  • VM OS: CentOS7

  • Software: VMware Fusion

Virtual machine cannot connect to internet and host.

ping www.google.com and ping 10.0.0.3 not working.

Procedure

  1. On the top, chooseVirtual Machine>Network Adapter>Network Adapter Settings...
  2. Choose Bridged Networking>Wi-Fi
  3. Go to VM’s terminal, enter dhclient, enter, then type ifconfig, remember the ip address under “ens33”: “inet”. For example, 10.0.0.195.
  4. In VM’s terminal, enter vim /etc/sysconfig/network-scripts/ifcfg-ens33, change the file to
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=824ec4bd-a9ae-4410-8346-17ce7f3dd111
DEVICE=ens33
ONBOOT=yes
IPADDR=10.0.0.195
NETMASK=255.255.255.0
GATEWAY=192.168.31.1
DNS1=119.29.29.29

Note: Pay attention to BOOTPROTO=static, ONBOOT=yes, and the last 4 lines. The IPADDR is what we got in step 3.

  1. In VM’s terminal, systemctl restart network.service

Now, ping www.google.com and ping 10.0.0.3 should work.

  1. In host’s terminal, ping 10.0.0.195 should work as well.
  2. May need to restart the VM to update the ip address shown in the VMWare.

SSH to VM on Mac

In host terminal, enter ssh user@ip-addr (usually “user” is “root”). For me, it is ssh root@10.0.0.195. Next, it will ask you to enter the root password. Then enter “yes” if it is the first time.

Enable Root Login

  1. sudo vim /etc/ssh/sshd_config
  2. Uncomment #PermitRootLogin no and change it to PermitRootLogin yes
  3. sudo systemctl restart sshd.service
  4. If doesn’t work, change root password using sudo passwd root

File Transfer

Use SFTP connection type.

Reference

https://mp.weixin.qq.com/s/WeZLtfrMdnISpX3v5WpJfA