How to configure multiple IP addresses for Nic placement in CentOS

Source: Internet
Author: User

Today, let's review how to configure multiple IP addresses for a single Nic in linux. One is to use commands for direct configuration, and the other is to write the configuration file by yourself, now let's talk about it one by one.

1. Use commands for configuration

This is simple. First, check the IP address of the current machine. The command is as follows:

  1. ifconfig
  2. eth0 Link encap:Ethernet HWaddr 00:19:D1:24:2A:EC
  3. inet addr: Bcast: Mask:
  4. inet6 addr: fe80::219:d1ff:fe24:2aec/64 Scope:Link

We can see that the IP address of the current machine is 1.55, so we will configure a 1.56 (Be sure not to conflict with the address in the LAN), run the following command:

  1. ifconfig eth0:0 netmask
  2. ifconfig
  3. eth0 Link encap:Ethernet HWaddr 00:19:D1:24:2A:EC
  4. inet addr: Bcast: Mask:
  5. inet6 addr: fe80::219:d1ff:fe24:2aec/64 Scope:Link
  7. eth0:0 Link encap:Ethernet HWaddr 00:19:D1:24:2A:EC
  8. inet addr: Bcast: Mask:

The first line of command is to configure an IP address, and then use the ifconfig command to view the two IP addresses. Then ping the test to see if it is successful:

  1. ping
  2. PING ( bytes of data.
  3. 64 bytes from icmp_seq=1ttl=64time=0.045 ms
  4. 64 bytes from icmp_seq=2ttl=64time=0.045 ms
  5. 64 bytes from icmp_seq=3ttl=64time=0.043 ms
  6. ping
  7. PING ( bytes of data.
  8. 64 bytes from icmp_seq=1ttl=64time=0.030 ms
  9. 64 bytes from icmp_seq=2ttl=64time=0.022 ms
  10. 64 bytes from icmp_seq=3ttl=64time=0.022 ms
2. Use the configuration file for configuration

The nic ip configuration file is in/etc/sysconfig/network-scripts/, and the files are ehtx or ethx: x, respectively. Run the following command:

  1. cd/etc/sysconfig/network-scripts/
  2. cp ifcfg-eth0 ifcfg-eth0:1

In this way, we simply copy the configuration file of the current network. Then we open the copied file and change the IP address to the desired IP address, such as! Vi file, the content is as follows:

  1. DEVICE=eth0
  2. BOOTPROTO=none
  3. HWADDR=00:19:D1:24:2A:EC
  4. ONBOOT=yes
  5. DHCP_HOSTNAME=zhongqg.localdomain
  6. IPADDR=
  9. TYPE=Ethernet
  10. USERCTL=no
  11. IPV6INIT=no
  12. PEERDNS=yes

Then we only need to change the IPADDR to our IP address, and then save and exit and start the configuration file:

  1. ifup eth0:1

In either of these methods, we can easily configure multiple IP addresses in linux.

Related Article

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: 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.