Linux a NIC to add multiple Ip__linux

Source: Internet
Author: User
Under the Linux system, the first network card is called Eth0, the second network card is called eth1, here we give the first network card to set up multiple IP, also that is to add multiple subnets, such as eth0:0, eth1:1 This network interface, Linux can support up to 255 IP subnet cards.
First, use the command to temporarily add IP
1) Check the eth0 configuration:
Ifconfig
Eth0 Link encap:ethernet hwaddr 00:0c:29:0c:d1:64
inet addr:192.168.36.189 bcast:192.168.36.255 mask:255.255.255.0
Inet6 ADDR:FE80::20C:29FF:FE0C:D164/64 Scope:link
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:27537 errors:0 dropped:0 overruns:0 frame:0
TX packets:15994 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:28935981 (27.5 MiB) TX bytes:1430497 (1.3 MiB)
Interrupt:19 Base address:0x2024
2) Add the subnet card
Ifconfig eth0:0 172.16.1.100 netmask 255.255.255.255 broadcast 172.16.1.255 up
Ifconfig eth0:1 192.168.36.110 netmask 255.255.255.255 broadcast up
View: Ifconfig
Eth0 Link encap:ethernet hwaddr 00:0c:29:0c:d1:64
inet addr:192.168.36.189 bcast:192.168.36.255 mask:255.255.255.0
Inet6 ADDR:FE80::20C:29FF:FE0C:D164/64 Scope:link
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:28286 errors:0 dropped:0 overruns:0 frame:0
TX packets:16398 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:28998261 (27.6 MiB) TX bytes:1493145 (1.4 MiB)
Interrupt:19 Base address:0x2024
eth0:0 Link encap:ethernet hwaddr 00:0c:29:0c:d1:64
inet addr:172.16.1.100 bcast:172.16.1.255 mask:255.255.255.255
Up broadcast RUNNING multicast mtu:1500 metric:1
Interrupt:19 Base address:0x2024
Eth0:1 Link encap:ethernet hwaddr 00:0c:29:0c:d1:64
inet addr:192.168.36.110 bcast:192.168.36.255 mask:255.255.255.255
Up broadcast RUNNING multicast mtu:1500 metric:1
Interrupt:19 Base address:0x2024
Description and Attention:
1: Must use up to start, let this IP take effect.
2: This method is only temporary, if reboot, then all will disappear

3: When setting IP alias, if the increase is the same network segment with the LAN IP (such as 192.168.36.110), then in addition to the local LAN other machines can ping this IP. If the additional network segment of the IP, then only the local machine can ping it only (but can be set by a multiple network segment IP, you can access), the latter is mainly used for native testing needs.

If the configuration of different network segments, reference: In Linux to configure multiple network segment IP if no longer need this IP address, use Ifconfig ${dev_name} down can use the new binding IP address offline. Now put the eth0:1 that you just tied up:
[root@localhost]# ifconfig eth0:1 down
Two, the above method adds IP, if the machine restarts, the configuration will be lost, we can through the following 2 ways to retain the IP card.
1 Add IP commands to the/etc/rc.local file
Going to be all like this ifconfig eth0:0 192.168.36.110 netmask 255.255.255.0 up of the command line to fill in the Rc.local file, rc.local file is the role of Linux boot Automatic command, the detailed use of G or B, here do not specify. This method is the most convenient, but not very reliable, sometimes failure.
2) manually write IP card configuration file
All network card configuration files are saved in the/etc/sysconfig/network-scripts directory, a network adapter corresponding to a configuration file, such as:
[Root@slave-b opt]# ls/etc/sysconfig/network-scripts/
Ifcfg-eth0 IFDOWN-BNEP Ifdown-ipv6 ifdown-ppp ifdown-tunnel ifup-bnep ifup-ipv6 ifup-plusb ifup-routes ifup-wi Reless network-functions
Ifcfg-lo ifdown-eth ifdown-isdn ifdown-routes ifup ifup-eth ifup-isdn ifup-post ifup-sit Init.ip V6-global Network-functions-ipv6
Ifdown ifdown-ippp ifdown-post ifdown-sit ifup-aliases ifup-ippp ifup-plip ifup-ppp ifup-tunnel net.hot Plug
The file Ifcfg-eth0 is the configuration file for the native network card, and we can write other IP profiles in the format of this file.
#vi Ifcfg-eth0
Open the network card configuration file, copy all the fields inside
#vi ifcfg-eth0:0
Create a eth0:0 configuration file and paste the fields you just copied into this profile, modify some of the information as described below, and then save the exit after the modification is complete
The following is a partial description of the NIC configuration file and other similar information by default:
##############################################################################
device=eth0:0//Virtual network interface, random
Onboot=yes//System activated at startup
Bootproto=static//using static IP address
ipaddr=192.168.36.100//IP alias for this virtual network interface, random
netmask=255.255.255.0//subnet mask, corresponding IP alias
gateway=192.168.36.1//gateway, corresponding IP alias
HWADDR=00:10:5A:5E:B1:E4//Nic MAC address, no change required
Userctl=no//whether to give non-root user device administrative rights
##############################################################################
The configuration completes the Reboot network card:
Service Network restart

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.