Linux next NIC set multiple IP addresses

Source: Internet
Author: User

Whether it is in the actual production of the bad, or in peacetime practice, a network card set up multiple IP addresses is very common, but also very useful.


We set multiple IP addresses on a network card with the centos6.8 system as a column.


1>. Setting multiple IP addresses for a network card This feature may be affected by the NetworkManager service, first shutting down the NetworkManager service, and shutting down the boot from startup.

[Email protected] network-scripts]# service NetworkManager stopstopping NetworkManager daemon: [OK] [Email protected] network-scripts]# Chkconfig NetworkManager off

2>. View the IP address of the current system and the device name of the network card.

[Email protected] network-scripts]# ifconfig

Eth0      link encap:ethernet  hwaddr 00:0c:29:b3:32:cc             inet addr:192.168.203.138   Bcast:192.168.203.255  Mask:255.255.255.0           inet6 addr: fe80::20c:29ff:feb3:32cc/64 Scope:Link           UP BROADCAST RUNNING MULTICAST  MTU:1500   metric:1          rx packets:3964 errors:0  dropped:0 overruns:0 frame:0          tx  packets:1193 errors:0 dropped:0 overruns:0 carrier:0           collisions:0 txqueuelen:1000            rx bytes:328092&nbSP; (320.4 kib)   TX bytes:167348  (163.4 kib) eth1       Link encap:Ethernet  HWaddr 00:0C:29:B3:32:D6             inet addr:192.168.203.131  Bcast:192.168.203.255   mask:255.255.255.0          inet6 addr: fe80 ::20c:29ff:feb3:32d6/64 scope:link          up  broadcast running multicast  mtu:1500  metric:1           rx packets:4083 errors:0 dropped:0 overruns:0 frame:0           tx packets:626 errors:0 dropped:0  overruns:0 carrier:0          collisions:0  txqueuelen:1000           rx bytes:323667  (316.0 KiB)   TX  bytes:92256  (90.0 kib)

Apparently, there are two NICs on the machine, one named Eth0 and the other named Eth1.


3>.eth0 network card on the original basis, and then add an IP address.

Modifying a configuration file ifcfg-eth0:1

[Email protected] network-scripts]# vim Ifcfg-eth0:1[[email protected] network-scripts]# cat Ifcfg-eth0:1device=eth0 : 1hwaddr=00:0c:29:b3:32:cctype=ethernetuuid=a7f94e4f-1f87-439f-a044-9888cc8ddc7conboot=yesnm_controlled= yesbootproto=staticipaddr=192.168.203.11netmask=255.255.255.0gateway=192.168.203.2dns1=192.168.203.2


4>. Restart Network Service

[[email protected] network-scripts]# service network restartshutting down  interface eth0:                               [  ok   ]Shutting down loopback interface:                           [   OK  ]Bringing up loopback interface:                              [  OK  ]Bringing up interface eth0:   Determining ip information for eth0... done. determining if ip address 192.168.203.11 is already in use for device eth0...                                                              [   OK  ]


5>. View System IP Address

[[email protected] network-scripts]# ifconfigeth0      link  encap:ethernet  hwaddr 00:0c:29:b3:32:cc             inet addr:192.168.203.138  bcast:192.168.203.255  mask : 255.255.255.0          inet6 addr: fe80::20c:29ff : Feb3:32cc/64 scope:link          up broadcast  RUNNING MULTICAST  MTU:1500  Metric:1           RX packets:5027 errors:0 dropped:0 overruns:0 frame:0           TX packets:1536 errors:0 dropped:0  overruns:0 carrier:0          collisions:0  txqueuelen:1000           rx bytes:418869  (409.0 kib)   TX bytes :224202  (218.9 kib) eth0:1    link encap:ethernet  hwaddr  00:0c:29:b3:32:cc            inet addr :192.168.203.11  bcast:192.168.203.255  mask:255.255.255.0           UP BROADCAST RUNNING MULTICAST  MTU:1500   Metric:1

Eth0 The second IP address setting was successful.


How to bind two IP addresses to the NIC, one of which is assigned automatically, and the other is statically assigned.

No matter how many addresses are bound on a single network card, but only one dynamic address can bind dynamically, and the dynamically assigned address must be the primary network configuration file, not the alias profile. The alias configuration file must be statically assigned an IP address.


1>. We first set the alias network profile to Dynamic (DHCP) and assign the IP address, while the primary network profile is set to a static IP address.

