Configure the NIC ip alias in Linux

Source: Internet
Author: User
Article title: configure the NIC ip alias in Linux. Linux is a technology channel of the IT lab in China. Includes desktop applications, Linux system management, kernel research, embedded systems, open source, and other basic categories. what is ip alias?
In windows, multiple ip addresses are configured for one Nic.
In what scenarios can I add an ip alias to help?
Network deployment needs, multi-ip access tests, specific software requirements for multi-ip... and so on.

The following example describes how to use the ifconfig command to configure an ip alias for the NIC.
Environment: the newly purchased server, just installed with the RedHat AS4 operating system, has only one Nic and has no configuration.


1. 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 NIC
Netmask subnet mask 255.255.0 // subnet mask of the IP address, no need to explain
Up // indicates that the Eni is activated immediately.

# Ifconfig
If so, the static IP address is successfully set.




2. set the ip alias of the NIC
# 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 created on eth0, value range: 0-255
192.168.6.xxx // add an ip alias ~~

# Ifconfig
After setting, let's take a look. all the added ip addresses have taken effect.



# Ping 192.168.6.100
# Ping 173.173.173.173
# Ping 119.110.120.1
Then ping these ip addresses on the local machine separately to make sure the ip addresses are available ~~




* Note: When you set an ip alias, if you add an ip address in the same network segment as the LAN (for example, 192.168.6.100), you can ping the ip address from other machines except the local LAN. If a strange ip address is added, only the local machine can be pinged. The latter is mainly used for local testing.


3. retain the ip alias information of the NIC
When we were sweating and adding n ip addresses, we were preparing to perform a project test ~~ A power outage... xx @ # $ %. it's silly to have a call to open the computer ~~ The newly added ip addresses are all gone ???
After the system is restarted, all ip aliases will be lost... rpwt... xx $ #% @
Based on the linux feature, if you need to use an ip alias for a long time, it is best to save the alias information. There are two general methods:

1. enter the command for adding an ip alias in the/etc/rc. local file.
Fill in all the command lines for ifconfig eth0: 0 192.168.6.100 netmask 255.255.255.0 up to rc. go to the local file, rc. the local file is used to automatically execute commands when linux is started. For more information, see g or B.
This method is the most convenient, but unreliable, and sometimes fails.

2. manually compile the Nic configuration file for the ip alias
All Nic configuration files are saved in the/etc/sysconfig/network-scripts directory. one Nic corresponds to one configuration file,



The file ifcfg-eth0 is the configuration file of the local Nic, we can write the configuration file of other ip alias by following the format of this file.

# Vi ifcfg-eth0
Open the Nic configuration file and copy all the fields.
# Vi ifcfg-eth0: 0
Create the eth0: 0 configuration file, paste the copied field to this configuration file, and modify some information as described below. save and exit after modification.

Some information about the Nic configuration file is described below. other similar information can be used by default:
######################################## ######################################

# 3Com Corporation 3c905B 100 BaseTX [Cyclone] // hardware model, not counted
DEVICE = eth0: 0 // virtual network interface, random
ONBOOT = yes // activated at system startup
BOOTPROTO = static // use a static IP address
IPADDR = 192.168.6.100 // The ip alias of the virtual network interface.
NETMASK = 255.255.255.0 // subnet mask, corresponding to ip alias
GATEWAY = 192.168.6.1 // GATEWAY, corresponding ip alias
HWADDR = 00: 10: 5A: 5E: B1: E4 // Nic MAC address, no need to change
USERCTL = no // whether to grant non-root user device management permissions

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

Configuration files for other ip aliases are similar and are purely physical ~~
This method is the most cumbersome, but the most reliable. Alas, this is the way we live, and we will never be able to have the best of both worlds ~~


4. clear ip alias
# Ifconfg eth0: 0 down
# Ifconfg eth0: 1 down
# Ifconfg eth0: 2 down
......

It's easy... no need to explain it.

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.