Single NIC in Linux system binds multiple IP addresses

Source: Internet
Author: User

Single NIC configuration single IP command

The code is as follows Copy Code

#ifconfig eth0 192.168.0.1 netmask 255.255.255.0 up Description: Up is to indicate immediate activation

Single NIC configuration multiple IP method is to use the command

If you are configuring multiple IP addresses for a single network adapter eth0, if you use the Ifconfig command, then the place where you need to change is eth0 only, eth0 to Eth0:x (x is 0-255 such as eth0:0 or eth0:1, etc.), eth0: X is called a virtual network interface and is built on top of the network interface.

The code is as follows Copy Code

#ifconfig eth0:0 192.168.0.1 netmask 255.255.255.0 up
#ifconfig eth0:1 192.168.0.2 netmask 255.255.255.0 up

The ping test passes, completes the single NIC configuration multiple IP function.

Note: The IP address will change back after the server restarts, so set the IP setting to activate automatically when you start.


add another article:

1. Configure using commands

This is very simple, first look at the current machine IP address, the following command:

The code is as follows Copy Code
#ifconfig
Eth0 Link encap:ethernet hwaddr 00:19:d1:24:2a:ec
inet addr:192.168.1.55 bcast:192.168.3.255 mask:255.255.252.0
Inet6 ADDR:FE80::219:D1FF:FE24:2AEC/64 Scope:link
Up broadcast RUNNING multicast mtu:1500 metric:1

Note that the red part of the computer, you can see our local IP address is 1.55, then we have to match a 1.56 (pay attention to the local area network with the address conflict OH), the use of the following command:

The code is as follows Copy Code

#ifconfig eth0:0 192.168.1.56 netmask 255.255.252.0
#ifconfig
eth0  Link encap:ethernet   hwaddr 00:19:d1:24:2a: ec 
 inet addr:192.168.1.55   bcast:192.168.3.255   Mask:255.255.252.0
  Inet6 addr:fe80::219:d1ff:fe24:2aec/64 scope:link
 up broadcast RUNNING multicast   MTU:1500    Metric:1

Eth0:0link encap:ethernet hwaddr 00:19:d1:24:2a:ec
inet addr:192.168.1.56 bcast:192.168.3.255 mask:255.255.252.0
Up broadcast RUNNING multicast mtu:1500 metric:1
#ping 192.168.1.56
PING 192.168.1.56 (192.168.1.56) bytes of data.
Bytes from 192.168.1.56:icmp_seq=1 ttl=64 time=0.045 ms
Bytes from 192.168.1.56:icmp_seq=2 ttl=64 time=0.045 ms
Bytes from 192.168.1.56:icmp_seq=3 ttl=64 time=0.043 ms
#ping 192.168.1.55
PING 192.168.1.55 (192.168.1.55) bytes of data.
Bytes from 192.168.1.55:icmp_seq=1 ttl=64 time=0.030 ms
Bytes from 192.168.1.55:icmp_seq=2 ttl=64 time=0.022 ms
Bytes from 192.168.1.55:icmp_seq=3 ttl=64 time=0.022 ms

This allows us to easily configure another IP address 1.56!

2. Configure using a configuration file

Network card IP configuration files under/etc/sysconfig/network-scripts/, files are ehtx or ethx:x, the following commands are executed:

The code is as follows Copy Code

#cd/etc/sysconfig/network-scripts/
#cp Ifcfg-eth0 ifcfg-eth0:1

So we simply copy a copy of the current network configuration file, and then we open the copied file, change the IP address of which we want the IP address, such as 192.168.1.57 can!

The code is as follows Copy Code

#vi ifcfg-eth0:1
Device=eth0
Bootproto=none
Hwaddr=00:19:d1:24:2a:ec
Onboot=yes
Dhcp_hostname=zhongqg.localdomain
ipaddr=192.168.1.55
netmask=255.255.252.0
gateway=192.168.0.1
Type=ethernet
Userctl=no
Ipv6init=no
Peerdns=yes

Then modify the red portion of it to 192.168.1.57, and then save the exit and start the configuration file!

  code is as follows copy code

#ifup eth0 : 1

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.