How to create a KVM virtual machine connected to the external network communication? (Network communication with the external host can premise)

This article explains how to create a KVM virtual machine connected to the external network communication? Of course, the host needs to be able to network communication with the outer

1. Configure the card file. (My card file is ifcfg-eth0, other small partners need to be modified depending on the desired oh ~)

[root@da ~]#vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"  
ONBOOT=yes
IPV6INIT=no
BOOTPROTO=static        #我这里设置了静态分配ip
IPADDR=192.168.1.2      #虚拟主机的ip地址,在这里可以修改
NETMASK=255.255.255.0   #虚拟主机的子网掩码,也可以改
GETAWAY=192.168.1.254   #虚拟主机所对应的网关,可以改
TYPE=Ethernet

2. Restart network services

# As error check to see if an error has occurred above documents, such as a symbol errors! !

[root@da ~]# systemctl restart network

3. Set the default route to the host ip (the most important step, generally do not do this step emerging issues)

[root@da ~]# ip route add default via 192.168.1.254 dev eth0

#我这里的192.168.1.254是虚拟机和主机通信的同一个网段,这个网段中,\
#主机ip是192.168.1.254,虚拟机是192.168.1.1

4. Verify

[root@da ~]# ifconfig

[root@da ~]# ip route

[root@da ~]# ping 8.8.8.8  #能够ping通代表成功!

Well, this article has to end here!

Released six original articles · won praise 0 · Views 76

Guess you like

Origin blog.csdn.net/a84050933/article/details/104998548