How to bind multiple ip addresses to the same Nic in CentOS6

Source: Internet
Author: User

Before centos6.0, bind multiple ip addresses to the same Nic, you need to create a file similar to ifcfg-eth0: 0 to define the new ip address, and from centos6.0, it is easy to bind multiple IP addresses. Instead of creating a configuration file, you only need to modify the configuration file of the NIC.

Method 1, such as the ifcfg-em1, in which you can add such a few lines:

IPADDR2 = 192.168.2.101

NETMASK2 = 255.255.255.0

GATEWAY2 = 192.168.2.1

GATEWAY2 is optional. In practice, you do not need to configure multiple gateways.

To bind more ip addresses, you only need to add IP addresses and mask numbers in sequence, such as IPADDR3 and NETMASK3. Of course, the first ip address does not require the serial number 1.

Method 2: centos6.0 or earlier


To bind an IP address, you only need to change the file.
Nic files are in the directory:/etc/sysconfig/network-scripts
 
Query the current IP address:
Ifconfig:
Eth0 Link encap: Ethernet HWaddr 00: 50: 56: AC: 6B: 0F
Inet addr: 42.51.135.206 Bcast: 42.51.135.255 Mask: 255.255.255.0
Inet6 addr: fe80 :: 250: 56ff: fead: 6b0f/64 Scope: Link
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 374772 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 35165 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 fig: 1000
RX bytes: 28759089 (27.4 MiB) TX bytes: 4779278 (4.5 MiB)
 
There are files in the current directory:
Ifcfg-eth0
 
Create a file in the directory:
Ifcfg-eth0: 1
The content is as follows:
DEVICE = eth0: 1
IPADDR = 42.51.138.1
NETMASK = 255.255.255.0
HWADDR = 00: 50: 56: AC: 6B: 0F
NM_CONTROLLED = yes
ONBOOT = yes
BOOTPROTO = dhcp
TYPE = Ethernet
IPV6INIT = no
USERCTL = no
 
Ifcfg-eth0: 2
DEVICE = eth0: 2
IPADDR = 42.51.138.2
NETMASK = 255.255.255.0
HWADDR = 00: 50: 56: AC: 6B: 0F
NM_CONTROLLED = yes
ONBOOT = yes
BOOTPROTO = dhcp
TYPE = Ethernet
IPV6INIT = no
USERCTL = no
 
Ifcfg-eth0: 3
DEVICE = eth0: 3
IPADDR = 42.51.138.3
NETMASK = 255.255.255.0
HWADDR = 00: 50: 56: AC: 6B: 0F
NM_CONTROLLED = yes
ONBOOT = yes
BOOTPROTO = dhcp
TYPE = Ethernet
IPV6INIT = no
USERCTL = no
 
Restart Nic:
Service network restart

Method 3: manually bind a small number of IP addresses (here we use binding an IP address to eth0 as an example. If other network cards are used, modify the corresponding file name)


1. Copy the Nic configuration file for the ifcfg-eth0 and rename it to ifcfg-eth0: 0

[Root @ akinlau/] # cp/etc/sysconfig/network-scripts/ifcfg-eth0/etc/sysconfig/network-scripts/ifcfg-eth0: 0

2. Edit ifcfg-eth0: 0 file

[Root @ akinlau/] # vim/etc/sysconfig/network-scripts/ifcfg-eth0: 0

DEVICE = "eth0: 0 & Prime; // change to eth0: 0 here to be consistent with the file name
BOOTPROTO = "static" // The protocol is static and can be used with none
HWADDR = "00: 0C: 29: 6F: 62: A7 & Prime; // MAC address
ONBOOT = "yes" // enable this Nic upon startup
IPADDR = 192.168.1.3 // The newly bound IP address
NETMASK = 255.255.255.0 // subnet mask
GATEWAY = 192.168.1.1 // GATEWAY

Save and exit after modification, and enable this Nic

[Root @ akinlau/] # ifup eth0: 0

Note: Some people like to restart the network with service network restart in this step. In fact, this is not necessary. You only need to enable this Nic.

Then ping again. If the ping is successful, you can.

Method 4: automatically bind an IP segment or multiple IP segments (here, the eth0 is used as an example. If other network interfaces are used, modify the corresponding file name)


1. create a new ifcfg-eth0-range0 File (note that the file name here should not change the location of the range or write the wrong word, otherwise the bound IP will not take effect, if you have a few IP to bind to eth0, you can create a new ifcfg-eth0-range1, ifcfg-eth0-range2 and other files, but here you should note that the CLONENUM_START values defined in each range file cannot overlap, otherwise there will be problems. )

[Root @ akinlau/] #/etc/sysconfig/network-scripts/ifcfg-eth0-range0

# Write the following content

DEVICE = eth0 // the name of the NIC bound to the IP segment
ONBOOT = yes // enable this Nic at startup
BOOTPROTO = static // The protocol is static
IPADDR_START = 192.168.0.101 // start IP address of the CIDR block
IPADDR_END = 192.168.0.120 // end IP address of the network segment
NETMASK = 255.255.255.255.255 // subnet mask
CLONENUM_START = 0 // the starting position of the NIC alias. For example, 3 indicates eth0: 0, and the IP192.168.0.101 set by IPADDR_START is bound to eth0: 0, and so on.
NO_ALIASROUTING = yes // this parameter is used to ensure that data packets always pass in and out through eth0 without the Nic alias (such as eth0: 0). Setting this parameter can speed up the response of the route, therefore, we strongly recommend that you configure it.

After modification, save and exit, and then restart the network:

[Root @ akinlau/] # service network restart

Test whether the ping operation is successful.

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.