Linux Analog Router Experiment

Source: Internet
Author: User

Experimental objectives:

Set up 3 hosts as routers

Enables two terminals to communicate with each other

The network structure is as follows:

650) this.width=650; "Style=" Border-style:none;color:rgb (51,51,51); font-family: '-apple-system ', Blinkmacsystemfont, ' Segoe UI ', Roboto, Helvetica, Arial, Sans-serif, ' Apple Color Emoji ', ' Segoe UI Emoji ', ' Segoe UI Sym ' Bol '; font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height : 21px;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb (255,255,255 ); "alt=" Qq20170819192200.png "src=" Http://upload-images.jianshu.io/upload_images/6886239-f92952fe9074fc7e.png? imagemogr2/auto-orient/strip%7cimageview2/2/w/1240 "/>

Preparatory work:

1, bulk copy of virtual machine files, create multiple systems, in advance to change the MAC address

2. Turn off the firewall

Service iptables Stop//CENTOS6 version

Systemctl Stop Firewalld.service//CENTOS7 version

3. Turn off SELinux

Setenforce 0//Off

Getenforce//view

4. Enable routing forwarding on three "routers"

Echo 1 >/proc/sys/net/ipv4/ip_forward

Echo 1 >/proc/sys/net/ipv4/ip_forward


Operation Process:

1th Step: Configure the network card address, test the direct connection

Configure IP Address

Ifconfig interface IP address/mask

Or

IP addr Add IP address/mask Dev interface

Check IP configuration

IP add

Or

Ifconfig

Pc-a:ifconfig eth2 10.10.1.1/24r_x:ifconfig eth1 10.10.1.254/24//pc-a Gateway ifconfig eth2 10.10.12.1/24//r_y Direct connection R_y:ifco Nfig eth0 10.10.12.2/24//with r_x direct connection ifconfig eth2 10.10.23.1/24//with R_z Direct connect r_z:ifconfig eth0 10.10.23.2/24//r_y Direct connection Ifcon Fig eth1 10.10.2.254/24//pc-b Gateway Pc-b:ifconfig eth1 10.10.1.1/24


Test Direct Connect address using the tool: Ping

If the direct connection does not work, the subsequent cannot operate, must ensure that the IP configuration is correct

The network card configuration file is stored in the following directory:

/etc/sysconfig/network-scripts/

You can modify the corresponding NIC file in the directory if you want to take it permanently


2nd step: Add routes, test

Configure Routing

IP route Add destination network segment/mask via next hop IP address

Or

Route add-net Destination network segment/mask dev native out interface

If you want to get to a certain network, you need to go out from the local specified interface, or specify the neighboring router interface IP address, and this is the next hop

Viewing routing information

Route-n

Or

IP route

Pc-a:ip route default via 10.10.1.254//host A will send the packet to the gateway 10.10.1.254 the R_XR_X:IP route add 10.10.2.0/24 via 10.10, regardless of the network. 12.2 IP route add 10.10.23.0/24 via 10.10.12.2//to reach the target network, this section must have a route to go, but does not care about the route back because that is the R_Y:IP route add 10.10.1 that is responsible for the peer device. 0/24 via 10.10.12.1ip route add 10.10.2.0/24 via 10.10.23.2r_z:ip route add 10.10.1.0/24 via 10.10.23.1ip route add 10.10. 12.0/24 via 10.10.23.1pc-b:ip route default via 10.10.2.254//each route is only responsible for going to the path that the other side is responsible for returning. The route back to this paragraph is the route to the end.

View the routing table for each device

