In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail how to solve the problem of adding redhat6.5 static routes. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
First, take a look at the Route command. It is used to manipulate the kernel-based ip routing table, and its main function is to create a static route to specify a host or network through a network interface, such as eth0. When the "add" or "del" parameters are used, the routing table is modified, and if there are no parameters, the current contents of the routing table are displayed.
1. Show the current route
# route-n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.16.14.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 00 eth0
0.0.0.0 172.16.14.254 0.0.0.0 UG 0 0 0 eth0
2. Some basic operations of route
Addition of rout
For a network segment
# route add-net 192.168.100.0 netmask 255.255.255.0 dev eth0
For a host
# route add-host 192.168.100.1 gw 10.224.0.251
Deletion of Linux rout
# route del-net 192.168.10.0 netmask 255.255.255.0 dev eth0
Set the default Linux route
# route add default gw 192.168.10.30
Delete default rout
# route del (default) gw 192.168.10.30
Note: gw means that it is followed by an IP address, not dev.
Note:
When linux loads the configuration file of the network card, eth0 is loaded first, and then eht1 is loaded. In this way, if gateway is set in eth2, the gateway setting in eth0 will be overwritten. Therefore, the solution is to delete the gateway setting of eth2. The file location is in the / etc/sysconfig/networking/devices directory, and delete the gateway setting in eth2.
Second: the method of setting permanent route under linux:
1. Add to / etc/rc.local
Methods:
Route add-net 192.168.3.0 ax 24 dev eth0
Route add-net 192.168.2.0ax 24 gw 192.168.2.254
two。 Add to the end in / etc/sysconfig/network
Method: GATEWAY=gw-ip or GATEWAY=gw-dev
3./etc/sysconfig/static-routes: (create such a file manually without static-routes)
Any net 192.168.3.0/24 gw 192.168.3.254
Any net 10.250.228.128 netmask 255.255.255.192 gw 10.250.228.129
4. Enable IP forwarding:
# echo "1" > / proc/sys/net/ipv4/ip_forward (temporary)
# vi / etc/sysctl.conf-- > net.ipv4.ip_forward=1 (permanently enabled)
There is nothing wrong here, but I didn't have any idea about these parameters before. This time I just studied it and probably understood the meaning of no parameters.
First of all, the simplest is the route add method:
Route add this is the command to add a route, there is nothing to say about this, and then there are the-host and net parameters. According to the information immediately following the parameters, we can find that host refers to adding a host to the route, and net means adding a network segment to the route. The following parameters are dev and gw. Literally, plus the value judgment that follows, dev indicates which network port this host or this net is going through, and gw is gateway, so which gateway is passed naturally. As to why the network port or gateway is specified here, my understanding is that the gateway information is configured on the network port, and the specified network port will eventually read the gateway information corresponding to this network port, which is equivalent to specifying gw parameters. However, the designated network port is generally due to the situation of multiple network environments, if the network port does not specify a gateway, it will read the default gateway, so it is generally required to configure the gateway information of the network port. Under linux, the gateway information is not configured in the configuration file of the network port, for example: / etc/sysconfig/network-scripts/ifcfg-eth0 file, but in / etc/sysconfig/network. So be careful with this when using the dev parameter, as much as possible by specifying gw.
Why the route add method is introduced, because it will be used later. Now let's get back to the subject, about the settings for static-routes. On the Internet, it usually reads:
Any net 192.168.3.0/24 gw 192.168.3.254
The settings are for the entire network segment, but how to set them if it is a single host? At the same time, a script was given from the manufacturer:
Eth0 x.x.x.x netmask 255.255.255.192 gw x.x.x.x
It also looks right, but the execution finds that the added information can't be seen in netstat-an, so not at all.
Then we take a look at the role of the static-routes file. According to the Internet, static-routes is actually called by the network script. Open the script:
/ etc/rc.d/init.d/network
It says:
# Add non interface-specific static-routes.
If [- f / etc/sysconfig/static-routes]; then
Grep "^ any" / etc/sysconfig/static-routes | while read ignore args; do
/ sbin/route add-$args
Done
Fi
Network looks for the line beginning with any in static-routes during execution, and then executes
/ sbin/route add-$args is equivalent to manually executing the route add script, so it's easy to go back to manual execution. According to the previous instructions, the correct script is:
Any host 10.0.0.10 gw 192.168.1.1
Remove any when network executes, and get the following parameter: host 10.0.0.10 gw 192.168.1.1
Then execute route add-host 10.0.0.10 gw 192.168.1.1
Note that the one in front of host-comes with network and does not need to be configured in the static-routes file.
This is the end of the article on "how to solve the problem of adding redhat6.5 static routes". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.