Network Management of Linux (2) virtual network card

Source: Internet
Author: User
Tags aliases tag name

Network Management of Linux (2) virtual network card

in Linux , the default kernel module contains many network-related components and tools to provide management and setup of the network. Similarly,Linux is also a support for virtual network card settings, has many network adapter bindings and other functions. In the case of insufficient network card, want to use a number of different addresses to represent themselves, so that other IP access, can be set up multiple addresses.

Network card basic Information view

Use the ifconfig command to view IP

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

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

Example:

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/86/DC/wKioL1fNaVCR0596AAAlTBDL9I4916.png "title=" Ifconfig.png "alt=" Wkiol1fnavcr0596aaaltbdl9i4916.png "/>

Parsing: Here the format is for READHAT5,6 version, the higher version may have some minor changes in information.

Format Description: eth0 represents the NIC device name

inet addr: Represents IPv4 address

Bcast: Represents a broadcast address

Mask: Represents the subnet mask

HWaddr: Represents the physical address, which is the mac address

MTU: Network card packet Maximum transmission unit

Single-NIC multi-Address:

1, use the command to set :ifconfig,IP

(1) using the Ifconfig command

#在设置之前, let's look at eth0 's IPv4 address, information or long, here I use the Text Processing tool to remove IP

[Email protected] ~]# ifconfig eth0 | Sed-n ' s/.*addr:\ (. *\) [[: Space:]]b.*$/\1/gp ' 10.1.249.185

#同样ifconfig can view the network card information, can also set the network card information, the eth0 added an IP address

[Email protected] ~]# ifconfig eth0:1 172.16.2.10 netmask 255.255.0.0 up

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/86/DC/wKioL1fNambxJAXoAAAo9g_n_Ok325.png "title=" Ipconfig_add1 "alt=" Wkiol1fnambxjaxoaaao9g_n_ok325.png "/>

Parsing: From the point of view, it seems that a new device is added, in fact, the Eth0 has an alias to hold another IP address, and the NIC interface is pointing to the eth0 device, adding aliases to the NIC this is a fixed wording: ethx:x

Ethx:x:EthX represents a command for the NIC device, and the following X represents a label label for the device, and all two views are displayed using ifconfig .

#删除刚才的网卡别名及信息, stop this command device directly

[Email protected] ~]# ifconfig eth0:1 down

Parsing: Because this configuration is only in memory and is temporarily in effect, it is not written to the configuration file, so once you stop an in-memory data, it is equivalent to clearing out the NIC alias and all the information.

#为了验证, use ifconfig naming again below to enable the alias you just set eth0:1

[Email protected] ~]# ifconfig eth0:1 Upsiocsifflags:cannot Assign requested address

Description: This proves that the above statement, the eth0:1 as a device to identify, is certainly not recognized.

(2) Using IP commands

IP addr Show eth0 # show eth0 IP address related information

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/86/DC/wKioL1fNaw7CYL9tAAAY-huy5h8874.png "title=" Ip_ Show "alt=" Wkiol1fnaw7cyl9taaay-huy5h8874.png "/>

Parsing: Here the information format and ifconfig display is different, but the general information is, line 3 shows the current eth0 IPv4 address and its broadcast address,IP address after the / the 255.255.0.0(subnet mask).

IP addr Add # add address

[[Email protected] network-scripts]# IP addr add 172.16.2.10 dev eth0

Note: You can add an additional address directly to the network card device by not specifying an alias, but you can only use the IP command to see the additional IP address, and the ifconfig command is not visible:

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/86/DD/wKiom1fNbKSTWm9yAAAs0nFPM7w925.png "title=" Ifconfig cannot see multiple address "alt=" wkiom1fnbkstwm9yaaas0nfpm7w925.png "/>

#下面使用IP Command View   

IP Addr Show eth0

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/86/DD/wKiom1fNbM_Cx6AZAAAbxBhm3eE693.png "title=" IP View multi-IP "alt=" Wkiom1fnbm_cx6azaaabxbhm3ee693.png "/>

Resolution: This shows the IPof the 172.16 segment, indicating that it has been successfully configured

# Add an alias IP to eth0 using the IP command

