In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "routing configuration commands and several ways to configure permanent routes under Linux". In daily operation, it is believed that many people have doubts about routing configuration commands under Linux and several ways to configure permanent routes. The editor consulted all kinds of materials and sorted out simple and useful operation methods. I hope it will be helpful for you to answer the doubts about "routing configuration commands under Linux and several ways to configure permanent routing"! Next, please follow the editor to study!
Routing configuration commands under Linux
1. Add host rout
Route add-host 192.168.1.11 dev eth0 route add-host 192.168.1.12 gw 192.168.1.1
two。 Add Network rout
Route add-net 192.168.1.11 netmask 255.255.255.0 eth0 route add-net 192.168.1.11 netmask 255.255.255.0 gw 192.168.1.1 route add-net 192.168.1.0 eth0 route add 24 eth0 route add-net 192.168.1.0 gw 192.168.1.1
3. Add default Gateway
Route add default gw 192.168.1.1
4. Delete a rout
Route del-host 192.168.1.11 dev eth0
5. Delete default rout
Route del default gw 192.168.1.1
Several ways to configure permanent routing under Linux
1. Add routing information to / etc/rc.local
Route add-net 192.168.1.0 netmask 24 dev eth0 # or route add-net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1
two。 Add to / etc/sysconfig/network
GATEWAY= [gateway IP or gateway Nic name]
3./etc/sysconfig/static-routes
Any net 192.168.1.0 any net 24 gw 192.168.1.1 # or any net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1
4. Enable IP forwarding
1. Temporary opening
Echo "1" > / proc/sys/net/ipv4/ip_forward
two。 Permanently open
Vim / etc/sysctl.conf modify net.ipv4.ip_forward=1
Lab: configure dual Nic hosts to use both internal and external networks
The background of this experiment is a problem encountered by the author in practice, and this experiment tries to restore the network environment at that time. Take it as a note and share it with the students who encounter this problem.
But I don't have any hardware right now. VMware Workstation and eNSP can only be used to simulate the experimental environment.
Problem background
As shown in the following topology, if the client node is removed, the internal and external networks are isolated from each other.
But the actual situation is that client nodes need to access both external and intranet resources, while client can only configure one default route. If the default route is configured on the external network card, client can access the resources of the 172.16.2.0 Universe 24 network and the resources of the external network, but the rest of the internal network resources cannot be accessed. If the default route is configured on the internal network card, client can fully access the internal network resources, but it cannot access the external network resources. How to solve it?
Experimental environment
VMware Workstation Pro
4 minimally installed CentOS 7.3virtual machines
Huawei eNSP Simulator
Experimental topology
Without the client node, the internal network and the external network are isolated.
The external network is 10.0.0.0amp 16, which represents the operator's access network.
The intranet network is 172.16.0.0amp 16, which represents the intranet part (for security reasons, direct access to the Internet is not allowed).
Where:
Client is a host with dual network cards, and the network segments of the two network cards are 10.0.0.0Universe 16 and 172.16.2.0Universe 24, respectively.
A server with a server2 of 172.16.2.0 and a server of 24 network segments
A server with a server3 of 172.16.3.0 and a server of 24 network segments
The server4 is the server on the 24 network segment of 172.16.4.0.
Network planning
How to implement the intranet router?
VMnet2, VMnet3 and VMnet4 are all in host-only mode, so under normal circumstances, only the computers in the network can communicate. How can we realize the communication between the three networks?
The answer is to use Cloud in Huawei's eNSP simulator. Using Cloud devices, you can connect the router in eNSP to the network card of the VMware virtual machine.
Configure the private network environment
Configure the router for eNSP
System-view [huawei] int g0/0/0 [Huawei-GigabitEthernet0/0/0] ip address 172.16.2.254 255.255.255.0 [Huawei-GigabitEthernet0/0/0] quit [huawei] int g0/0/1 [Huawei-GigabitEthernet0/0/1] ip address 172.16.3.254 255.255.255.0 [Huawei-GigabitEthernet0/0/1] quit [huawei] int g0/0/2 [Huawei-GigabitEthernet0/0/2] ip address 172. 16.4.254 255.255.255.0 [Huawei-GigabitEthernet0/0/2] quit [huawei]
Modify the IP address of the virtual machine
Build HTTP service on server
Take server2 as an example:
Create a simple HTTP service using Python
Cd ~ echo "server2" > index.html python-m SimpleHTTPServer 8080
Control trial, access to the external network on client
Ping www.baidu.com-c 4
Access server2 on client
Ping 172.16.2.11-c 4
Access server3 on client
Ping 172.16.3.11-c 4
Access server4 on client
Ping 172.16.4.11-c 4
In the control experiment, it can be seen that when client configures the default gateway on the external network card, the client of the dual network card can normally access the 172.16.2.0 Unix 24 part of the external network and the internal network, while 172.16.3.0 Universe 24 and 172.16.4.0 Universe 24 cannot be accessed.
Why can client access the 172.16.2.0 ax 24 network, but not the rest of the 172.16.0 amp 16 network?
Because client is located in the 172.16.2.0 Universe 24 network and communicates within the network, packets do not have to be sent to other networks, and of course the default gateway does not work.
When client communicates with the rest of the 172.16.0.0Comp16 network, the routing table of client does not record the path to the destination address, so client can only foolishly send the packet to the default gateway, and from then on the packet and the real destination address are "poles apart". Of course, the result of ping is that the network is unreachable.
Routing configuration
View the routing table on client
Add routes on client
Route add-net 172.16.0.0amp 16 gw 172.16.2.254
Permanent configuration, then add routing information to / etc/rc.local
Route add-net 172.16.0.0amp 16 gw 172.16.2.254
View routing tabl
Experimental results
Test connectivity
Ping www.baidu.com-c 4
Ping 172.16.2.11-c 4
Ping 172.16.3.11-c 4
Ping 172.16.4.11-c 4
Access to internal and external network resources
Curl http://www.baidu.com/
Curl http://172.16.2.11:8080/index.html curl http://172.16.3.11:8080/index.html curl http://172.16.4.11:8080/index.html
The solution is very simple. It's just a command. However, the principles, concepts and theories behind this command need us to study deeply.
At this point, the study on "routing configuration commands under Linux and several ways to configure permanent routes" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.