| What is an 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:
Multi-VLAN multiple IP 1. Load 8021q Modprobe 8021q 2. Vconfig Add eth0 2 3. Configure IP and Mac Ipconfig–s eth0.2 192.168.42.129 broadcast 192.168.42.0 netmask up --------------BingIP.h--------------------- #include <stdlib.h> #include <stdio.h> int main () { int i=-1; Char *p= "vconfig add eth0 254"; I=system (P); printf ("%d", I); return 0; }
----------------addip.sh-------------- #! /bin/sh Modprobe 8021q i=2 J=1 k=131 while (($j!=0)) && (($i <120)) Todo Vconfig add eth0 $i 2>/dev/null J=$? i=$ (($i + 1)) k=$ (($k + 1)) Done i=$ (($i-1)) Ifconfig eth0. $i 192.168.42. $k Broadcast 192.168.42.0 netmask 255.255.255.0 -----------------delip.sh----------------- For ((i=1;i<120;i++)) Todo Vconfig rem eth0. $i 2>/dev/null Done
Multiple network adapters /etc/sysconfig/network-scripts/eth0 Add eth1 file, file contents as follows Static IP: Device=eth1 Onboot=yes Bootproto=static ipaddr=192.168.0.18 netmask=255.255.255.0 gateway=192.168.0.1 Device=eth0 Bootproto=dhcp dhcpclass= Hwaddr=00:0c:29:ed:8d:f1 Onboot=yes Run: /etc/init.d/network Reload Dynamic IP file Ifcfg-eth0 is the configuration file of the native network card, we can write the configuration file of other IP aliases by imitating the format of this file.
#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
|