[[Email protected] network-scripts]# IP addr add 192.168.0.0/24 dev eth0 label eth0:0

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/86/DC/wKioL1fNbdnSl50VAAAdZJujjGY004.png "title=" IP command View 2.png "alt=" Wkiol1fnbdnsl50vaaadzjujjgy004.png "/>

Parsing: When an IP address is defined as a label name, it is also recognized as an alias device, then the use of the ifconfig command can also be viewed, the following view test:

Ifconfig eth0

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/86/DC/wKioL1fNbmuB_nE_AAA2WADQnH4439.png "title=" Ifconfig view Ip.png "alt=" Wkiol1fnbmub_ne_aaa2wadqnh4439.png "/>

Summary: The above method even if set to take effect, but can not guarantee the permanent effect, of course there are other ways to deal with the volume of these files.

2. Write the configuration file:

Note: The above command appears to take effect quickly, but once the system or network service restarts, the information will be removed from the memory, all, to be permanent, the configuration file must be set to allow the network service to restart automatically read the configuration file information to set up network information directly.

#下面我们切换到存放网卡配置文件的目录/etc/sysconfig/network-sctipts/, before switching, the character length of this directory path is found to be too long, so consider setting an alias to switch to the directory more quickly.

(1) setting aliases and writing to user profiles

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/86/DD/wKiom1fNbvnzKGdVAAAdE2WVaCE864.png "title=" Add the Cdnet alias. png "alt=" wkiom1fnbvnzkgdvaaade2wvace864.png " />

Parsing: Cdnet is the newly added alias, you want to use it after saving, you have to let the current kernel recognize alias alias


(2) let the current bash reread the user profile

[Email protected] ~]# source ~/.BASHRC

shell alias cdnet There's already a

[[email protected] ~]# 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 '

#使用定义好的cdnet switch directly to the network-scripts directory

[Email protected] ~]# cdnet

#使用pwd to view the current directory, has been successfully switched

[Email protected] network-scripts]# pwd/etc/sysconfig/network-scripts

#查看eth0 device file ifcfg-eth0

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/86/DC/wKioL1fNb-WzCByrAAAb8_04N8c881.png " Title= "Ifcfg-eth0.png" alt= "Wkiol1fnb-wzcbyraaab8_04n8c881.png"/>

#可以根据 eth0 configuration to refer to Settings, create a new network alias profile ifcfg-eth0:0

[[email protected] network-scripts]# vim ifcfg-eth0:0device=eth0:0 #eth0表示为为此设备做别名: The following 0 represents a label tag name Bootproto=sta IC #因为网卡别名, all of which must be set to static or noneipaddr=172.16.2.10 #设置额外的ip地址PREFIX =16 #PREFIX表示子网掩码255换成2进制1的个数 , 16-bit 1 indicates 255.255.0.0gateway=172.16.0.1 #设置网关ONPARNET =yes #表示标记的网卡设备启用时, and this alias device also takes effect at the same time

#下面使用servcie command to restart the network service

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/86/DD/wKiom1fNcEHgYVtRAAAOl3lgBPk989.png "title=" Restart the network service. png "alt=" Wkiom1fncehgyvtraaaol3lgbpk989.png "/>

Parse: Show OK here indicates that each module started successfully

#再次查看网卡设备

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/86/DC/wKioL1fNca-wJRijAAA2RykQQPg982.png "title=" Ifconfig view 1.png "alt=" Wkiol1fnca-wjrijaaa2rykqqpg982.png "/>

#再使用命令添加一个别名, use the IP command here

[[Email protected] network-scripts]# IP addr add 192.168.0.0/24 dev eth0 label Eth0:2

#再次查看, there is another NIC alias device, so that other people can access the 3 IP Address

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/86/DC/wKioL1fNcduh173jAABGJX1domg337.png "title=" Ifconfig view 2.png "alt=" Wkiol1fncduh173jaabgjx1domg337.png "/>

#下面重启网络服务 to see if eth0:2 will be deleted

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/86/DD/wKiom1fNcfGwTjUVAABEPiFgLwU112.png "title=" Ifconfig view 3.png "alt=" Wkiom1fncfgwtjuvaabepifglwu112.png "/>

Parsing: The alias of the NIC has been verified



This article is from the "Excalibur Trunks-kun" blog, please be sure to keep this source http://mengzhaofu.blog.51cto.com/10085198/1846545

Network Management of Linux (2) virtual network card

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.