Ifconfig removing problems with virtual network Interfaces __ Network programming

Source: Internet
Author: User
Tags aliases

Turn from: http://blog.chinaunix.net/uid-24148050-id-3045244.html

Use the following command to start multiple IP aliases/sbin/ifconfig eth0:1 1.42.9.162 netmask 255.255.255.224/sbin/ifconfig eth0:2 1.42.9.163 netmask 255.255.255.224/sbin/ifconfig eth0:3 1.42.9.186 netmask 255.255.255.224/sbin/ifconfig eth0:4 1.42.9.182 netmask 255.255.255.224/sbin/ifconfig eth0:5 1.42.9.169 netmask 255.255.255.224/sbin/ifconfig eth0:6 1.42.9.168 netmask 255.255.255.224/sbin/ifconfig eth0:7 1.42.9.190 netmask 255.255.255.224/sbin/ifconfig eth0:8 1.42.9.183 netmask 255.255.255.224/sbin/ifconfig eth0:9 1.42.9.184 netmask 255.255.255.224/sbin/ifconfig eth0:10 1.42.9.185 netmask 255.255.255.224 then perform ifconfig eth0:1 Dwon Note that at this point, you will find that Ifconfig has all the IP aliases down .... But if you bring down the 2,3 ... That is, except 1 of the remaining IP alias, does not appear above the problem.

Using the Advanced Routing command of Iproute2 to set IP, the effect is the same. Set multiple IPs using the following command
IP addr Add 192.168.4.1/28 dev eth0 ip addr add 192.168.4.2/28 dev eth0 ip addr add 192.168.4.3/28 dev eth0 ip addr Add 192.168.4.4/28 Dev eth0

Use the following command
IP addr del 192.168.4.1/28 dev eth0
The rest of the IP is gone.

Analysis and Resolution:1. Relevant information multi-homing, IP aliasing, Primary address and secondary address concept discriminationHost ADDRESS:A unique address assigned to a communications device in a computer. If A computer has multiple communications devices (e.g., Ethernet cards or modems), each of these devices would have its OW N Unique address. This is means that a-host (computer or router) can be multi-homed, i.e., have multiple IP addresses.    This can also is artificially created by assigning different IP addresses to the same device (called IP aliasing). Add multiple IP addresses for the same physical network card in Linux, previously creating and maintaining IP alias via the ifconfig command, and creating and maintaining primary address and secondary in the new IPROUTE2 via IP addressing commands Address Multiple primary addresses and multiple secondary addresses can be configured on each interface. For a specific netmask (the netmask in the example is/24), there can be only one primary address.

Responding to many events and conditions in the routing code depends on whether the IP address is an primary address or an secondary address. Here are some examples: Primary addresses contribute to the entropy of the CPU this happens to run the code that applies the Configurat   Ion. When a primary address is deleted, all associated secondary addresses are also deleted.   However, you can configure an option through/proc to elevate the secondary address to the primary address when the current primary address is deleted. When the host selects the source IP address for locally generated traffic, only the primary address is considered.
2. SolutionsUse the IP addr Show command to view the status of the IP eth0:mtu 1500 qdisc pfifo_fast Qlen 1000 link/ether 00:0c:29:c8:9b:3c the BRD ff:ff:ff:ff:ff : FF inet 192.168.7.191/24 BRD 192.168.7.255 scope global eth0 inet 1.42.9.162/27 BRD 1.42.9.191 scope global eth0: 1 inet 1.42.9.163/27 BRD 1.42.9.191 Scope Global secondary eth0:2 inet 1.42.9.186/27 BRD 1.42.9.191 Scope Global S Econdary eth0:3 inet 1.42.9.182/27 BRD 1.42.9.191 scope Global Secondary Eth0:4
As you can see, the Red section indicates that the eth0:1 is a primary address with a mask of 27 segments, and when we delete this address, the following secondary address is deleted.
Set parameters:/sbin/sysctl net.ipv4.conf.eth0. Promote_secondaries=1 (Promotion of secondary IP address)

If This is enabled, and primary address of a interface gets deleted, an alias of the interface (secondary) would be Upgrad Ed to become primary.

The default is to purge all of the secondaries when you delete the primary setting reboot is still in effect: echo "Net.ipv4.conf.eth0.promote_seconda Ries=1 ">>/etc/sysctl.conf

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.