I have seen many people post posts asking me how to play with virtual machines. In fact, I do not recommend using virtual machines. It is best to directly install the real environment. However, I am still sending an article about virtual machine network configuration, after reading the package, you will play.
Several network configurations in VMware
(1) bridged Mode
In this way, the IP address of the virtual system can be set to the same network segment as the local system. The virtual system is equivalent to an independent machine in the network and is inserted in a hub together with the local machine, other machines in the network can access the virtual system, and the virtual system can also access other machines in the network. Of course, two-way access to the local system is not a problem.
(2) Nat
This method can also achieve two-way access between the local system and the virtual system. However, other machines in the network cannot access the virtual system. The virtual system can use the NAT protocol to access other machines in the network.
Nat IP Address Configuration method: the virtual system uses DHCP to automatically obtain the IP address. VMWare services in the local system will assign an IP address to the virtual system. If you want to use a fixed IP Address at each start, set this IP address directly in the virtual system.
(3) Host-only mode
As the name suggests, this method only supports Network Communication between virtual machines and hosts. Other machines in the network cannot access the virtual system or other machines.
(4) not use method
The Virtual System is a single machine.
In general, the bridged method is the most convenient and easy to use. However, if the local system is Win2000 and the network cable is not plugged in (or there is no nic at all), the Network is likely to be unavailable (most of the machines with PCI Nic ), in this case, you can only use the NAT mode or host-only. The two virtual NICs mentioned previously are prepared to adapt to the two network types.
Network settings of vmwarevm
Virtual Machine network settings (Principles)
Before the official start, I think it is necessary to learn some necessary network knowledge first. If you do not understand any principle, you can only get a blank eye when you change the actual situation. Due to space limitations, we will only talk about some simple network knowledge related to VMware settings.
1. What is network?
Internet refers to "Internet connection", which seems redundant. However, many people have incorrect understandings about it. "Internet connection" refers to network interconnection, instead of messing up a computer as some people imagine. When we need to use computers to communicate with distant computers, we should first make up a network of local computers. Of course, remote computers also need to form a network, connect the two networks to form an "Internet connection ". When you use a telephone line or modem to dial up the Internet, connect your computer to the network of the ISP (Internet Service Provider) through the telephone line, it then communicates with computers around the world through the ISP network.
2. How does a computer transmit data over the network?
Each network needs a network address, and the computer in the network needs a unique identifier in the network. The network ID and the computer ID constitute an IP address, therefore, IP addresses are composed of network numbers and host numbers. When your computer needs to communicate with other computers, the computer will first determine whether the target host is in the local network or in the remote network based on the IP address and subnet mask, if an IP packet containing information is directly sent to the local network in the local network, the target host will detect and receive the packet, if the target host is in a remote network, it needs to be forwarded to the remote network through a computer called the gateway. The Gateway (geteway) can be seen as a bridge connecting the network and the network. The Gateway has a wide range of concepts, for the sake of simplicity, we now consider it to be the same concept as a router. A router is a special computer that connects networks and selects the path for IP packet transmission. In many cases, the gateway concept is equivalent to a router.
3. What are the requirements for IP addresses of computers on the network?
In the same network, each computer must have the same network number, so that the computer considers that the target host is in the current network and can be delivered correctly. If the network number is different, even if the target host has been connected to the network with a network cable, the data cannot be delivered directly. Even if the two computers are close at hand, they still seem to be a remote computer. for example, if the network number of a network is 192.168.0, the IP address of the computer in the network must start with 192.168.0. If you want to transmit a data packet to a network with the network number 192.168.1, it must be forwarded through the router. If there is no router in the network, the transmission fails. Therefore, to connect two networks, a router interface must have at least two network interfaces (network interfaces for network devices such as network adapters and modem ). For the relationship between the network and the vro, see:
-------------------------------------------
| Network A | router | Network B |
|
| □-- | ----------- | -- □□-- | ---------- | -- □|
| 1 | 2 3 | 4 |
-------------------------------------------
Figure 1
The small box in the figure indicates the NIC or other network interfaces.
The router has at least two network interfaces.
Assume that the IP address of Network A is 192.168.0 Nic 1 and 192.168.0.1.
The IP address of Network B is 192.168.1 Nic 4 and 192.168.1.1.
Then the network adapter 2 on the vro must belong to the network 192.168.0 address 192.168.0.x (X is any number less than 255)
Nic 3 on the vro must belong to the network address 192.168.1 as 192.168.1.x (X is any number less than 255)
That is to say, a router belongs to both network A and Network B, so that it serves as a bridge.
When data is sent from Network A to Network B, the router receives data from network adapter 2 and sends data to Network B through network adapter 3 after modification.
In this way, the IP address 192.168.0.x of Network Card 2 is the gateway of Network.
The IP address 192.168.1.x of network adapter 3 is the gateway of Network B.
4. What virtual network devices does vmwarevm provide?
By default, VMWare provides the vmnet1 and vmnet8 virtual NICs, as well as the "amd pcnet family PCI Ethernet Adapter" on the virtual system"
Note that vmnet1 and vmnet8 are virtual devices on the master system. You can see them using the ifconfig command, and "amd pcnet family PCI Ethernet Adapter" is a virtual device on the virtual system, after installing the virtual system, you can see in the device manager that the first two belong to the real system, which is a device in your real computer. The last one belongs to the virtual system and is a device in the virtual computer, do not confuse.
-------------------------------------------
| Network A | router | Network B |
|
| □-- | ----------- | -- □□-- | ---------- | -- □|
| 1 | 2 3 | 4 |
-------------------------------------------
-------------------------------------------------------
| Virtual System | main system (router) | real network |
|
| □-- | ----------- | -- □□< ---> □----- | ------ | -- □|
| Amd pcnet card | vmnet1 vmnet8 real Nic | 4 |
-------------------------------------------------------
Figure 2
Let's make a comparison with the relationship between the above network and the router.
We can see that the amd pcnet nic and vmnet1.
Vmnet1 was originally in the main system, and the system can directly access it. Therefore, the main system acts as a router. As long as there are two virtual devices, the main system and the virtual system can communicate with each other.
The key lies in three points:
1. Make sure that the network numbers of AMD pcnet and vmnet1 are the same.
2. Set Network Properties in the virtual system and set the gateway address to the address of vmnet1.
3. Enable the routing function of the main system to make it a router.
In fact, if you only need to communicate with the Virtual System and the Master System, and do not need to communicate with other hosts on the real network where the master system is located, you only need to satisfy the first point. Because the first point is met, the Master System and the virtual system are in the same network and can communicate without a vro. However, in most cases, we need to communicate with the real network where the virtual system and the main system are located, meeting the requirements of the other two points.
Iv. Virtual Machine network settings (Implementation)
1. Let's first contact the virtual system with the Master System.
When VMware is installed, the installer automatically assigns an IP address to vmnet1. The following is an example on my computer:
Vmnet1 link encap: Ethernet hwaddr 00: 50: 56: C0: 00: 01
Inet ADDR: 192.168.221.1 bcast: 192.168.221.255 mask: 255.255.255.0
Up broadcast running Multicast MTU: 1500 Metric: 1
RX packets: 191 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 63 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 100
RX Bytes: 0 (0.0 B) TX Bytes: 0 (0.0 B)
On the second line, we can see that the IP address assigned by the installer to vmnet1 is 192.168.221.1 (note that each installation of VMware IP address is randomly assigned. The actual situation is different from the example here ). That is, vmnet1 belongs to the network 192.168.221. Therefore, we need to start the virtual system, set the network properties, and set the IP address of the virtual system nic "amd pcnet family PCI Ethernet Adapter" to 192.168.221.x (X is 2 ~ The author sets any number between 254 to 2), and sets the Gateway as the vmnet1 address: 192.168.221.1 (if it does not communicate with the external real network, the gateway can not be set)
Windows 2000 and XP settings take effect immediately, Win98 needs to be restarted, and Linux needs to restart the network service:
# Service network restart
Ping the virtual system on the Master System:
# Ping-C 3 192.168.221.2
Ping 192.168.221.2 (192.168.221.2) from 192.168.221.1: 56 (84) bytes of data.
64 bytes from 192.168.221.2: icmp_seq = 1 TTL = 128 time = 6.91 MS
64 bytes from 192.168.221.2: icmp_seq = 2 TTL = 128 time = 0.425 MS
64 bytes from 192.168.221.2: icmp_seq = 3 TTL = 128 time = 0.527 MS
--- 192.168.221.2 Ping statistics ---
3 packets transmitted, 3 bytes ed, 0% loss, time 2001 Ms
RTT min/AVG/max/mdev = 0.425/2.623/6.917/3.036 MS
Yeah! Yes!
Ping the Master System on the virtual system:
C:/> Ping 192.168.221.1
Pinging 192.168.221.1 with 32 bytes of data:
Reply from 192.168.221.1: bytes = 32 time <10 ms TTL = 64
Reply from 192.168.221.1: bytes = 32 time <10 ms TTL = 64
Reply from 192.168.221.1: bytes = 32 time <10 ms TTL = 64
Reply from 192.168.221.1: bytes = 32 time <10 ms TTL = 64
Ping statistics for 192.168.221.1:
Packets: Sent = 4, stored ED = 4, lost = 0 (0% loss ),
Approximate round trip times in Milli-seconds:
Minimum = 0 ms, maximum = 0 ms, average = 0 ms
Yeah! Again! Contact the Master System and virtual system!
2. allow real network communication between the virtual system and the Master System
First, you need to have a real Nic connected to the real network on your computer (2 ). Vmnet8 takes effect when communicating with the real network. vmnet8 will correspond to the real network card. When the virtual system needs to send data packets to the real network, the real system is a router, first, data is sent to vmnet1, and then to vmnet8 through the vro (the main system is Linux). Because vmnet8 corresponds to the real network card, VMWare completes this mechanism, therefore, the NIC sent to vmnet8 is sent to the real Nic, and then the packet is sent to the real network through the real Nic. For the whole process, see Figure 2. If you have more than two real NICs on your system, the installation program will ask which real Nic the virtual Nic is mapped to during installation. It can be selected based on the actual situation.
Set the IP address of vmnet8 to the address of the same network as the real network card. If the network number of the real network is 192.168.0 and the IP address of the real network card is 192.168.0.1, you can set the IP address of vmnet8 to 192.168.0.2.
In Linux, the method is as follows:
# Ifconfig vmnet8 down
# Ifconfig vmnet8 192.168.0.2 up
Let's review the three conditions mentioned above:
--------------------------------------------------------------
The key lies in three points:
1. Make sure that the network numbers of AMD pcnet and vmnet1 are the same.
2. Set Network Properties in the virtual system and set the gateway address to the address of vmnet1.
3. Enable the routing function of the main system to make it a router.
--------------------------------------------------------------
The first two points have been completed in the first part. Now, you only need to enable the Linux routing function and the virtual system can communicate with the outside world.
Linux is a natural network operating system. Its powerful network functions make it widely used in the network server field. Using Linux as a router does not even require additional software. The Linux kernel directly supports the static routing function. All we need to do is to enable the routing function.
You can first look at the route table:
# Route
Make sure that the IP addresses or network addresses of all NICs are in the destination column, for example:
-------------------------------------------------------------------------------
Kernel IP routing table
Destination gateway genmask flags metric ref use iface
192.168.0.0*255.255.255.0 u 0 0 0 eth1
192.168.0.0*255.255.255.0 u 0 0 0 eth1
192.168.0.0*255.255.255.0 u 0 0 0 vmnet8
192.168.221.0*255.255.255.0 u 0 0 0 vmnet1
127.0.0.0*255.0.0.0 u 0 0 0 Lo
Default www. gucuiwen. CO 0.0.0.0 ug 0 0 0 eth0
-------------------------------------------------------------------------------
By default, when a network device is started, the system adds the IP address of the device to the routing table. If not, restart the network service:
# Service network restart
Enable the routing function again:
# Echo 1>/proc/sys/NET/IPv4/ip_forward
Now, the routing function of Linux has been enabled, and your Linux system has become a vro connected to a virtual network and a real network. The virtual network can communicate with the real network. For security reasons, you need to use the iptables command to set routing rules if necessary.
5. Virtual Machine network settings in windows.
The network settings of virtual machines in windows are basically the same as those in Linux, but additional routing software needs to be installed. Many such software can be used on Windows platforms, such as sysgate Wingate, if you are using Windows 2000 Server or Windows NT server, you can use the system's built-in "Routing and Remote Access" software. The specific settings are ominous. I believe that as long as you understand the principles, it is not difficult to find a suitable solution. If your computer hardware is good enough and you have more than 1 GB of memory and 2 GB of CPU, you can run several virtual machines at the same time to form a network of these virtual machines, in this way, you can have a powerful network lab platform on a computer.
VMware (Virtual Machine workstation) Network Configuration
VMware connects virtual machines to physical networks through virtual network components.
VPC components include the following:
Vswitch: Like a real vswitch, it allows connecting multiple network components, automatically installed as needed during VMware software installation, a maximum of 9 vswitches can be mounted, named VMnet0-8 respectively. Three of them are allocated to the Net Bridge (vmnet0), host machine virtual network adapter (vmnet1), and network address translation NAT device (vmnet8) by default ).
You can connect a virtual machine to an unallocated switch by using the network adapter entry "editing this machine settings" of the virtual machine.
Bridge: The bridge connects the virtual machine to the LAN where your host is located. The method is to connect the virtual adapter on the virtual machine to the physical network adapter on your host machine. If the network connection mode of "typical" or "using bridged networking" is selected in the Wizard for creating a VM, the bridge will automatically generate it.
The figure above shows the relationship between the virtual machine network adapter and the host machine physical adapter under the bridge connection mode. This is the easiest way to allow virtual machines to access the network of the host. In this case, the virtual machine needs its own identification. For example, the TCP/IP network needs its own IP address. This IP address is obtained from the network administrator, and other network details need to be set manually. In the bridge mode, a virtual machine is just like a host in a local network, just like a physical machine. If multiple virtual machines are running in VMware at the same time, each virtual machine should have an independent IP address.
Virtual adapter on the host: a virtual network adapter that appears on the host for use by the vmware workstation. Allow the virtual machine to communicate with the host machine, but this virtual adapter does not connect to any external network. Only special software such as a proxy server established on the host machine can connect the virtual adapter to the physical adapter. In fact, virtual machines only connect to the host machine over the network. This method is also called host-only.
In the create virtual machine wizard, select Custom network settings and select "use host-only networking". Then, this network connection mode will be automatically established. In this case, the host machine operating system can see a virtual network adapter. The host machine can communicate with the virtual machine. It is suitable for establishing an independent private TCP/IP network isolated from external networks. The Virtual Machine IP address is provided by the virtual DHCP server. In combination with the network sharing feature on Windows 2003, XP, and, this connection allows virtual machines to connect to the external internet.
Network Address Translation device: if the host machine has only one IP address for external physical network connection, you can use NAT to connect the virtual machine to the external network.
If you select Custom network settings in the Wizard for creating a virtual machine and select "Use Network Address Translation", the connection will be created. If the network of the host cannot provide an IP address to the virtual machine, Nat is the easiest way to allow the virtual machine to access the network of the host machine. Because the virtual machine does not have an external physical network IP address, VMWare establishes an independent private network on the host machine and obtains the IP address through the Virtual DHCP server. Nat can differentiate the network data of multiple virtual machines and transmit the data between the virtual machine and the external physical network. In Nat mode, many standard TCP/IP protocols can be used on virtual machines, such as HTTP, FTP, and telet. However, computers on external networks cannot be connected to virtual machines by default. Therefore, virtual machines cannot provide services such as Web browsing.
DHCP server: provides a virtual machine with an IP address, which is applicable only to Nat and host-only (that is, the virtual machine only performs network connection with the host machine ).
Network Adapter: when you use the Wizard to generate a virtual machine, create a virtual network adapter for the virtual machine. In the virtual machine operating system, you can see an AMD pcnet PCI adapter. You can create up to three virtual network adapters in the VMware adapter settings.
Configure VM access
Generally, there are two ways for a host to access the Internet. One is that the local machine is in the LAN environment. When multiple computers access the Internet through a switch, the switch is a dial-up host instead of a local machine) there is an IP address, which is similar to the office computer. Another method is to directly dial up the Internet on the Local Computer, such as a home computer. Based on the different ways on which the machine accesses the Internet, the virtual computer's Internet access settings are also different. We will introduce them separately.
I. LAN environment
In the LAN environment, it is actually very simple to set up virtual machines to access the Internet. For example, the IP address assigned by the Windows XP system computer in the LAN is 192.168.0.2, and the Host IP address of the switch in the LAN environment is 192.168.0.1, therefore, the VMware Virtual Windows 2000 system can regard it as a computer in the LAN and assign it an IP address of 192.168.0.4.
Setting Process:
First, open the "Settings" command window under the "virtual machine" menu of the VMware program, and then select "Ethernet" in the hardware settings to set the NIC used by the virtual machine, select "Custom vmnet0 default bridge.
Next, set Network Connection Properties in Windows 2000, and right-click "Network neighbors" on the desktop of Windows 2000 to open the "properties" window, then, right-click "Local Connection" and choose "Internet Protocol (TCP/IP)" and click "properties" to set the IP address of the VM, for example, we assigned the IP address of the VM on the LAN as "192.168.0.4". The default gateway enters the IP address of the LAN host, and the preferred DNS server is the IP address of the LAN host (figure 1 ). Click OK after setting.
Open the IE browser of the Virtual Machine Windows 2000 and enter a URL to check whether the Internet can be accessed normally.
Ii. Local dial-up Internet access
If the local machine is used for dial-up Internet access, it is different from the LAN environment. The local machine does not have an IP address. How can a virtual machine set its own IP address to access the Internet? The VMware Virtual runtime environment has a virtual network (Virtual LAN) function. In VMWare, configure the virtual network host IP address, Virtual Machine (that is, the Windows 2000 system) you can use the gateway of the virtual network host to access the Internet.
Setting Process:
Select the "virtual network settings" command under the "edit" menu of the VMware program, and then the "summary" tab of the virtual network editor window shows the network types that VMware can simulate, there is "vnetwork 8 ".
Next, add the hardware of a virtual network card. Under the "host virtual adapter" tab, add a virtual network named "vmnet8", click "add", and select "vmnet8.
Next, on the "Nat" tab, view the virtual host's "vmnet8" gateway IP address. The default gateway IP address set by VMware Is 192.168.59.2. You can also modify it by yourself.
Similarly, we need to define the "Ethernet" Hardware Device in "Virtual Machine Settings". The network connection method is "Custom vmnet8 (NAT )".
Finally, set the IP address, gateway, and subnet mask of the virtual machine in the current environment in the "Internet Protocol (TCP/IP)" of the Virtual Machine. For example, assign the IP address of this virtual machine to 192.168.59.3, the gateway is the gateway IP address set in "Nat" in the previous step, and then click "OK" to complete the settings.
Now, open the IE browser of the virtual machine, enter the URL to access the Internet in the virtual machine, and enjoy surfing.
VMware and qemu connections
VMware three network connections, qemu two network connections to achieve Virtual Machine <---> host Virtual Machine <---> Internet communication method.
By the way, I wrote how to not re-compile the entire kernel to support a certain function, which has no impact on the system. The compilation speed is faster than compiling the entire kernel.
If your XXX card is not supported by the kernel, and you are afraid that the compiled kernel will cause system damage, you can try this method. ^_^
Three network connection settings for VMware:
1. Bridge:
Vmnet0 is used by default.
Set the IP address of the Virtual Machine and the IP address of the host in the same network segment, and the rest are the same as those of the Host:
For example, if the host IP address is 10.70.54.31, set the Virtual Machine IP address to 10.70.54.22. Netmask, broadcast, gateway, and DNS are all the same as the host to implement Internet communication between virtual machines <---> host virtual machines <---->.
2. NAT:
Vmnet8 is used by default.
Set the VM to use DHCP to access the Internet. In Windows, select "automatically obtain IP Address". In Linux, enable the DHCP service.
You can also set it manually:
The IP address is set to the same network segment as vmnet8, And the gateway is set to the Gateway (/etc/vmware/vmnet8/NAT) of vmnet8. conf) to check the vmnet8 gateway, which is usually XXX. xxx. xxx.2.
The netmask and broadcast settings are the same as those of vmnet8, And the DNS settings are the same as those of the host.
For example, vmnet8 IP: 172.16.249.1 GW: 172.16.249.2
Virtual Machine Settings: IP: 172.16.249.100 GW: 172.16.249.2
3. Host-only:
Vmnet1 is used by default.
Set the Virtual Machine IP address to the same network segment as vmnet1 and gateway to the IP address of vmnet1. the other settings are the same as vmnet1, And the DNS settings are the same as those of the host.
For example, vmnet1 IP: 172.16.245.1
Virtual Machine Settings: IP: 172.16.245.100 Gateway: 172.16.245.1
In this way, the VM <---> host communication is realized, but the VM <---> the Internet still cannot communicate.
Communication between virtual machines and the Internet:
1. Enable Host Routing
2. Set iptables to make the host a NAT Server
1. Echo 1>/proc/sys/NET/IPv4/ip_forward so that the host has the routing function
2. iptables-T Nat-A postrouting-O eth0-s 172.16.245.0/24-J Masquerade
This rule is used to disguise the source IP address from 172.16.245.0/24 packets as an eth0 IP address to implement communication between virtual machines and the Internet.
If the network interface is PPP + or pppoe, you need to change it to-O pppoe.
Of course,-s 172.16.245.0/24 should also be modified according to the actual situation.
Qemu two ways to access the Internet:
User Mode Network:
It is very easy to implement virtual machine Internet access in this way, similar to Nat in VMware. When qemu is started, the-user-net parameter is added. The virtual machine can communicate with the Internet through DHCP, however, the communication between the VM and the host is inconvenient.
TAP/TUN network:
This method is more complex than the user mode, but after the virtual machine is set, the VM <--> Internet Virtual Machine <--> host communication is easy.
This method is similar to VMware's host-only. qemu uses the tun/TAP device to add a virtual network device (tun0) to the host, and then you can configure it like a real Nic.
First, the kernel supports the TAP/Tuns device:
Device Drivers --->
Networking support --->
[M] universal tun/TAP Device Driver Support
If the current kernel does not support this function, you can recompile and add only the corresponding modules. The method is simple:
Run the current Kernel configuration file CP under the kernel source code directory:
[Root @ LFS ~] # Cp/boot/config-[kernel-Version]/usr/src/Linux
[Root @ LFS ~] # Cd/usr/src/Linux
Configure the kernel and select the tun/TAP module (M), as shown in the following figure:
[Root @ LFS ~] # Make menuconfig
Recompile only the module (M), not the core (*) supported stuff:
[Root @ LFS ~] # Make modules
After compilation, you can find tun. KO in/usr/src/Linux/Drivers/NET:
[Root @ LFS net] # ls-L/usr/src/Linux/Drivers/NET/TUN. Ko
-RW-r -- 1 Root 11116 Mar 23/usr/src/Linux/Drivers/NET/TUN. Ko
[Root @ LFS net] #
CP to the corresponding location of the Module Directory of the current kernel:
[Root @ LFS net] # cp/usr/src/Linux/Drivers/NET/TUN. Ko/lib/modules/'uname-R'/kernel/Drivers/Net
Re-establish the module dependency:
[Root @ LFS net] # depmod
Now you can load it:
[Root @ LFS net] # modprobe Tun
Check:
[Root @ LFS net] # lsmod | grep Tun
Tun 8704 0
[Root @ LFS net] #
OK. The entire kernel is not re-compiled and added to the support of special modules.
If your XX card is not supported by the kernel and can be compiled into modules, you can use this method to compile only the modules you need if you are afraid of a problem after re-compiling the kernel, then manually install it to the corresponding location and then load it.
In this way, the Compilation speed is faster than that of the entire kernel. Without any damage to the system, you can use the XX card. Pai_^
Note the following three points:
1. the source code of the kernel must be exactly the same as that of the current kernel version. Otherwise, the compiled modules cannot be used.
2. Note that only make modules (compilation module) does not have make modules_install (the module is automatically installed under/lib/modules)
3. Run depmod before loading the newly compiled module. Otherwise, modprobe cannot find it.
In fact, you can use the current Kernel configuration file (/boot/config-[kernel-Version]) to add only the modules you need without making any changes. Make modules_install should not be faulty.
However, the safest way is to install it manually, and the control is more reliable in your own hands.
OK, go back to qemu for Internet access
If you use udev to manage devices (udev is usually used in 2.6.x kernel releases), after modprobe Tun, the/dev/NET directory is automatically created and the Tun device is created, link:
[Root @ LFS net] # ls-L/dev/NET/TUN
Lrwxrwxrwx 1 Root 6 Mar 25 :35/dev/NET/TUN-> ../TUN
[Root @ LFS net] #
If unfortunately you don't see it, you need to do it manually.
[Root @ LFS ~] # Mkdir/dev/Net
[Root @ LFS ~] # Mknode/dev/NET/tun c 10 200
OK. The related device is ready. You also need a tun/TAP initialization script:
/Etc/qemu-IFUP:
#! /Bin/sh
/Sbin/ifconfig $1 172.20.0.1
Then, you can grant the qemu-IFUP x execution permission under/etc.
This script can only be executed by the root user. To use qemu for normal users, you need to change it to sudo/sbin/ifconfig... and then set Sudo-related permissions.
After qemu is started, it adds a virtual network device (tun0) to the Host ):
[Root @ LFS ~] # Ifconfig tun0
Tun0 link encap: Ethernet hwaddr 0a3: 8A: 5D: 97: CD
Inet ADDR: 172.20.0.1 bcast: 172.20.255.255 mask: 255.255.0.0
Up broadcast running Multicast MTU: 1500 Metric: 1
RX packets: 0 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 0 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 500
RX Bytes: 0 (0.0 B) TX Bytes: 0 (0.0 B)
[Root @ LFS ~] #
Now you can start qemu to configure Virtual Machine network parameters, just like VMware Host-only:
The IP address is the same as tun0, the gateway is tun0, And the other parameters are the same as tun0, And the DNS is the same as the host:
Tun0: IP: 172.20.0.1 broadcast: 172.20.255.255 netmask: 255.255.0.0
Qemu: IP: 172.20.0.100 broadcast: 172.20.255.255 netmask: 255.255.0.0 Gateway: 172.20.0.1
Similar to host-only, in this way, only virtual machines <----> can communicate with each other. You also need to set a router to enable Nat to connect to the Internet.
[Root @ LFS ~] # Echo 1>/proc/sys/NET/IPv4/ip_forward
[Root @ LFS ~] # Iptables-T Nat-A postrouting-O eth0-s 172.20.0.0/24-J Masquerade
[Root @ LFS ~] #