Linux Virtual Machine simulated configuration Network Routing environment-lite version, linux Virtual Machine

Source: Internet
Author: User

Linux Virtual Machine simulated configuration Network Routing environment-lite version, linux Virtual Machine
Network Routing must be configured at home or in the company, so it is very important. Today, I will give you a small experiment on configuring network routing, for your reference only. 1. First, let's briefly introduce the network routing. 1. Network Routing: connect the network and direct the network information to other networks. Generally, the network information is automatically searched for multiple routers and the most efficient route is selected. A network router, working at the Layer 3 of OSI, connects to the Wan and the external internet to separate broadcast domains. The most important thing is its route table. 2. route table (1) route table: Logical Address path problem. Select the best route forwarding data to reach the target in the route table, which consists of multiple route records (2) route table: consists of four components ① The network ID netid of the target network, which is divided into three routing host routes: Host address network route: network ID default route: unknown address ② subnet mask netmask ③. interface, which interface is sent to the target? 4. gateway: the IP address of the next router interface Near the current router.

 

Ii. commands for querying, adding, and deleting route records ① Route(Old command) route management command. The route is invalid when it is not saved to the configuration file. -NView route information route Add-Net [/-host] IP/subnet gw gateway add network [/host] routing example: route add-net 10.1.0.0/16 gw 10.2.0.200route add default gw gateway add default routing example: route add default gw 10.2.0.200 or route add-net 0.0.0.0 netmask 0.0.0.0 gw gateway add default route example: route add-net 0.0.0.0 netmask 0.0.0.0 gw 10.2.0.200route Del-Net [/-host] IP/subnet Delete network [/host] routing example: route del-net 10.1.0.0/16 route del default gw gateway delete default route ② Ip route(New command) ip route [show | list] view route information ip route AddOption ViaGateway add route NETWORK route: NETWORK/MASK host route: IP address example: ip route add 192.168.0.0 /24Via 172.16.0.1 + network route ip route add 192.168.1.13 via 172.16.0.1 + host route ip route add default via GW + default route, for routing boundary example: ip route add default via 172.16.0.1ip route DelTARGET deletes the route ip route Flush[Dev IFACE] [via PREFIX] Clear route table example: ip route flush dev eth0 ③/etc/sysconfig/network-scripts/route-interface (eth0) (not available by default) configuration file of route records added by route • Note: service network restart is required • two styles: cannot mix (a) TARGET via GW (Multi-Purpose) such: 10.0.0.0/8 via 172.16.0.1 (B) define a route entry (rarely used) ADDRESS # = TARGETNETMASK # = maskGATEWAY # = GW ④ netstat-nr: display the kernel route table windows query route table: route print 3. Experiment: configure the routing environment • experimental tool: 4 virtual machines (you can clone a virtual machine to complete this experiment. Remember to modify the MAC address after cloning) machine A R1 router R2 router B • experiment process: (1) conception of the routing Environment

 

(2) Preparations: "physically Connect the four machines together" ① according to the requirements, we need to divide the four machines into three network segments: VMnet11, VMnet12, and VMnet13

② Put machine A, router R1, router R2, and machine B into the corresponding network segment: a-> eth0 interface of VMnet11R1-> eth1 interface of VMnet11 R1-> eth0 interface of VMnet12 R2-> eth1 interface of VMnet12R2-> VMnet13B-> VMnet13

 

(3) query interface name. If it is incorrect (not the eth0 or eth1 we are used to), modify it. ① For standardization, change centos 7 to the traditional naming method (eth0, eth1) (this step is not required) to edit/boot/grub2/grub. cfg, add net. ifnames = 0, effective only after restart ② vim/etc/udev/rules. d/70-persistent-net.rules edit the network interface configuration file ③ After the configuration file is modified, it generally does not take effect, so the following operation is required: ethtool-I ethX query interface corresponding NIC Driver name, the first line is the corresponding Nic name rmmod Nic name uninstall the corresponding Nic modprobe Nic name restart Nic, interface name changed (4) Add the required IP address, note: gateways are required for machines A and B, and gateways are not required for Routers R1 and R2. 1. in centos 6, modify the IP method vim/etc/sysconfig/network-scripts/ifcfg-ethX, modify the NIC configuration file, and restart the service network restart. 2. in centos 7, the IP address method ① can also modify the configuration file. This is not recommended because there are good commands in 7. ② The nmcli command takes effect directly because the command is used too much, for more information, see the following command to set the IP address nmcli connection. AddType ethernet con-name eth0 ifname eth0 ipv4.method manual ipv4.addresses 6.1.0.100/16 ipv4.gateway 6.1.0.200 add eth0 ip address 6.1.0.100/16, Gateway is 6.1.0.200nmcli connection ModifyEth0 route 4.method manual route 4.addresses 6.1.0.100 route 4.gateway 6.1.0.200 modify the ip address of eth0 to 6.1.0.100/16, and the gateway to 6.1.0.200nmcli connection up eth0 enable eth0 (5) add route records of two routers, you can use the commands described above to add R1: route add default gw 6.2.0.201R2: route add default gw 6.2.0.200route-n to query (6) according to the concept table (1) enable the routing function of two routes. Because a linux virtual machine is used as a router, You need to enable the routing function. Echo 1>/proc/sys/net/ipv4/ip_forward (7) disable firewall iptables-vnL view firewall policy centos6chkconfig iptables off set boot disabled firewall servcie iptables stop disable firewall centos7systemctl disable firewalld set boot disabled firewall systemctl stop firewalld disable firewall (8) the ping command is used to test the experiment. All sections can be pinged. A-> VMnet12: ping 6.2.0.201A-> VMnet13: ping 6.3.0.100 4. You can manually configure the routing protocol for small networks. For large networks, the routing protocol can be automatically generated through the routing protocol: r2P (Road approaching, less routers) OSPF (fast, comprehensive consideration) bgp eierp (Cisco proprietary) Conclusion: Well, the small experiment is done, although the experiment is very simple, however, the principle is worth learning. Of course, there are many errors during the experiment. If you have any questions, you can comment on them and discuss them together ~

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.