A small practice of linux network settings

Source: Internet
Author: User

A small practice of linux network settings
Some time ago, I also learned a lot of Network-related knowledge and passed various practices. But never start from scratch. I will try it out in a letter today. The following are detailed records of this process. This includes understanding of the network and recording of problems encountered.
Practice and purpose: 1. Bridge multiple linux virtual machines together. (If there is a physical host, the principle is the same .) 2. configure a network to enable network communication between virtual machines and hosts, and between virtual machines. 3. virtual machines can access the Internet. (If you can ping www.baidu.com)
Parameter to be set: Host ip Address: 192.168.1.101 (this configures the ip address and will not be dynamically allocated by dhcp. In the following operations, this step is done by default .) Virtual Machine 1 and Virtual Machine 2 are connected through a bridge and set to the same network segment as the host so that the host can communicate with each other. Virtual Machine 1IP: 192.168.1.11 Virtual Machine 2IP: 192.168.1.22 gateway address: 192.168.1.1 (this is the router address. You can access the Internet by setting the ip address of the gateway between the host and the virtual machine)
I. Environment preparation: a redhat Operating System "Red_hat_32_vt" is installed in the virtualbox Virtual Machine Manager (previously installed ). Today, we cloned an identical Virtual Machine and named it "Red_hat_Second" (I wanted to change the previous Virtual Machine to Red_hat_First, but I couldn't change it). Note: 1. Here we use virtual machines to simulate real servers. After learning about the network and linux system, there is basically no difference between virtual machines and real physical hosts. 2. Using vmware or kvm to install a virtual machine is the same. 3. The ip address in the physical host (windows) system is 192.168.1.101 4, and the ip address of the router is 192.168.1.1. The router here is a gateway connected to the Intranet and Internet.
2. Setting the bridging mode is simple in virtual box and vmware. Kvm is not the same. But the principle is the same.
3. Set the network. 1. Check whether the virtual machine that has just been installed in the network configuration is the original network configuration. There is only one back-to-ring network card. You can see through the ifconifg command.
2. You can see from the above that only the Back-to-ring network card is added. Now you need to add a network card for subsequent network configuration and operations. If you do not add a NIC and configure the network, you will find that it cannot communicate with the physical host, vcq9wLTM7bzT0ru/6c34v6ijugojIMP8we7Q0MztvNPSu7/pzfi/fingerprint = "http://www.2cto.com/uploadfile/Collfiles/20150413/201504130932008.png" alt = "\
However, the command line is added temporarily. If you change the terminal environment or restart the server next time, this setting will become invalid. So now we want to add it from the preparation and add it permanently. In order to avoid interference with the subsequent preparation, first turn off the NIC added in the preceding command line mode. Ifconfig eth0 down
Add the NIC by adding the configuration: Enter the/etc/sysconfig/network-scripts/network configuration directory
The ifcfg-Switch configuration file is the network configuration corresponding to the network card, you can add a new network card eth0cp ifcfg-lo ifcfg-eth0 look at the preparation of the Back-to-ring network card. I marked some information in red.
According to the gourd painting, the ifcfg-eth0 into what we want to prepare into what we need,
3. Test the internal network restart network: service network restart
Configure another virtual machine in the same way. The ip address of the other virtual machine is 192.168.1.11. Now, both the host and the virtual machine are in the same network segment, then they should be able to communicate with each other. Ping test:
4. Set the external network through the previous settings. The host and the two virtual machines can communicate with each other. However, it seems that you cannot access the Internet. Ping www.baidu.com
The error message shows that the virtual machine does not know the domain name "www.baidu.com. Okay. Let's prepare the DNS.
DNS configuration: how to configure DNS. First, you can use windows to check how dns is configured on windows. Then, you can configure it on linux. On my winddows machine:
The first method is to use/etc/resolv. conf dns configuration file to enter the linux Virtual Machine vim/etc/resolv. conf: edit the dns configuration file, and add the following red part to it:
Note: The first two nameservers are the primary dns server and the second dns server.
Method 2: Add dns in the NIC preparation file ifcfg-eth0
Note: You need to restart the network if you want to add it here!
Okay, DNS is ready. Can I ping www.baidu.com?
Ping failure found. What's going on.
Configure the Gateway: Check whether the dns settings are correct, or if you cannot ping www.baidu.com. Now you can ping the host, virtual machine, and gateway. Dns is also correctly configured. It is reasonable to say that you can access the Internet. However, there is another key step: configure the default gateway, which is not ready yet. If no default gateway is configured, how can we communicate with the outside world. Now let's configure the Gateway: there are two ways: first, use the command line for temporary configuration: add the default gateway on the command line: route add defalult gw 192.168.1.1 default gateway, this route (Default Gateway) is used when the corresponding route cannot be found, which is necessary for setting access to the Internet.

In order not to affect the following steps, delete the gateway prepared by the command line to delete the default Gateway: route del default gw 192.168.1.1
Method 2: Perform permanent configuration in the NIC preparation file. Pay attention to the red part. After preparation, restart the network.
Service network restart

Now you can ping www.baidu.com, which means you can access the Internet. Now, this practice is over.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.