Linux Next network adapter configuration multiple IP "virtual IP"

Source: Internet
Author: User
Tags aliases
Linux Configure network adapter IP alias is what IP alias.
In the words of Windows, it is to configure multiple IP for a network card.
Where to add IP aliases can be useful.
Network requirements, multiple IP access testing, specific software needs for multiple IP ... and so on.

Here are a few examples of how to use the Ifconfig command to configure an IP alias for a network adapter.
First, configure a static IP address for the server network card
#ifconfig eth0 192.168.6.99 netmask 255.255.255.0 up

Eth0//Machine's first network card, 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 that the NIC is activated immediately

#ifconfig
If, as shown in the diagram, 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, set up on the eth0, take a value range of 0-255
192.168.6.XXX//Add IP alias, add as much as you want ~ ~

#ifconfig
Set up if we look at it, as shown in the figure, the increased IP has been in effect



#ping 192.168.6.100
#ping 173.173.173.173
#ping 119.110.120.1

And then in this machine ping these several IP, as shown in the road smooth ~ ~





* Note: When setting IP aliases, if the increase is the same network segment with the LAN IP (such as 192.168.6.100), then in addition to the local LAN other machines can ping this IP. If the addition of strange-looking IP, then only the local machine can ping, the latter is mainly used for native testing needs.


Third, the retention of IP alias information card
When we sweat the increase of n IP, is ready to do the project test, suddenly ~ ~ Power outage ... xx@#$%, the moon on the branches, not easy to call the computer to open a look, silly ~ ~ Just increased the IP all gone ...
It turns out that when the system reboots, all IP aliases will be lost ... 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, there are two general methods, as follows:

1. Fill in the/etc/rc.local file with the command to add IP alias
Going to be all like this ifconfig eth0:0 192.168.6.100 netmask 255.255.255.0 up of the command line to fill in the Rc.local file, rc.local file is the role of Linux boot Automatic command, the detailed use of G or B, here do not specify.
This method is the most convenient, but not very reliable, sometimes failure.

2. The network card configuration file that writes IP alias manually
All network card configuration files are saved in the/etc/sysconfig/network-scripts directory, a network adapter corresponding to a configuration file, as shown:




The file Ifcfg-eth0 is the configuration file for the native network card, and we can write the configuration file of other IP aliases by imitating the file format.

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

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

# 3Com Corporation 3c905b 100BaseTX [Cyclone]//hardware model, negligible
device=eth0:0//Virtual network interface, random
Onboot=yes//System activated at startup
Bootproto=static//using static IP address
ipaddr=192.168.6.100//IP alias for this virtual network interface, random
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//Nic MAC address, no change required
Userctl=no//whether to give non-root user device administrative rights

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

Other IP alias profiles are similar, pure physical activity ~ ~
This method is the most cumbersome, but it is the most reliable, alas, life is like this, never have the best of both worlds ~ ~


Four, clear IP alias
#ifconfg eth0:0 Down
#ifconfg eth0:1 Down
#ifconfg Eth0:2 Down
......

It's simple ... No more explanations.

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.