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:192.168.1.55 Bcast:192.168.3.255 Mask:255.255.252.0
  4. inet6 addr: fe80::219:d1ff:fe24:2aec/64 Scope:Link
  5. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

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 192.168.1.56 netmask 255.255.252.0
  2. ifconfig
  3. eth0 Link encap:Ethernet HWaddr 00:19:D1:24:2A:EC
  4. inet addr:192.168.1.55 Bcast:192.168.3.255 Mask:255.255.252.0
  5. inet6 addr: fe80::219:d1ff:fe24:2aec/64 Scope:Link
  6. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  7. eth0:0 Link encap:Ethernet HWaddr 00:19:D1:24:2A:EC
  8. inet addr:192.168.1.56 Bcast:192.168.3.255 Mask:255.255.252.0
  9. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

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 192.168.1.56
  2. PING 192.168.1.56 (192.168.1.56)56(84) bytes of data.
  3. 64 bytes from 192.168.1.56: icmp_seq=1ttl=64time=0.045 ms
  4. 64 bytes from 192.168.1.56: icmp_seq=2ttl=64time=0.045 ms
  5. 64 bytes from 192.168.1.56: icmp_seq=3ttl=64time=0.043 ms
  6. ping 192.168.1.55
  7. PING 192.168.1.55 (192.168.1.55)56(84) bytes of data.
  8. 64 bytes from 192.168.1.55: icmp_seq=1ttl=64time=0.030 ms
  9. 64 bytes from 192.168.1.55: icmp_seq=2ttl=64time=0.022 ms
  10. 64 bytes from 192.168.1.55: 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 192.168.1.57! 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=192.168.1.55
  7. NETMASK=255.255.252.0
  8. GATEWAY=192.168.0.1
  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.


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.