[email protected] network-scripts]# cat ifcfg-eth0device=eth0hwaddr=00:0c:29:b3:32:cctype=ethernetuuid= a7f94e4f-1f87-439f-a044-9888cc8ddc7conboot=yesnm_controlled=yesbootproto=staticipaddr=192.168.203.11netmask= 255.255.255.0gateway=192.168.203.2dns1=192.168.203.2[[email protected] network-scripts]# cat ifcfg-eth0:1DEVICE= Eth0:1hwaddr=00:0c:29:b3:32:cctype=ethernetuuid=a7f94e4f-1f87-439f-a044-9888cc8ddc7conboot=yesnm_controlled= Yesbootproto=dhcp


2>. Restart Network Service

[[email protected] network-scripts]# service network restartshutting down  interface eth0:                               [  ok   ]Shutting down loopback interface:                           [   OK  ]Bringing up loopback interface:                              [  OK  ]Bringing up interface eth0:   Determining if ip address 192.168.203.11 is already in use for  device eth0...errOr in ifcfg-eth0:1: didn ' t specify device or ipaddr                                                               [  OK  ]


3>. To view the assigned IP address of the eth0

[Email protected] network-scripts]# ifconfig

Eth0      link encap:ethernet  hwaddr 00:0c:29:b3:32:cc             inet addr:192.168.203.11   Bcast:192.168.203.255  Mask:255.255.255.0           inet6 addr: fe80::20c:29ff:feb3:32cc/64 Scope:Link           UP BROADCAST RUNNING MULTICAST  MTU:1500   metric:1          rx packets:6408 errors:0  dropped:0 overruns:0 frame:0          tx  packets:2024 errors:0 dropped:0 overruns:0 carrier:0           collisions:0 txqueuelen:1000            rx bytes:535222  (522.6 kib)   TX bytes:298666  (291.6 kib) eth1       Link encap:Ethernet  HWaddr 00:0C:29:B3:32:D6             inet addr:192.168.203.131  Bcast:192.168.203.255   mask:255.255.255.0          inet6 addr: fe80 ::20c:29ff:feb3:32d6/64 scope:link          up  broadcast running multicast  mtu:1500  metric:1           rx packets:5589 errors:0 dropped:0 overruns:0 frame:0           tx packets:656 errors:0 dropped:0  overruns:0 carrier:0          collisions:0  txqueuelen:1000           RX bytes:438975  (428.6 kib)   TX  bytes:97234  (94.9 kib)

It is clear that the Eth0 alias network configuration file is not effective.


4>. The Eth0 Master profile is then modified to obtain the IP address dynamically, and the alias profile is modified to a statically assigned IP address

[email protected] network-scripts]# cat ifcfg-eth0device=eth0hwaddr=00:0c:29:b3:32:cctype=ethernetuuid= A7f94e4f-1f87-439f-a044-9888cc8ddc7conboot=yesnm_controlled=yesbootproto=dhcp[[email protected] network-scripts] # Cat Ifcfg-eth0:1device=eth0:1hwaddr=00:0c:29:b3:32:cctype=ethernetuuid= a7f94e4f-1f87-439f-a044-9888cc8ddc7conboot=yesnm_controlled=yesbootproto=staticipaddr=192.168.203.10prefix= 24gateway=192.168.203.2


5>. Restart Network Service

[[email protected] network-scripts]# service network restartshutting down  interface eth0:                               [  ok   ]Shutting down loopback interface:                           [   OK  ]Bringing up loopback interface:                              [  OK  ]Bringing up interface eth0:   Determining ip information for eth0... done. determining if ip address 192.168.203.10 is already in use for device eth0...                                                              [   OK  ]

6>. View IP Address

[[email protected] network-scripts]# ifconfigeth0      link  encap:ethernet  hwaddr 00:0c:29:b3:32:cc             inet addr:192.168.203.138  bcast:192.168.203.255  mask : 255.255.255.0          inet6 addr: fe80::20c:29ff : Feb3:32cc/64 scope:link          up broadcast  RUNNING MULTICAST  MTU:1500  Metric:1           RX packets:7840 errors:0 dropped:0 overruns:0 frame:0           TX packets:2479 errors:0 dropped:0  overruns:0 carrier:0          collisions:0  txqueuelen:1000           rx bytes:659719  (644.2 kib)   TX bytes :369320  (360.6 kib) eth0:1    link encap:ethernet  hwaddr  00:0c:29:b3:32:cc            inet addr :192.168.203.10  bcast:192.168.203.255  mask:255.255.255.0           UP BROADCAST RUNNING MULTICAST  MTU:1500   Metric:1

The second IP address of the eth0 was modified successfully.

Linux next NIC set multiple IP addresses

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.