search
HomeSystem TutorialLINUXSet up Linux network card independently and fully control the network environment
Set up Linux network card independently and fully control the network environmentFeb 14, 2024 am 08:30 AM
linuxlinux tutoriallinux systemlinux commandshell scriptembeddedlinuxGetting started with linuxlinux learning

With the rapid development of Internet technology, the role of the Internet in our daily lives is becoming more and more important. When building a network environment, the network interface card (NIC) is an important link between the computer and the external network. This article will provide an in-depth introduction to the method of modifying the network card configuration in Linux systems, allowing users to fully control the network environment by independently setting network parameters.

1. Environment

VirtualBox CentOS6.5

**2. Question

**

Sometimes you will encounter such a situation when configuring the network after cloning the server, or when maintaining the server built by others. As shown below:
Set up Linux network card independently and fully control the network environment

That is: in the interface configuration file ifcfg-eth0, the information of the network card eth1 is configured.

This kind of inconsistency may cause some trouble for obsessive-compulsive disorder. Sometimes what we want more is: in the ifcfg-eth0 file, the information of the network card eth0 should be configured, and the network card eth1 should be configured in ifcfg -Configure in eth1.

3. Solution

To solve the above problem, there are roughly two methods:

1) Change the file name of the interface configuration file from ifcfg-eth0 to ifcfg-eth1;

2) Change the name of the network card eth1 to eth0.

method one:

Set up Linux network card independently and fully control the network environment

This method is feasible in actual testing, as shown in the figure below. After modification, just restart the network.

Method Two:
Set up Linux network card independently and fully control the network environment

The intuitive feeling of this method is to directly change the network card name from eth1 to eth0 in the ifcfg-eth0 configuration file. However, if you change it like this, Device eth0 does not seem to be present when you restart the network. That is, Device eth0 does not exist. error, as shown in the figure below. To solve this problem, please refer to "L08-Linux solves the problem of Device eth0 does not seem to be present, delaying initialization".

So it cannot be changed simply and crudely, because, as shown in the figure below by the ifconfig -a command, the network card recognized by the server is still eth1, not eth0.

Note: Remember the mac address here 08:00:27:74:39:02, which can be used as a basis for modification in subsequent implementation steps, because the IP of a server can be changed at will, but the mac address is unique of.

Set up Linux network card independently and fully control the network environment

In order to solve this problem, we first modify the configuration in the /etc/udev/rules.d/70-persistent-net.rules file so that the server’s network card name changes from eth1 to eth0, and then, we Change the network card name in ifcfg-eth0 and finally restart the network.

1) Modify the configuration file /etc/udev/rules.d/70-persistent-net.rules.

The contents of the original /etc/udev/rules.d/70-persistent-net.rules file are as follows:

# This file was automatically generated by the /lib/udev/write_net_rules

# program, run by the persistent-net-generator.rules rules file.

#

# You can modify it, as long as you keep each rule on a single

# line, and change only the value of the NAME= key.

# PCI device 0x8086:0x100e (e1000)

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:9b:bb:3c", ATTR{type}=="1

", KERNEL=="eth*", NAME="eth0"

 
# PCI device 0x8086:0x100e (e1000)

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:74:39:02", ATTR{type}=="1

", KERNEL=="eth*", NAME="eth1"

The modified content is as follows:

# This file was automatically generated by the /lib/udev/write_net_rules

# program, run by the persistent-net-generator.rules rules file.

#

# You can modify it, as long as you keep each rule on a single

# line, and change only the value of the NAME= key.

  
# PCI device 0x8086:0x100e (e1000)

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:74:39:02", ATTR{type}=="1

", KERNEL=="eth*", NAME="eth0"

As shown above

a) Delete the eth0 configuration in the original file (because it is useless. This configuration is the configuration of the source machine when I cloned this server during this test. The corresponding mac address in the configuration is also the source server. The mac address is useless for our current server);

b) Change the eth1 network card name to eth0 (you can notice that its mac address is 08:00:27:74:39:02, which is exactly the entry we want to modify.)

