The network route is usually in the home, or in the company, are necessary to configure, so it is very important, today's small series will give you a configuration of network routing configuration of small experiments, for your reference only. First, a brief introduction to network routing. 1. Network routing: Connect the network and network information to other networks, usually network information automatically search for multiple routers, and select the most efficient route. The network router, which works on the third layer of the OSI, connects the WAN, the external Internet, separates the broadcast domain, and most importantly, its routing table. 2. Routing table (1) Routing table: Logical address path problem, select the route table to reach the destination of the best path forwarding data, composed of multiple routing records (2) routing table composition: 4 components ① the target network's network ID NetID, which is divided into three routing host routes: Host address network routing: Network ID Default route: Unknown address ② subnet mask Netmask③. Interface interface, to the target, from which interface to send out to ④. Gateway Gateways: IP of the next router's interface to this router
Ii. several commands for querying, adding, and deleting routing records ①
Route(Old command) Route Management command, when not saved to the configuration file, power on invalid route
- NView Route Information Route
Add-net[/-host] ip/Subnet GW Gateway add network [/host] Route example: Route add-net 10.1.0.0/16 GW 10.2.0.200route Add default GW 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 the Defaults route example: Route add-net 0.0.0.0 Netma SK 0.0.0.0 GW 10.2.0.200route
del-net[/-host] ip/Subnet Delete network [/host] Route example: Route del-net 10.1.0.0/16route del default GW gateway delete default route ②
IP Route(new command) IP route [show|list] View routing information IP route
AddOptions
viaGateway add routed network route: Network/mask host route: IP Example: IP route add 192.168.0.0
/24Via 172.16.0.1 Plus network routed IP route add 192.168.1.13 via 172.16.0.1 plus host route IP route add default via GW plus the defaults route for routing boundary example: IP r Oute add default via 172.16.0.1ip route
delTARGET Delete Route IP route
Flush[Dev IFACE] [via PREFIX] Empty routing table example: IP route flush Dev eth0③/etc/sysconfig/network-scripts/route-Interface (eth0) (system default) route plus routing record configuration file? Note: Need service network Restart to take effect? Two styles: Cannot mix (a) TARGET via GW (multi-use) such as: 10.0.0.0/8 via 172.16.0.1 (b) define one route per three lines (less) Address#=targetnetmask#=maskgateway#=gw④ NETSTAT-NR Show kernel routing table Windows Query routing table: Route print Three, experiment: Configure the routing environment? Lab Tools: 4 virtual machines (virtual machines can be cloned to complete this experiment, after cloning remember to modify the MAC address) a machine R1 router R2 router b machine? Experimental process: (1) Conceptual routing environment
(2) Preparation: 4 machines "Physically connected together" ① according to, we need to divide three network segments: VMnet11, VMnet12, VMnet13
② respectively put a machine, R1 router two interface, R2 router two interface, B machine to the corresponding network segment: A->VMNET11R1 eth0 interface->vmnet11 R1 eth1 interface->vmnet12 R2 interface VMNET12R2 Eth1 Interface->vmnet13b->vmnet13
(3) Query the interface name, if the error (not our habit of eth0, eth1), modify. ① to standardize, the CentOS 7 is changed to the traditional naming method (Eth0, eth1) (This step can not be required) edit the/boot/grub2/grub.cfg, at the first linux16 the end of the line plus net.ifnames=0, restart is effective ②vim/etc /udev/rules.d/70-persistent-net.rules Edit the network interface configuration file ③ The configuration file is not generally effective, so you need the following Operation ethtool-i EthX query interface corresponding network card driver name, The first line is the corresponding network card name rmmod nic name uninstall the corresponding network card modprobe NIC name restart the network card, the interface name is changed (4) Add the required IP address, note: A, b Two machines need to configure the gateway, two routes R1, R2 do not need to set up a gateway. 1.centos 6 Modify IP method vim/etc/sysconfig/network-scripts/ifcfg-ethx Modify the NIC Profile Restart Services service Network Restart effective 2.centos 7 Modify IP Party Law ① Of course can also modify the configuration file, not recommended, because 7 has a good command ②nmcli command, directly into effect, because the command usage too much, it is not known, you can according to 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 to 6 .1.0.100/16, Gateway 6.1.0.200NMCLI connection
Modifyeth0 ipv4.method manual ipv4.addresses 6.1.0.100 ipv4.gateway 6.1.0.200 modified eth0 IP is 6.1.0.100/16, gateway 6.1.0.200NMCLI Connection up eth0 enable eth0 (5) Add two router routing records, you can add r1:route add default GW 6.2.0.201r2:route add default GW using the command described above, according to the idea table (1) 6.2.0.200route-n Query (6) to turn on the routing function of two routes, because the Linux virtual machine is used as a router, so the routing function needs to be turned on. echo 1 >/proc/sys/net/ipv4/ip_forward (7) Turn off firewall iptables-vnl View firewall policy centos6chkconfig iptables off setting boot does not turn on firewall servcie Iptables Stop Firewall centos7systemctl disable FIREWALLD settings boot does not turn on firewall systemctl stop FIREWALLD shut down Firewall (8) test test with ping command, each segment can pin G-Pass. A->vmnet12:ping 6.2.0.201a->vmnet13:ping 6.3.0.100 Four, the routing protocol Small Network configuration, can be set manually, large networks, can be automatically generated by routing protocol Routing Protocol: R2P (Road near, Fewer routers) OSPF (fast, integrated) BGP Eierp (Cisco Proprietary) Conclusion: OK, the small experiment is done, although the experiment is very simple, but the principle is still worth learning, of course, the process of doing the experiment will have a lot of various mistakes, there is nothing to do, can comment together to discuss ~
Linux virtual machine emulation Configuration Network routing Environment-Simple edition