1. Background
This article briefly records, inmac arm
use in architectureVmware Fusion
under the virtual machineCentos7
How to configurestatic ip
address. If usingdhcp
Dynamic allocation of static IP addresses, then the IP addresses may change, so you need to use static IP addresses.
Second, the realization of the function
- Internally the virtual machine uses a static ip address.
- 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
existmac
Execute the following command on the computer
➜ ~ cat /Library/Preferences/VMware\ Fusion/vmnet8/nat.conf | grep netmask
netmask = 255.255.255.0
You can see that the obtained subnet mask is255.255.255.0
3.2 Get the gateway
existmac
Execute the following command on the 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 is192.168.121.2
3.3 Configure Centos static ip
existInside the virtual machine
Execute the following command
vim /etc/sysconfig/network-scripts/ifcfg-ens160
ifcfg-ens160
How did this value come about?
Can be executed in a virtual machineip addr
command to get.
The specific configuration is as follows:
BOOTPROTO=static # configure static ip
IPADDR=192.168.121.136 # Configured ip address
NETMASK=255.255.255.0 # subnet mask
GATEWAY=192.168.121.2 # Gateway
DNS1=8.8.8.8 # Configure dns address
3.4 Restart the network
systemctl restart network
3.5 Check whether the ip is valid
[[email protected] ~]# 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
[[email protected] ~]#
inet 192.168.121.136/24 brd 192.168.121.255 scope global noprefixroute ens160
You can see that our ip address configuration takes effect.
3.6 Determine whether you can access the external network
[[email protected] ~]# 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
[[email protected] ~]#
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 possible to passssh
Connecting to a virtual machine is slow,check information
It is found that the solution can be solved by the following solutions.
Willvirtual machine
of/etc/ssh/sshd_config
medium toUseDNS
Change this value tono
That's it.