In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to configure static routing under Linux". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to configure static routing under Linux".
A static route is a form of routing in which routing items are manually configured rather than dynamically determined. Unlike dynamic routes, static routes are fixed and will not change, even if the network condition has changed or has been reconfigured.
Background and principle
The function of the router is to realize the communication between one network segment and another, and the routing is divided into static route, dynamic route,
Default routes and directly connected routes. Static routes are specified manually, and the advantage of using static routes is the high security and confidentiality of the network. Dynamic routing requires routers to exchange their routing tables frequently, and the analysis of routing tables can reveal information such as network topology and network address. Therefore, static routing can also be used in the network for security reasons. Does not consume network bandwidth because static routes do not generate update traffic.
Network planning simulation
The simulation uses four Linux machines, named Linux1, Linux2 (router1) and Linux3 (router).
And Linux4, where Linux2 and Linux3 are configured as routers to configure static routing functions, using different network segments and network modes for communication between each two machines
Environmental simulation
Clone four Linux machines and name them. Configure the network card of each machine according to the network plan diagram, using only static ip and subnet mask. The cloned machine needs to execute the command > / etc/udev/rules.d/70-persistent-net.rules to clear the relevant information files of the network card. After configuration, check the ip and verify the communication with the network segment devices.
Linux1
Linux2
Linux3
Linux4
Configure static rout
4.1 add static routes:
Common parameters:
Add adds routing
Del delete route
-net sets the route to a network segment
-host sets the route to a host
Gw egress Gateway IP address
Dev egress Gateway physical device name
Step 1
Linux1:route add-net 192.168.1.0 gw 24 gw 10.0.0.129 (from 1 to 3)
Linux3:route add-net 10.0.0.0 amp 24 gw 192.168.1.129 (from 3 to 1)
At this point, Linux1 and Linux3 can communicate with each other through ping
Step 2
Linux4:route add-net 192.168.1.0 Linux4:route add 24 gw 192.168.2.130 (from 4 to 2)
Linux2:route add-net 192.168.2.0ax 24 gw 192.168.1.130 (from 2 to 4)
At this point, Linux2 and Linux4 can communicate with each other through ping
Step 3:
Linux1:route add-net 192.168.2.0ax 24 gw 10.0.0.129 (from 1 to 4)
Linux4:route add-net 10.0.0.0 amp 24 gw 192.168.2.130 (from 4 to 1)
At this point, Linux1, Linux2, Linux3 and Linux4 can communicate with each other
4.2 if Linux2 and Linux3 machines are involved in configuration, kernel forwarding should be enabled.
Echo 'net.ipv4.ip_forward = 1' > > / etc/sysctl.conf
Or vi / etc/sysctl.conf-> net.ipv4.ip_forward=1
Sysctl-p loads the sysctl configuration file
Verify static rout
5.1 View the routing tables of their respective machines
5.2 execute the ping command on the Linux1 machine to communicate in pairs
5.3 use tcpdump to crawl icmp packets between each pair of communication on other machines for verification
Ping 10.0.0.129-c3
Ping 192.168.1.130-c3
Ping 192.168.2.131-c3
The above configuration will fail when restarting the network service or restarting the system. If you want to take effect permanently, there are several ways
Method
Take Linux1 as an example
Method 1: use route-eth0 file
Vi / etc/sysconfig/network-scripts/route-eth0 # does not exist by default and needs to be created manually
Add the following
192.168.1.0/24 via 10.0.0.129
192.168.2.0/24 via 10.0.0.129
# when there are two network cards, the principle for configuring the route is that the network segment where the network card is located is the route exit
# write to the configuration, restart the network service and restart the system will take effect
Method 2: use static-route file
Vi / etc/sysconfig/static-routes # does not exist by default and needs to be created manually
Add the following
Any net 192.168.1.0/24 gw 10.0.0.129
Any net 192.168.2.0/24 gw 10.0.0.129
# write to the configuration, restart the network service and restart the system will take effect
Method 3: use rc.local file
Vi / etc/rc.local
Add the following
Route add-net 192.168.1.0 Universe 24 gw 10.0.0.129
Route add-net 192.168.2.0 bank 24 gw 10.0.0.129
# write it to the configuration and restart the system will take effect
These are all the contents of the article "how to configure static routing under Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.