This article describes how Linux implements broadband Internet sharing with Windows in Hyper-V.
I believe many readers will do (or have done) such an activity-install a Linux system into a virtual machine software in a Windows system, then, you can learn about Linux or experiment in the Windows environment. When conducting such an activity, I do not know whether readers feel the importance of network connectivity (Internet). In fact, both virtual machines and physical machines play a very important role in Linux and Internet networks. Think about it. when Linux cannot (Internet), we need to install a gcc compiler. what do you do? Source code compilation? I think gcc Compilation and installation is not what most people can do. Is the rpm package used for installation? It may take a lot of time to solve the rpm package dependency. Use yum and direct the source to the installation disc? This can indeed solve the gcc installation problem. However, have you ever thought about this problem? although the Linux installation CD does provide us with a lot of software packages, how big is one installation CD, in CentOS 6.4, only the four optical disks can be installed. This means that the optical disks are not omnipotent and there will be a lot of software that we cannot obtain from the optical disks, such as Mono, we must download one from the official website and compile and install it on our own. (Internet) networks are so important that we cannot lose them, even in virtual machines.
In real life, there are many types of virtual machine software, such as VM and VirtualBox, which are well-known and commonly used. If the readers who are reading this article use VM machines as their own Linux virtual machines, you are happy because the VM software is doing very well, its built-in NAT technology can help readers solve network problems at once. In other words, Windows, as a big environment, can access the network normally, you only need to select the "nat" option in the VM Nic settings or use the "8 Nic (vmnet8)" option. The Linux installed in the VM has been accessed (Internet) with the right to the Internet, users do not have to worry about or worry about the Internet.
However, since Hyper-V is selected as the virtual machine software in this article, it means we are not as happy as the VM, we have to make some effort to win the right to access the Internet.
Okay, it's the topic. in this article, we will discuss the research:
1. Introduction to the network background in this article
2. how to add a new NIC in Linux
3. how to implement shared broadband Internet access between Linux and Windows in Hyper-V
4. response policies for TTL detection (route blocking) network environment
1. Introduction to the network background of the current experiment
Previously, when the network center was resident, the Internet account could not be used up in theory. when Linux in the virtual machine wants to access the network, the method we used was normal dial-up Internet access, if a Linux system needs to access the Internet, it needs to dial a number. if there are 10 Linux instances that need to access the Internet, all Linux instances in the virtual machine can access the network. However, this method is extremely luxurious and unrealistic for most readers. Readers are more likely to withdraw from the network center as I do, and return to the dormitory, so there is a total of internet accounts (or money-provided by myself ), only one host can access the network at the same time.
In addition, the current environment only has one broadband account, because it is a campus network (including campus networks of many colleges and universities, Broadband Communities, or Telecom and Unicom broadband users in some regions ), they all have the anti-Network (router blocking) feature. it is really just a broadband account that can only be used by one host to access the network (VM users do not have to worry about this problem here ).
To allow Linux in Hyper-V to access the network, you can use the following methods:
A. open several more internet accounts (very costly)
B. buy an unblocking route (one-time investment, multiple returns, and a good choice)
C. refer to the method in this article (although it cannot be guaranteed to be successful, it is still worth a try, and the previous method cannot be used)
2. add a NIC for Linux
We officially entered our experiment. in order not to disturb the current Linux environment, we decided to add a new NIC for Linux for our current experiment.
First, make sure that there is an "internal" adapter in the "vSwitch manager" of Hyper-V (if not, you need to add one by yourself. here an existing Nic is used, readers do not have to worry about such a long name ).
Then add a NIC for the Linux Virtual Machine:
Note the following points:
(1) in the vSwitch, make sure to select the "internal" attribute adapter (Here we select the new one named "Windows phone ......")
(2) when adding hardware, we recommend that you select "old network adapter" to prevent drivers for the new NIC in some versions of Linux.
Start our Linux system and directly use "setup" to set the NIC:
We found that the newly added Nic is not identified by Linux (here, we use CentOS 6.4 X86_64, and other releases of Linux may be different ), we need to manually add a Nic configuration file. The adding method is very simple. go to the "/etc/sysconfig/network-scripts/" directory, then run cp ifcfg-eth0 ifcfg-eth1 (copy the configuration file of eth0 to eth1) and use the vi editor to open the ifcfg-eth1 profile you just copied:
Then, modify the configuration file as follows:
(1) change "DEVICE" from eth0 to eth1
(2) delete the "HWADDR" line (delete the NIC hardware address of the configuration file record)
(3) delete the "UUID" line (delete the unique identifier of the hardware in the configuration file)
Save and exit.
Continue to open "/etc/udev/rules. d/70-persistent-net.rules" in the vi editor, clear all the content, save and exit, and restart Linux.
Now setup will show the newly added Nic.
Okay. In this way, we have successfully added a new NIC for Linux.
3. Grant network access rights to Linux in Hyper-V
In the previous section, we added an internal adapter. now we share the broadband connection in Windows with this internal adapter so that Linux can share the network in Windows.
Open "network connection" in Windows ":
There are a lot of network adapters, which you don't need to worry about, just pay attention to the two blue boxes in the figure, one is a "broadband connection" (that is, a Windows broadband connection ), the other is "vEthement (Internal Ethernet ......)" (That is, the internal network adapter created in Hyper-V ).
In "broadband connection", right-click and select "properties" to open the Settings window and open the "share" tab, check "allow other network users to connect through the Internet connection of this computer", and select the new "internal" network adapter from the "home network connection" drop-down menu.
Click OK to save and exit. disconnect the current Windows broadband connection. after dialing again, the setting will take effect.
Then, set the IP address of our "internal" adapter. you just need to set an IP address of different network segments as needed.
Then, use DHCP to obtain IP addresses in eth1 Nic settings in Linux (interested readers can try to use static IP addresses and DHCP to obtain Linux IP addresses respectively, then compare the differences in "/etc/resolv)
Save and exit, and run "service network restart" to restart the network configuration
Now try to see if you can resolve the domain name "www.baidu.com ".
Well, our Baidu domain name can be properly resolved. because domain name resolution requires a connection to the DNS server, we can now see the resolution, which means that our Linux can be connected to the Internet, with the ability to access the network.
4. TTL detection for dial-up servers
Some readers may have encountered such a situation: there is now a broadband internet account, for some reason (such as adding some new computers ), I want to allow several computers to share this broadband account to access the internet. as a result, I bought a vro from the computer center. after setting relevant parameters very correctly, I found that I could not browse the webpage, from the packet monitoring in the vro, it is also found that packets are constantly sent, but one packet cannot be received. Take the router back to the computer center, where the router can be used normally.
If you have encountered this problem and ruled out a router fault, you can only prove one thing: there is a blocking on the router in the current network environment, that is, there is TTL detection in the dial-up server (of course, there are many ways to block the use of routers, the more common and popular way is to use TTL detection, in this article, we only take measures for TTL Detection ).
You can search for details about TTL values online. Here, I will just give a brief explanation: our data packet transmission in the network, from a network segment to another network segment, which requires the vro to play a role in it, however, a network composed of multiple network segments is often very large (such as the Internet). if there is no limit on the number of data packets transmitted, such an event may occur: "data packets are constantly transmitted over the network, traveled throughout the network, and this action is constantly repeated ". In this way, not only does the network congestion increase suddenly, but the whole network is even squashed, in addition, the host that sends this data packet cannot determine whether the data packet is reachable (that is, whether the receiver or receiver is found to exist ). Therefore, to solve this problem, we will set a TTL value in the data packet when sending the data packet. every time this data packet is forwarded through a router, the TTL value in the data packet is reduced by 1 until the TTL value in the data packet changes to 0, the router automatically considers the data packet to be inaccessible and discards the data packet.
For this feature of TTL value, you only need to add a TTL value detection to the dial-up server, as long as the user accesses the Internet through a vro (except for those with the function of releasing or flushing the firmware ), the TTL value of data packets arriving at the dial-up server is not the default TTL value (the default TTL value for Windows is 128, and the default TTL value for Linux is 64 ), if you do this in the dial-up server: "discard all data packets that are not the default TTL value", This achieves the effect of vro blocking. That is the reason why the reader sees that packets are constantly sent but one packet cannot be received in the packet monitoring of the router.
In this article, Hyper-V shared internet has encountered such a problem (not all readers may encounter it). For example, I want to download something from the Internet:
Although DNS can resolve domain names, it cannot download from the Internet. The reason for this phenomenon is that the principle of Internet sharing is the same as that of vrouters, and the current campus network blocks vrouters.
The method used to solve TTL detection and block the router is direct, that is, to modify the TTL value when the data packet is sent from the NIC.
For the configuration in this article, I used excel to draw a simple schematic. when Linux in the virtual machine sends a packet through eth1, the packet will be sent to the "internal" adapter, the "internal" adapter then acts as a routing function to forward data packets to the broadband connection. then, the broadband connection also acts as the same function to forward data packets. There is a simple arithmetic question: "The default TTL value for Windows is 128, that is, the data packet generated from the broadband connection must be 128 to be not discarded by the dial-up server, each time a packet passes through a route, the TTL value is reduced by 1. how many data packets are generated from eth0 before the packet is discarded by the dial-up server?" A smart reader will surely be able to give the answer to a quick calculation-130 !!!
Okay. now that we have calculated the appropriate TTL value, we will not talk much about setting the TTL value for Linux data packets. We only need to use the vi editor to open "/etc/sysctl. conf, and then add the "net. ipv4.ip _ default_ttl = 130 ", then save and quit and restart the network.
In this way, we can break through the blocking of vrouters on the current network.
You can download things.
At the same time, readers should pay attention to the following points: always be cautious about the functions of seLinux and iptables. if these two items are enabled in this article, you cannot download things. You should remember.
Now, how does Linux (CentOS) achieve broadband Internet sharing with Windows in Hyper-V is over.