A little practice with Linux network settings

Source: Internet
Author: User

some time ago also learned a lot of network-related knowledge, but also through a variety of practices. But it never starts with a real workout from scratch. Please try it today. The following is a detailed record of this process. This includes a partial understanding of the network and a record of the problems encountered.
Practice Content and Purpose:1, using the bridge mode, the multiple Linux virtual machines are bridged together. (if there is a physical host, the same principle.) )2, the preparation of networks, so that virtual machines and hosts, virtual machines and virtual machines can be network interoperability. 3, the virtual machine can access the external network. (If you can ping through www.baidu.com)
parameters that need to be set:Host IP Address: 192.168.1.101 (this IP is configured to die, will not be dynamically assigned by DHCP, in the following operation, this step has been done by default.) )Virtual Machine 1 is connected to virtual machine 2 through a bridge, and the host is set up to be the same network segment so that the host can communicate with each other between virtual machinesVirtual Machine 1ip:192.168.1.11Virtual Machine 2ip:192.168.1.22Gateway Address: 192.168.1.1 (This is the router address, which can be accessed by setting the gateway IP of the host and the virtual machine)
first, the environment preparation:in VirtualBox virtual Machine Manager, a Redhat operating system "RED_HAT_32_VT" (which was previously installed) is installed. today, we cloned an identical virtual machine and named "Red_hat_second" (I want to change the virtual machine in front to Red_hat_first, but not change it).Note: 1, here is the virtual machine to simulate the real server.           In Learning network knowledge and Linux system knowledge, virtual machine and real physical host basically no difference.           2. It is also possible to install virtual machines with VMware or KVM. 3, the physical host (Windows) system IP is 192.168.1.101 4, the router's IP is 192.168.1.1 here the router is an internal and external network connection gateway.
Second, setting the bridge mode in virtual box and VMware This step is simple. Not quite the same in KVM. But the principle is the same.
Third, set up the network 1, check the network configuration just installed virtual machine, inside or the original network configuration. There is only one loopback network card. You can view it by using the IFCONIFG command.
2, add network card from above see only loopback network card, now need to add a network card for subsequent network configuration and operation. If you do not add a network card and make a good connection, you will find that you cannot communicate with the physical host.
You can add a network card via the command line:# command line add a NIC and set its IP to 192.168.1.22Ifconfig eth0 192.168.1.22 netmask 192.168.1.255
but the command line added, just temporarily add, change the terminal environment or the next time you restart the server, this setting will be invalidated. So now consider fromadd in the configuration and add it permanently. In order to make the subsequent configuration undisturbed, the network card added by the previous command line is switched off. Ifconfig eth0 Down
to add a network card by adding a configuration:Enter the/etc/sysconfig/network-scripts/network configuration directory
The ifcfg-switch configuration file is the network configuration of the NIC, you can add a new NIC in a similar way eth0CP Ifcfg-lo ifcfg-eth0Let's look at the configuration of the loopback network card. I marked the part of the message with a red word.
According to the gourd painting scoop, change the ifcfg-eth0 into what we want to be formulated as we need to look,
3. Test the Internal network Restart Network: Service network restart
Another virtual machine in the same way, another virtual machine IP is 192.168.1.11 good, now, the host, two virtual machines are in the same network segment, then they should be able to communicate with each other. The ping test verifies that:
4, set the external network through the previous settings, the host, the two virtual machines can communicate with each other 22. But it seems that you can't access the extranet. Ping www.baidu.com
Through the error message, you can find that the virtual machine to "www.baidu.com" This domain name does not know. Good. Then let's make a configuration for DNS.
To Configure DNS:DNS How to formulate, first through windows to see how the DNS is configured on Windows, in the preparation of Linux up to it. On my winddows machine:
Two ways to configure DNS:the first method: To make a configuration by/etc/resolv.conf the DNS configuration fileentering a Linux virtual machinevim/etc/resolv.conf Edit the DNS configuration file, followed by the following red section:
Note: The above two nameserver, the first one is the primary DNS server, the second service DNS server.
The second method: In the network card configuration file Ifcfg-eth0, add the DNS configuration
Note: If you add it here, you need to restart the network!
OK, DNS has been prepared, then can ping www.baidu.com?
The discovery or ping does not pass. What's going on here.
To Configure the gateway:DNS settings Yes, or ping does not pass www.baidu.comCheck that it is now possible to ping the host, the virtual machine, and the gateway. And DNS is also formulated correctly, supposedly, should be able to access the outside network AH. But there is a critical step: the configuration of the default gateway, not done. How to communicate with the outside world without the configuration of the default gateways? Okay, let's do it now. Configure the gateway: There are two ways to do this: a temporary configuration from the command line: The command line adds a default gateway: The route add defalult GW 192.168.1.1 default gateway, which is the case where the corresponding route is not found, go to this route (default gateway), This is the setting necessary to set up access to the extranet.

In order not to affect the following steps, delete the default gateway by deleting the command line's prepared gateway: Route del default GW 192.168.1.1
The second method: in the network card configuration file for permanent configuration, pay attention to the Red label section. This is done, and you need to restart the network.
Service Network restart

Now you can ping the www.baidu.com, which means you can access the extranet. Well, this is the end of the practice.

A little practice with Linux network settings

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.