Set up Linux network card independently and fully control the network environment

2) Modify the interface configuration file ifcfg-eth0 and change the network card from eth1 to eth0

Set up Linux network card independently and fully control the network environment

3) Restart the machine and let the server reconfigure the network card information according to the /etc/udev/rules.d/70-persistent-net.rules file

It can be found that after restarting the machine and entering the server, the network has been configured to be consistent, as shown below:

Set up Linux network card independently and fully control the network environment

At this point, the modification is completed.

In today's information age, the network has become an indispensable part of our work and life, and the network card is the key device to achieve network communication. This article explains in detail how to modify the network card configuration in Linux systems and provides some practical cases. By learning this knowledge, we can manage and configure network cards more flexibly, and fully control our own devices in the network environment.

The above is the detailed content of Set up Linux network card independently and fully control the network environment. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:良许Linux教程网. If there is any infringement, please contact admin@php.cn delete
什么是linux设备节点什么是linux设备节点Apr 18, 2022 pm 08:10 PM

linux设备节点是应用程序和设备驱动程序沟通的一个桥梁;设备节点被创建在“/dev”,是连接内核与用户层的枢纽,相当于硬盘的inode一样的东西,记录了硬件设备的位置和信息。设备节点使用户可以与内核进行硬件的沟通,读写设备以及其他的操作。

Linux中open和fopen的区别有哪些Linux中open和fopen的区别有哪些Apr 29, 2022 pm 06:57 PM

区别:1、open是UNIX系统调用函数,而fopen是ANSIC标准中的C语言库函数;2、open的移植性没fopen好;3、fopen只能操纵普通正规文件,而open可以操作普通文件、网络套接字等;4、open无缓冲,fopen有缓冲。

linux中什么叫端口映射linux中什么叫端口映射May 09, 2022 pm 01:49 PM

端口映射又称端口转发,是指将外部主机的IP地址的端口映射到Intranet中的一台计算机,当用户访问外网IP的这个端口时,服务器自动将请求映射到对应局域网内部的机器上;可以通过使用动态或固定的公共网络IP路由ADSL宽带路由器来实现。

linux中eof是什么linux中eof是什么May 07, 2022 pm 04:26 PM

在linux中,eof是自定义终止符,是“END Of File”的缩写;因为是自定义的终止符,所以eof就不是固定的,可以随意的设置别名,linux中按“ctrl+d”就代表eof,eof一般会配合cat命令用于多行文本输出,指文件末尾。

linux怎么判断pcre是否安装linux怎么判断pcre是否安装May 09, 2022 pm 04:14 PM

在linux中,可以利用“rpm -qa pcre”命令判断pcre是否安装;rpm命令专门用于管理各项套件,使用该命令后,若结果中出现pcre的版本信息,则表示pcre已经安装,若没有出现版本信息,则表示没有安装pcre。

什么是linux交叉编译什么是linux交叉编译Apr 29, 2022 pm 06:47 PM

在linux中,交叉编译是指在一个平台上生成另一个平台上的可执行代码,即编译源代码的平台和执行源代码编译后程序的平台是两个不同的平台。使用交叉编译的原因:1、目标系统没有能力在其上进行本地编译;2、有能力进行源代码编译的平台与目标平台不同。

linux中rpc是什么意思linux中rpc是什么意思May 07, 2022 pm 04:48 PM

在linux中,rpc是远程过程调用的意思,是Reomote Procedure Call的缩写,特指一种隐藏了过程调用时实际通信细节的IPC方法;linux中通过RPC可以充分利用非共享内存的多处理器环境,提高系统资源的利用率。

linux怎么查询mac地址linux怎么查询mac地址Apr 24, 2022 pm 08:01 PM

linux查询mac地址的方法:1、打开系统,在桌面中点击鼠标右键,选择“打开终端”;2、在终端中,执行“ifconfig”命令,查看输出结果,在输出信息第四行中紧跟“ether”单词后的字符串就是mac地址。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function