Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure static routing in Linux system

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to configure static routing in Linux system". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to configure static routing in Linux system".

When the host has only one network card, it will not involve the problem of default route and static route. When there are two network cards, one can be configured with a gateway (the default route takes this network card), and the other can only be configured with IP and mask confirmation (the host can be interconnected with the network). However, in a larger environment with multiple network segments, default routes and static routes need to be configured separately.

I. demand

At present, there is a network as follows. The host has two network cards, and the two network segments are the business address eth0 and the management address eth2.

The business address field is: 192.168.3.0Universe 24.

Admin address segment: 10.212.52.0Universe 24

Fire wall section: 10.211.6.0A24 section

The demand now is that the default route goes to the business address (192.168.3.0), the firewall segment goes to 10.211.6.0 to 24 business address, and all addresses to 10.0.0.0Uniple 8 go to the management address segment.

II. Redhat static route configuration

In the redhat environment, there are three configuration methods

Method 1: configure in the / etc/sysconfig/network configuration file:

The code is as follows:

Default via 192.168.3.1 dev eth0 # 192.168.3.1 is the gateway address of the eth0 Nic

10.211.6.0/24 via 192.168.3.1 dev eth0

10.0.0.0Charger 8 via 10.212.52.1 dev eth2 # 10.212.52.1 is the gateway address of the eth2 network card

Note: this configuration method also supports writing to the / etc/sysconfig/network-scripts/route-interferface configuration file.

For more information, please refer to the redhat official documentation.

Method 2: configure in / etc/sysconfig/network-scripts/route-interferface configuration file

Two configuration formats are supported here

A: the method mentioned in method 1

The code is as follows:

# cat / etc/sysconfig/network-scripts/route-eth0

0.0.0.0/0 via 192.168.3.1 dev eth0

10.211.6.0/24 via 192.168.3.1 dev eth0

# cat / etc/sysconfig/network-scripts/route-eth2

10.0.0.0/8 via 10.212.52.1 dev eth2

B: network mask method

The code is as follows:

# cat / etc/sysconfig/network-scripts/route-eth0

ADDRESS0=0.0.0.0

NETMASK0=0.0.0.0

GATEWAY0=192.168.3.1

ADDRESS1=10.211.6.0

NETMASK1=255.255.255.0

GATEWAY1=192.168.3.1

Where the network segment address and mask are all 0 for all network segments, that is, the default route.

# cat / etc/sysconfig/network-scripts/route-eth2

ADDRESS0=10.0.0.0

NETMASK0=255.0.0.0

GATEWAY0=10.212.52.1

The netmask method can also be found in the redhat official documentation.

Method 3: / etc/sysconfig/static-routes configuration

The code is as follows:

# cat / etc/sysconfig/static-route

Any net any gw 192.168.3.1

Any net 10.211.6.0/24 gw 192.168.3.1

Any net 10.0.0.0 netmask 255.0.0.0 gw 10.212.52.1

Note: this file does not exist in the host by default, and this method can also be done because the / etc/init.d/network startup script calls the file. The specific calling code is as follows:

The code is as follows:

# 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

III. Suse static route configuration

Method 1: through the / etc/sysconfig/network/routes configuration file

The code is as follows:

# cat routes

Default 192.168.3.1-

10.0.0.0 10.212.52.1 255.0.0.0 eth2

10.211.6.0 192.168.3.1 255.255.255.0 eth0

Note: the first one configured is a default route, and the default route mask and interface can be replaced by "-". Note that this cannot be done without a default route.

Method 2: through the / etc/sysconfig/network/ifroute-* configuration file

/ etc/sysconfig/network/ifroute-*, where the asterisk represents the corresponding device number, such as the configuration above, which can be configured using the following:

The code is as follows:

# cat / etc/sysconfig/network/ifroute-eth0

0.0.0.0 192.168.3.1 0.0.0.0 eth0

10.211.6.0 192.168.3.1 255.255.255.0 eth0

# cat / etc/sysconfig/network/ifroute-eth2

10.0.0.0 10.212.52.1 255.0.0.0 eth2

You can also refer to the novell site documentation or suse official documentation for details. In the novell site documentation, there is the following paragraph:

The code is as follows:

Define an additional configuration file: / etc/sysconfig/network/ifroute-*. Replace * with the name of the interface.

The entries in the routing configuration files look like this:

DESTINATION GATEWAY NETMASK INTERFACE [TYPE] [OPTIONS]

DESTINATION GATEWAY PREFIXLEN INTERFACE [TYPE] [OPTIONS]

DESTINATION/PREFIXLEN GATEWAY-INTERFACE [TYPE] [OPTIONS]

You can see that the four options that must be configured are: destination segment or host interface gateway address destination segment mask interface

4. View the routing table

After the configuration is completed, you can take effect by restarting the network service and view the routing table information through any of the following commands:

The code is as follows:

# netstat-nr

# route-n

# ip route list

# ip route show

Thank you for reading, the above is the content of "how to configure static routing in Linux system". After the study of this article, I believe you have a deeper understanding of how to configure static routing in Linux system, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report