1

1. Background

This article briefly records how to configure it under the mac arm architecture Vmware Fusion virtual machine Centos7 under the 静态ip address. If you use the dynamic allocation of dhcp static ip address, the ip address may change, so you need to use a static ip address.

Second, the realization of the function

  1. Internally the virtual machine uses a static ip address.
  2. The virtual machine can access the external network.

3. Implementation steps

1. Set the network of the virtual machine to nat

2. Modify the network adapter network of the virtual machine

3. Configure static ip

To configure static ip, we know that we generally need to configure the following three parameters.
ip address: IPADDR , subnet mask: NETMASK and gateway: GATEWAY

3.1 Get the subnet mask

Execute the following command on the mac computer

 ➜  ~ cat /Library/Preferences/VMware\ Fusion/vmnet8/nat.conf | grep netmask
netmask = 255.255.255.0

You can see that the obtained subnet mask is 255.255.255.0

3.2 Get the gateway

Execute the following command on the mac computer

 ➜  ~ cat /Library/Preferences/VMware\ Fusion/vmnet8/nat.conf | grep "ip ="  -B 1
# NAT gateway address
ip = 192.168.121.2

You can see that the obtained gateway is 192.168.121.2

3.3 Configure Centos static ip

In 虚拟机内 execute the following command

 vim /etc/sysconfig/network-scripts/ifcfg-ens160

ifcfg-ens160 How did this value come from?
You can execute the ip addr command in the virtual machine to obtain it.

The specific configuration is as follows:

 BOOTPROTO=static # 配置静态ip
IPADDR=192.168.121.136 # 配置的ip地址
NETMASK=255.255.255.0 # 子网掩码
GATEWAY=192.168.121.2 # 网关
DNS1=8.8.8.8 # 配置dns地址

3.4 Restart the network

 systemctl restart network

3.5 Check whether the ip is valid

 [root@appbasic ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether ee:fc:d8:1c:7d:5d brd ff:ff:ff:ff:ff:ff
    inet 192.168.121.136/24 brd 192.168.121.255 scope global noprefixroute ens160
       valid_lft forever preferred_lft forever
    inet6 fe80::ecfc:d8ff:fe1c:7d5d/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
[root@appbasic ~]#

inet 192.168.121.136/24 brd 192.168.121.255 scope global noprefixroute ens160 You can see that our ip address configuration has taken effect.

3.6 Determine whether you can access the external network

 [root@appbasic ~]# ping www.baidu.com
PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data.
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=1 ttl=128 time=34.4 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=3 ttl=128 time=30.7 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=4 ttl=128 time=30.2 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=5 ttl=128 time=39.7 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=6 ttl=128 time=36.6 ms
^C
--- www.a.shifen.com ping statistics ---
6 packets transmitted, 5 received, 16% packet loss, time 5080ms
rtt min/avg/max/mdev = 30.244/34.363/39.793/3.600 ms
[root@appbasic ~]#

You can see that you can access the external network normally.

4. Slow access to ssh

After configuring a static ip address, it may be slow to connect to the virtual machine through ssh , 查阅资料 found that it can be solved by the following solutions.

Change the value of --- 虚拟机 from /etc/ssh/sshd_config to UseDNS and change it to no .


huan1993
218 声望34 粉丝

java工程师