By default, if you do not specify any network mode, KVM will silently choose NAT mode for us, in addition to NAT there is bridge and VLAN mode.
User Networking (NAT mode)
With this mode, no additional configuration is required for the host. Under normal circumstances, the virtual machine can access the host's physical network directly, and the host cannot access the virtual machine.
The benefit is simple, no configuration, and if the host can surf the Internet, the virtual machine can also surf the Internet.
The disadvantage is that the network between the virtual machine and the virtual machine is unreachable, the ICMP protocol does not work properly (that is, the ping function does not return a normal value), and NAT uses a forwarding mechanism, so the efficiency is low.
# Host: ip address [[email protected] qemuimages]$ ifconfig p3p1p3p1: flags=4163 <UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.102 netmask 255.255.255.0 broadcast 0.0.0.0 inet6 fe80::ba88:e3ff:fef3:af7c prefixlen 64 scopeid 0x20<link> ether b8:88:e3: f3:af:7c txqueuelen 1000 (Ethernet) rx packets 232953 bytes 210207598 (200.4&NBSP;MIB) RX errors 0 dropped 0 overruns 0 frame 0 tx packets 282248 bytes 40669709 (38.7&NBSP;MIB) &Nbsp; tx errors 0 dropped 0 overruns 0 carrier 0 collisions 0# host: can access the internet normally [[email protected ] qemuimages]$ ping ping www.a.shifen.com (119.75.217.56) 56 (+) bytes of data.64 bytes from 119.75.217.56: icmp_seq=1 ttl=56 time=33.8 ms64 bytes from 119.75.217.56: icmp_seq=2 ttl=56 time=31.8 ms # Host: boot virtual machine [[email protected] qemuimages]$ sudo qemu-kvm -m 2048 -hda networknode.img
Virtual machines:
Ping www.baidu.com Conclusion: Ping does not pass the Internet
Ping Host (192.168.1.102) Conclusion: Ping not detox host and internet
wget http://www.baidu.com Conclusion: The page can be downloaded normally
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/54/2E/wKioL1R7OkfQmBOpAAWLvPCsCv0257.jpg "title=" x4.png "alt=" Wkiol1r7okfqmbopaawlvpcscv0257.jpg "/>
Finally, some advanced features enable host access to virtual machines.
# host: The HOSTFWD parameter is provided when the virtual machine is started # This parameter allows the host to connect to the VM's 22 port via port 60000 without any change in other aspects. [[email protected] qemuimages]$ sudo qemu-kvm -m 2048 -hda networknode.img -net nic -net user,hostfwd=tcp:127.0.0.1:60000-:22# host: Connect to a virtual machine conclusion: can connect to the virtual machine normally [[Email protected] qemuimages]$ ssh [email protected] -p 60000The authenticity of host ' [localhost]:60000 ([ 127.0.0.1]:60000) ' can ' t be established. rsa key fingerprint is 42:73:36:58:f3:75:12:35:8a:07:8d:4d:32:1a:59:3a. are you sure you want to continue connecting (yes/no)? yesWarning : permanently added ' [localhost]:60000 ' (RSA) to the list of Known hosts. [email protected] ' s password: last login: sun nov 30 23:53:27 2014[[emaIl protected] ~]# ifconfig ens3: flags=4163<up,broadcast,running,multicast> mtu 1500 inet 10.0.2.15 netmask 255.255.255.0 broadcast 0.0.0.0 inet6 fe80::5054:ff:fe12:3456 prefixlen 64 scopeid 0x20<link> ether 52:54:00:12:34:56 txqueuelen 1000 (Ethernet) RX packets 66 bytes 8768 (8.5 kib) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 81 bytes 11168 (10.9 kib) tx errors&nBsp;0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10
This article is from the Software testing blog, so be sure to keep this source http://9614554.blog.51cto.com/9604554/1584880
KVM Nic Mode (nat/usernetworking)