Linux system single NIC binds multiple IP addresses

Source: Internet
Author: User
Tags nameserver

Linux system single NIC binds multiple IP addresses

Description

Single NIC binding two IP addresses, telecommunications and Unicom, the purpose: is to be used when the telecommunications fault unicom normal use.

System

IP Address

Subnet mask

Gateway

CentOS 6.3_64bit

eth0:116.18.176.19

255.255.255.0

192.168.1.1

eth0:0:172.188.174.20

255.255.255.0

192.168.1.1

...

...

...

1, Linux network device storage path is/etc/sysconfig/network-scripts into the directory:

[Email protected] ~]# cd/etc/sysconfig/network-scripts/

[email protected] network-scripts]# LL

Total 196

-rw-r--r--. 1 root root 212 Mar 22:15 Ifcfg-eth0

 

2. Create a ifcfg-eth0:x on the/etc/sysconfig/network-scripts directory (x can be 0,1,2 ...).
For the sake of simplicity we can speak Ifcfg-eth0, duplicate a copy named ifcfg-eth0:0, and then modify the configuration file.

[email protected] network-scripts]# CP ifcfg-eth0.0 ifcfg-eth0:0

  

3. Edit ifcfg-eth0:0 Virtual IP

[Email protected] network-scripts]# vim ifcfg-eth0:0

Device= "eth0:0"//Modify the name of the device

bootproto= "Static"//[none|static|bootp|dhcp] (No protocol at boot | Static split
with | BOOTP protocol | DHCP protocol)

ipaddr=172.188.174.20//Modify IP Address

netmask=255.255.255.0//Subnet mask

gateway=192.168.1.1//Gateway

broadcast= ' 192.168.1.255 '//broadcast address

Hwaddr= "00:0c:29:c9:6d:11"//mac address

Nm_controlled= "Yes"

onboot= "yes"//boot Activation

: Wq

If you need to bind more than one IP address, simply add the file name and the eth0:x in the device in the file.

4. Configure network card DNS (Telecom and Unicom)

The configuration file is below/etc/resolv.conf.

Vim/etc/resolv.conf

NameServer 202.109.14.5 #主DNS

NameServer 219.141.136.10 #次DNS

Save the exit, and then run the following command to restart the virtual network card.

[[Email protected] network-scripts]# service network restart or/etc/init.d/network restart

5, we come to see if our virtual network card is activated, with Ifconfig, that is, the following.

[Email protected]calhost network-scripts]# ifconfig

Eth0 Link encap:ethernet HWaddr 00:0c:29:c9:6d:18

inet addr:116.18.176.19 bcast:192.168.1.255 mask:255.255.255.0

Inet6 ADDR:FE80::20C:29FF:FEC9:6D18/64 Scope:link

Up broadcast RUNNING multicast mtu:1500 metric:1

RX packets:1622 errors:0 dropped:0 overruns:0 frame:0

TX packets:702 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:170181 (166.1 KiB) TX bytes:122357 (119.4 KiB)

eth0:0 Link encap:ethernet HWaddr 00:0c:29:c9:6d:18

inet addr:172.188.174.20 bcast:192.168.1.255 mask:255.255.255.0

Up broadcast RUNNING multicast mtu:1500 metric:1

Lo Link encap:local Loopback

inet addr:127.0.0.1 mask:255.0.0.0

Inet6 addr::: 1/128 scope:host

Up LOOPBACK RUNNING mtu:16436 metric:1

RX packets:0 errors:0 dropped:0 overruns:0 frame:0

TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:0  (0.0 b) TX bytes:0 (0.0 b)

  

6, the following test, another computer using ping to test

C:\users\administrator>ping 116.18.176.19

Pinging 116.18.176.19 with 32 bytes of data:

Reply from 116.18.176.19: Byte =32 time =16ms ttl=64

Reply from 116.18.176.19: Byte =32 time =8ms ttl=255

Reply from 116.18.176.19: Byte =32 time =8ms ttl=255

Reply from 116.18.176.19: Byte =32 time =8ms ttl=255

C:\users\administrator>ping 172.188.174.20

Pinging 172.188.174.20 with 32 bytes of data:

Reply from 172.188.174.20: Byte =32 time =16ms ttl=64

Reply from 172.188.174.20: Byte =32 time =8ms ttl=255

Reply from 172.188.174.20: Byte =32 time =8ms ttl=255

Reply from 172.188.174.20: Byte =32 time =8ms ttl=255

Test success!

7, test when eth0 network interrupt eth0:0 is normal use

C:\users\administrator>ping 116.18.176.19

Pinging 116.18.176.19 with 32 bytes of data:

The request timed out.

The request timed out.

The request timed out.

Reply from 192.168.1.2: Unable to access target host.

C:\users\administrator>ping 172.188.174.20

Pinging 172.188.174.20 with 32 bytes of data:

Reply from 172.188.174.20: Byte =32 time =16ms ttl=64

Reply from 172.188.174.20: Byte =32 time =8ms ttl=255

Reply from 172.188.174.20: Byte =32 time =8ms ttl=255

Reply from 172.188.174.20: Byte =32 time =8ms ttl=255

Test success!

      • This article is from: Linux Learning Network

Linux system single NIC binds 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.