In Linux, you sometimes need to bind multiple IP addresses to a network card. This article describes the RedHat series (RedHat, Fedora Core, centos) and a method that is widely used in other Linux systems such as Gentoo.
1. How to bind multiple IP addresses to a single Nic In the RedHat Series
Suppose the NIC that needs to bind multiple IP addresses is eth0, Please create a file named ifcfg-eth0: 0 in the/etc/sysconfig/network-scripts directory,
|Device = "eth0: 0 ″
Ipaddr = "192.168.0.2 ″
Broadcast = "172.160.255 ″
Netmask = "255.255.255.0 ″
Onboot = "yes"
The device is the device name,
The IP address of the device,
Broadcast is a broadcast address,
Netmask is the subnet mask,
Onboot indicates Automatic startup when the system starts.
If you need to bind another IP address,
You only need to add the file name and the eth0: X in the device in the file.
Linux supports up to 255 IP aliases
2. It is widely used to bind multiple IP addresses to a single Nic.
|Ifconfig eth0: 1 192.168.0.3 broadcast 192.168.0.255 netmask 255.255.255.0
You can add the preceding command to the self-running Startup File. Under Gentoo, It is/etc/CONF. d/local. start, while some versions of Linux are/etc/rc. d/RC. local.
3. How to share a single IP address with multiple NICs
You can use multiple NICs to create a network card with the same IP address. This technology actually exists in Sun and Cisco, respectively known as trunking and etherchannel technology. In Linux, this technology is called bonding. Because bonding is included in kernel 2.4.x, you only need to select bonding driver support in network device options during compilation.
Then, recompile the core, restart the computer, and execute the following command:
Ifconfig eth0 down
Ifconfig eth1 down
Ifconfig bond0 IPaddress
Ifenslave bond0 eth0
Ifenslave bond0 eth1
Now the two NICs work like one, which can improve data transmission between cluster nodes.
You 'd better write these statements as a script, and then use/etc/rc. d/RC. local or/etc/CONF. d/local. start is called to take effect on the server.
Bonding is a good choice for Servers. When there is no Gigabit Nic, using two or three 100 m NICs as bonding can greatly increase the bandwidth between servers and switches. However, you need to set the two ports mapped to the same Virtual Interface on the vswitch to connect to the bonding Nic.