[[email protected]_a ~] #ip  route 192.168.1.0/24  dev eth1  proto kernel  scope link  src 192.168.1.100   metric 1 10.10.1.0/24 dev eth2  proto kernel  scope  link  src 10.10.1.1 default via 10.10.1.254 dev eth2         //Host A has a default route and all packets destined to the destination are given to the Eth2 interface 
[[email protected]_x ~] #ip  route 10.10.23.0/24  via 10.10.12.2 dev eth2 10.10.2.0/24 via 10.10.12.2 dev eth2          //Router r_x The path to the destination network is 10.10.12.2, which is r_y10.10.1.0/24 dev  eth1  proto kernel  scope link  src 10.10.1.254 10.10.12.0/ 24 dev eth2  proto kernel  scope link  src 10.10.12.1    //the two routes above are directly connected to the network 
[[email protected]_y ~] #ip  route 10.10.23.0/24  dev eth2  proto kernel  scope link  src 10.10.23.1  10.10.2.0/24 via 10.10.23.2 dev eth2 10.10.1.0/24 via 10.10.12.1 dev  eth0       //because R_y is one of the 3 routers in the middle, you need to configure routing to both ends, so the next hop is not the same 10.10.12.0/24  dev eth0  proto kernel  scope link  src 10.10.12.2 
[[email protected]_z ~] #ip  route 10.10.23.0/24  dev eth0  proto kernel  scope link  src 10.10.23.2  10.10.2.0/24 dev eth1  proto kernel  scope link  src  10.10.2.254 10.10.1.0/24 via 10.10.23.1 dev eth0 10.10.12.0/24 via  10.10.23.1 DEV ETH0     //has three routers to reach the destination network gateway 
[[Email protected] ~] #ip routedefault via 10.10.2.254 Dev eth1//destination host B10.10.2.0/24 dev eth1 proto kernel scope l  Ink src 10.10.2.1 192.168.2.0/24 dev eth0 proto kernel scope link src 192.168.2.100 192.168.122.0/24 dev virbr0 Proto Kernel scope link src 192.168.122.1

The 192.168.x.x network that appears can be ignored


Test:

Configuration is not a problem, to this step pc-a can ping through pc-b

[[email protected]_a ~] #ping  -c 5 10.10.2.1ping  10.10.2.1  (10.10.2.1)  56 (+)  bytes of data.64 bytes from  The reason why 10.10.2.1: icmp_seq=1 ttl=61 time=0.752 ms    //ttl is 61, is through 3 routers r_x, R_y, R_z,ttl value originally is 64, after 1 routers minus one 64 bytes from 10.10.2.1: icmp_seq=2 ttl=61 time=0.983  ms64 bytes from 10.10.2.1: icmp_seq=3 ttl=61 time=1.74 ms64  Bytes from 10.10.2.1: icmp_seq=4 ttl=61 time=2.12 ms64 bytes from  10.10.2.1: icmp_seq=5 ttl=61 time=1.34 ms--- 10.10.2.1 ping  statistics ---5 packets transmitted, 5 received, 0% packet loss,  Time 4007msrtt min/avg/max/mdev = 0.752/1.389/2.123/0.498 ms 


Below is the path of traceroute to Pc-b on pc-a [email protected]_a ~] #traceroute 10.10.2.1traceroute to 10.10.2.1 (10.10.2.1), hops max , packets 1 10.10.1.254 (10.10.1.254) 0.195 ms 0.066 ms 0.051 MS//first to Gateway R_x 2 10.10.12.2 (10.10.12.2) 0.816 Ms 0.795 MS 0.764 MS//again to R_y 3 10.10.23.2 (10.10.23.2) 0.730 ms 0.701 ms 0.670 MS//Then arrives R_z 4 10.10.2.1 (10.10.2. 1) 0.920 ms 0.893 ms 0.862 MS//Last arrival pc-b//can go to pc-b instructions have been made, if pc-b on traceroute The result is exactly the opposite

Expand:

On r_x and r_z two routers, because their next hop IP address is pointing to neighboring routers, consider merging their two into a default route. Thus reducing the routing entry




This article is from the "Gao Pan" blog, make sure to keep this source http://panpangao.blog.51cto.com/10624093/1957681

Linux Analog Router Experiment

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.