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 change the network card number and configure static route when CentOS dual network card

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly introduces "how to change the network card number and configure static route when CentOS dual network card". In the daily operation, I believe that many people have doubts about how to change the network card number and configure static route when CentOS dual network card. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt of "how to change the network card number and configure static route when CentOS dual network card". Next, please follow the editor to study!

Change the number of the network card

We often find that linux systems often recognize the first network card as eth2 and the second network card as eth0.

However, the hardware label of the server is different, which may give us an illusion in the process of server management.

The name of the network interface in the system can be renamed through the nameif command

1. Use the command to temporarily specify the name of the network card

If you execute the following command as a root user, the name of the network card whose mac address is 00:13:72:52:D9:48 will be changed to eth0

The code is as follows:

# nameif-s eth0 00:13:72:52:D9:48

two。 Permanent changes through the configuration file (after restart) also take effect

Write the configuration to the configuration file

The code is as follows:

# echo 'eth0 0014 13 etc/mactab 72 1 52 1 D9 1 8' > / etc/mactab

Add the following to the Nic configuration file (usually / etc/sysconfig/network-scripts/ifcfg-eth0)

The code is as follows:

HWADDR=00:13:72:52:D9:48

After the modification is completed, restart the server, and the name of the network card whose mac address is 00:13:72:52:D9:48 will be recognized as eth0 by the system.

Set up static rout

Generally speaking, our server sets up 2 network cards and configures the ip addresses of different network segments, but for some network segments, we need to go out through specific network ports, and we need to set up static routes to achieve our purpose, as follows:

Add static routes through the route command, which can be placed in the / etc/rc.local file

The code is as follows:

Cat / etc/rc.local

Route add-net 10.20.0.0 netmask 255.255.0.0 gw 192.168.1.1 dev eth2

Automatically load static routes as the server starts by setting the static route profile

RedHat 6 + 7 + + 8 + + 9 earlier release configuration file / etc/sysconfig/static-routes

The code is as follows:

Cat / etc/sysconfig/static-routes

Any host 10.10.10.10 gw 192.168.1.1 # Host routing

Any net 10.20.0.0amp 16 gw 192.168.1.1 # Route the entire 10.20 network

RHEL 3-4-5 current release configuration file * * / etc/sysconfig/network-scripts/route-interface * * where route-interface is replaced with the corresponding network card name, such as setting a static route for eth2, then the configuration file name is route-eth2

The code is as follows:

Cat etc/sysconfig/network-scripts/route-eth2

ADDRESS0=10.10.10.10

NETMASK0=255.255.255.255

GATEWAY0=192.168.1.1

ADDRESS1=10.20.0.0

NETMASK1=255.255.0.0

GATEWAY1=192.168.1.1

At this point, the study on "how to change the network card number and configure static route when CentOS dual network card" is over. I hope to be able to solve everyone's 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.

Share To

Servers

Wechat

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

12
Report