IP alias and its application

Source: Internet
Author: User
Tags aliases
Configure NIC IP alias under Linux

What is an IP alias (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.
Environment: Newly purchased server, just installed Redhat AS4 operating system, only a network card and clean did not make any configuration.

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.

#cp Ifcfg-eth0 ifcfg-eth0:0
Make a copy of Ifcfg-eth0
#vi ifcfg-eth0:0
Follow the instructions below to modify some of the information, save the exit after the modification is completed

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

......

V. IP aliases and subordinate IP addresses (secondary IP address)

Secondary IP address and IP alias are different concepts, first ask Google,google did not give me a good answer. Had to grope for their own, so currently can only get some of the following concepts:

IP alias and secondary IP address are two different implementations for adding multiple IP addresses to the same physical network card in a Linux system.

IP alias is created and maintained by the Ifconfig program, while secondary IP address is created and maintained by an IP program. The Scondary IP address created by IP addr Add cannot be seen in ifconfig-a, in turn, the ethx:y created by Ifconfig can be seen in IP addr show.

IP alias is described above, so talk about how secondary IP address creates

[Root@mlsx autostart]# Ifconfig
eth1 Link encap:ethernet hwaddr 00:13:77:00:7c:c6
inet addr:192.168.0.100 bcast:192.168.0.255 mask:255.255.255.0
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:163438 errors:2515 dropped:0 overruns:0 frame:2515
TX packets:165217 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:96792997 (92.3 MiB) TX bytes:16356841 (15.5 MiB)

Lo Link encap:local Loopback
inet addr:127.0.0.1 mask:255.0.0.0
Up loopback RUNNING mtu:16436 metric:1
RX packets:561 errors:0 dropped:0 overruns:0 frame:0
TX packets:561 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:119798 (116.9 KiB) TX bytes:119798 (116.9 KiB)
Eth0 was ifconfig eth0 down with me.

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.