The alias of the NIC configured under Linux is the configuration of the NIC sub-IP

Source: Internet
Author: User

What is an IP alias?
In the words of Windows, you configure multiple IPs for a network card.
When do I add IP aliases to what occasions?
Web needs, multi-IP access testing, specific software for multiple IP needs ... and so on.

How
Here are a few examples of how to use the Ifconfig command to configure an IP alias for a network card.
For the configuration of the ip/mask/dns/Gateway/route, seeRouter/linux host/win The host's routing configuration summary.   Note: Be aware that your configuration takes effect immediately or permanently.
First, configure a static IP address for the server NIC
#ifconfig eth0 192.168.6.99 netmask 255.255.255.0 up

Eth0//The first network card of the machine, some machines have multiple network cards, eth1, eth2 ...
192.168.6.99//Set the static IP address of the network card
netmask 255.255.255.0//IP Address Subnet mask, no more explanation
Up//Indicates immediate activation of the NIC

#ifconfig
If the static IP has been set successfully second, set the IP alias of the network card
#ifconfig eth0:0 192.168.6.100 netmask 255.255.255.0 up
#ifconfig eth0:1 173.173.173.173 netmask 255.255.255.0 up
#ifconfig eth0:2 119.110.120.1 netmask 255.255.255.0 up
......

ETH0:X//Virtual network interface, built on eth0, value range 0-255
192.168.6.XXX//Increase the IP alias, how much you want to add ~ ~

#ifconfig
After we set up our if look, the added IP is already in effect.

#ping 192.168.6.100
#ping 173.173.173.173
#ping 119.110.120.1
Then in this machine separately ping these several IP, all the way unimpeded ~ ~
* Note: When setting IP aliases, if the increase is the same network segment of LAN IP (such as 192.168.6.100), then in addition to the local area network other machines can ping this IP. If you add a strange-shaped IP, then only the native can ping, the latter is mainly used for native testing needs.

Third, the IP alias information of the reserved network card
When we sweat to increase the n IP, is preparing for the project test, suddenly ~ ~ [e-mail protected]#$%, in the blink of an eye on the branches, and finally call the computer to open a look, silly ~ ~ Just increase the IP has not???
It turns out that all IP aliases will be lost when the system restarts ... rpwt...xx$#%@
Based on the characteristics of Linux, so if you need to use IP alias for a long time, it is best to save the alias information, the general method has two, as follows:

1. Fill in the/etc/rc.local file with commands to add IP aliases
Will all be like this ifconfig eth0:0 192.168.6.100 netmask 255.255.255.0 up command line all fill in the Rc.local file, rc.local file is acting on the Linux boot Automatic execution command, detailed usage g or B, here is not detailed.
This method is most convenient, but not very reliable, and sometimes fails.

2. Manually write the IP alias of the NIC configuration file
All the network card configuration files are saved in the/etc/sysconfig/network-scripts directory, a network card corresponding to a configuration file, the file Ifcfg-eth0 is the local network card configuration file, We can write configuration files for other IP aliases by copying the format of this file.

#vi Ifcfg-eth0
Open the configuration file of the network card, copy all the fields inside
#vi ifcfg-eth0:0//Note that the configuration file is increased: ifcfg-eth0:0
Create the eth0:0 configuration file and paste the field you just copied into this profile, modify some of the information as described below, and save the exit after the modification is complete

The following is a partial description of the NIC configuration file, and other similar information is available by default:
###################################################################

# 3Com Corporation 3c905b 100BaseTX [Cyclone]//hardware model, negligible
device=eth0:0//Virtual network interface, optional
Onboot=yes//Activated at system startup
Bootproto=static//Use static IP address
ipaddr=192.168.6.100//IP alias of the virtual network interface, optionally
netmask=255.255.255.0//subnet mask, corresponding IP alias
gateway=192.168.6.1//gateway, corresponding IP alias
HWADDR=00:10:5A:5E:B1:E4//network card MAC address, no need to change
Userctl=no//whether to give non-root user device administrative rights

####################################################################

Configuration files for other IP aliases the same, pure physical activity ~ ~
This method is the most tedious, but also the most reliable, alas, life is so, never have the best of both worlds ~ ~


Iv. Clear IP aliases
#ifconfg eth0:0 Down
#ifconfg eth0:1 Down
#ifconfg Eth0:2 Down

The alias of the NIC configured under Linux is the configuration of the NIC sub-IP

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.