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

Network Management of Linux (2) Virtual Network Card

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

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

Network Management of Linux (2) Virtual Network Card

In linux, the default kernel module contains a number of network-related components and tools to provide network management and settings. Similarly, linux also supports the setting of virtual network cards, binding of multiple network cards and other functions. In the case of insufficient network card, you can set multiple addresses if you want to use multiple different addresses to represent yourself so that other ip can access them.

Check the basic information of the network card

Use the ifconfig command to view IP

Ifconfig [interface] # is not specified to display all network interfaces by default

Ifconfig eth0 # indicates that only the information of the eth0 network card device is displayed

Example:

Parsing: the format here is for readhat5, version 6, and the information in the higher version may change slightly.

Format description: eth0 stands for network card device name

Inet addr: indicates the ipv4 address

Bcast: indicates the broadcast address

Mask: indicates the subnet mask

HWaddr: indicates the physical address, that is, the mac address

MTU: maximum transmission unit of network card packet

Single network card with multiple addresses:

1. Use the command to set: ifconfig, ip

(1) use ifconfig command

# before setting up, let's check the ipv4 address of eth0, information or length. Here I use the text processing tool to extract the ip.

[root@mageedu ~] # ifconfig eth0 | sed-n 's/.*addr:\ (. *\) [[: space:]] B.roommates /\ 1/gp'10.1.249.185

# similarly, ifconfig can view and set the network card information, and add an ip address to the eth0

[root@mageedu ~] # ifconfig eth0:1 172.16.2.10 netmask 255.255.0.0 up

Parsing: from the above picture, it seems that a new device has been added. In fact, an alias is given to eth0 to store another ip address, while the interface of the network card points to the eth0 device. Adding an alias to the network card is a fixed way to write: ethX:X.

EthX:X:ethX represents the command of the network card device, and the following X represents a label tag for this device, and all views using ifconfig will show two.

# delete the alias and information of the network card just now, and stop this command device directly

[root@mageedu ~] # ifconfig eth0:1 down

Parsing: because this configuration is only in memory, temporarily effective, and is not written to the configuration file, once you stop the data in memory, it is tantamount to erasing the network card alias and all information.

# to verify, use ifconfig naming again to enable the alias eth0:1 you just set

[root@mageedu ~] # ifconfig eth0:1 upSIOCSIFFLAGS: Cannot assign requested address

Explanation: the above statement has been verified here, and it is definitely impossible to identify eth0:1 as a device.

(2) use the ip command

Ip addr show eth0 # displays information about the ip address of eth0

Parsing: the format of the information here is different from that shown in ifconfig, but there is general information. The third line shows the ipv4 address of the current eth0 and its broadcast address, and the / 16 after the ip address indicates 255.255.0.0 (subnet mask).

Ip addr add # add address

[root@mageedu network-scripts] # ip addr add 172.16.2.10 dev eth0

Note: you can add an additional address to the Nic device directly without specifying an alias, but you can only use the ip command to view the additional ip address, but you cannot use the ifconfig command:

# use the ip command to view

Ip addr show eth0

Resolution: the ip of the 172.16 network segment is displayed here, indicating that the configuration has been successful

# use the ip command to add another ip with an alias to eth0

[root@mageedu network-scripts] # ip addr add 192.168.0.0/24 dev eth0 label eth0:0

Resolution: when an ip address is defined with a label name and is identified as an alias device, it can also be viewed using the ifconfig command. Check the test below:

Ifconfig eth0

Conclusion: even if the above methods are set to take effect, they are not guaranteed to take effect permanently. Of course, there are other ways to deal with these files.

2. Write the configuration file:

Note: the above command seems to take effect soon, but once the system or network service is restarted, the information will be cleaned out of memory, so if you want to take effect permanently, you must set up the configuration file. to let the network service restart to automatically read the information in the configuration file to set the network information directly.

# Let's switch to the directory where the Nic configuration file is stored / etc/sysconfig/network-sctipts/,. Before switching, we found that the character length of this directory path is too long, so we can consider setting an alias to switch to the directory more quickly.

(1) set the alias and write to the user profile

Parsing: cdnet is a newly added alias. If you want to use it after saving and exiting, you must first let the current kernel recognize the alias alias.

(2) Let the current bash reread the user profile

[root@mageedu] # source ~ / .bashrc

# look at the list of alias definitions in the current shell again. Cdnet has already appeared.

[root@mageedu] # alias alias cdnet='cd / etc/sysconfig/network-scripts/'alias cdyum='cd / etc/yum.repos.d/'alias cp='cp-i'alias l.='ls-d. *-- color=tty'alias ll='ls-l-- color=tty'alias ls='ls-- color=tty'alias mv='mv-i'alias rm='rm-i'alias which='alias | / usr/bin/which-- tty-only-- read-alias-- show-dot-- show-tilde'

# use the defined cdnet to change directly to the network-scripts directory

[root@mageedu ~] # cdnet

# use pwd to view the current directory, which has been switched successfully

[root@mageedu network-scripts] # pwd/etc/sysconfig/network-scripts

# View eth0 device file ifcfg-eth0

# you can refer to the settings according to the eth0 configuration. Here, create a new network alias profile, ifcfg-eth0:0.

[root@mageedu network-scripts] # vim ifcfg-eth0:0DEVICE=eth0:0 # eth0 denotes an alias for this device, and the following 0 indicates a label tag name BOOTPROTO=staic # because the network card alias, all must be set to static or noneIPADDR=172.16.2.10 # to set an additional ip address PREFIX=16 # PREFIX indicates the number of subnet masks from 255to binary 1s 16-bit 1 means 255.255.0.0GATEWAY=172.16.0.1 # sets the gateway ONPARNET=yes # indicates that when the tagged network card device is enabled, this alias device also takes effect

# restart the network service using the servcie command below

Parsing: ok shown here indicates that each module starts successfully

# check the Nic device again

# add an alias using the command, using the ip command here

[root@mageedu network-scripts] # ip addr add 192.168.0.0/24 dev eth0 label eth0:2

# check again, another Nic alias device has been added, so that others can access it through these three ip addresses

# restart the network service to see if eth0:2 will be deleted

Parsing: the alias of the network card has been verified

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

Network Security

Wechat

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

12
Report