Introduction to Linux-eth0 eth0:1 and eth0.1 relationships, Ifconfig, and virtual IP implementations

Source: Internet
Author: User



The relationship between eth0 eth0:1 and eth0.1 corresponds to the relationship between the physical network card, the sub-network card, and the virtual VLAN NIC:
Physical network card : Physical network card here refers to the actual network interface device on the server, here my server on the dual network card, in the system to see the 2 physical network card corresponding to the eth0 and eth1 the two network interfaces.

Sub -Network card: Sub-network card is not the actual network interface device, but can be used as a network interface in the system, such as ETH0:1, eth1:2 this network interface. They must depend on the physical network card, although the network interface with the physical network card can exist in the system and use different IP addresses, but also have their own network interface configuration files. However, when the dependent physical network card is not enabled (down state) These sub-cards will not work together.

virtual VLAN NIC : These virtual VLAN NICs are not actually network interface devices or can appear as network interfaces in the system, but unlike sub-NICs, they do not have their own configuration files. They are simply VLAN virtual NICs that are generated by adding a physical network to different VLANs. If a physical network card is added to multiple VLANs through the Vconfig command, there will be multiple VLAN virtual network cards, and their information and associated VLAN information are stored in the/proc/net/vlan/config temporary file. Without the configuration file alone. Their network interface name is the name eth0.1, eth1.2.



Note: When you need to enable VLAN virtual network card operation, the associated physical NIC network interface must not have the IP address configuration information, and these primary physical network card sub-cards must not be enabled and must not have IP address configuration information. The conclusion that I see on the internet is inaccurate according to my actual test results, the physical NIC itself can bind the IP, and give the Eigen VLAN the function of the communication gateway, but it must be under 802.1q.






/sbin/ifconfig Tools to view, configure, enable, or disable network interface (NIC)
Ifconfig is a tool used to view, configure, enable, or disable a network interface, which is extremely common. For example, we can use this tool to configure the network card IP address, MAC address, mask, broadcast address and so on. It is worth saying that you use Ifconfig to specify the IP address for the network adapter, which is only used for debugging networks, and does not change the system configuration file on the NIC. If you want to fix the IP address of the network interface, there are currently three methods: one is to modify the IP address through each release and version-specific tool, and the other is to modify the configuration file of the network interface directly, and the third is to modify the specific file and add the ifconfig instruction to specify the IP address of the NIC. For example, in Redhat or Fedora, the name of the Ifconfig is written into the/etc/rc.d/rc.local file;



/etc/sysconfig/network
/etc/sysconfig/network-scripts/ifcfg-eth0



ifconfig Configuring the Network interface Syntax:
Ifconfig Network port IP address HW MAC address netmask Mask address broadcast broadcast address [Up/down]

ifconfig common usage:

    • Ifconfig: View the host activation status of the network interface situation; in the output: Lo is the return bad address of the host, Eth0 represents the first Nic, where HWaddr represents the physical address (MAC address) of the network card, inet addr is used to represent the IP address of the network card, Bcast represents the broadcast Address, mask represents the mask address
    • Ifconfig-a: View the status of all host (including non-active) network interfaces
    • Ifconfig eth0: Viewing the status of a specific network interface
    • Ifconfig eth0 down = ifup eth0: If the eth0 is active, terminate it. This command is equivalent to Ifdown eth0;
    • Ifconfig eth0 up = Ifdown eth0: activates eth0; This command is equivalent to Ifup eth0
    • Ifconfig eth0 192.168.1.99 broadcast 192.168.1.255 netmask 255.255.255.0: Configure the Eth0 IP address, broadcast address, and netmask;
    • Ifconfig eth0 192.168.1.99 broadcast 192.168.1.255 netmask 255.255.255.0 up: Configure IP address, netmask, broadcast address while activating NIC Eth0
    • Ifconfig eth1 HW ether 00:11:00:00:11:22: Sets the physical address (MAC address) of the network card. Where HW is followed by the network interface type, ether means Ethernet, but also support ax25, ARCnet, Netrom, etc., see Man ifconfig for details;





Virtual IP technology in high-availability domain like database SQL Server, Web server and other scenarios under the use of many, very confused how it is implemented, by chance, found a way to implement virtual IP. its principle is that the same physical network card, can have more than one IP address, as for the virtual network card, can also be used in this way to have multiple IP  . That is, the host of the external database server, in addition to a real IP there is a virtual IP, using any one of these two IP can be connected to this host, all projects in the database link is a configuration of this virtual IP, when the server fails to provide services to the outside, Dynamically switch this virtual IP to an alternate host .



The implementation of the principle is mainly by TCP/ip arp protocol. Because the IP address is just a logical address, in the Ethernet MAC address is really used for data transmission physical address, each host has an ARP cache, store the same network IP address and the corresponding relationship between the MAC address, When the host in the Ethernet sends the data, the MAC address of the destination IP is queried from this cache, and the data is sent to the MAC address. This cache is automatically maintained by the operating system. This is the key to the entire implementation.



The alias is referenced at eth0 and the subnet mask is set
Ifconfig eth0:0 166.111.69.100 netmask 255.255.255.0 up



View NIC information at this time


eth0 Link encap:Ethernet HWaddr 08:00:27:64:59:11 
          inet addr:166.111.69.17 Bcast:166.111.69.255 Mask:255.255.255.0
          inet6 addr: 2402:f000:1:4412:a00:27ff:fe64:5911/64 Scope:Global
          inet6 addr: fe80::a00:27ff:fe64:5911/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
          RX packets:597673 errors:0 dropped:0 overruns:0 frame:0
          TX packets:215472 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:67285933 (67.2 MB) TX bytes:22782158 (22.7 MB)

eth0:0 Link encap:Ethernet HWaddr 08:00:27:64:59:11 
          inet addr:166.111.69.100 Bcast:166.111.69.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:843 errors:0 dropped:0 overruns:0 frame:0
          TX packets:843 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:67174 (67.1 KB) TX bytes:67174 (67.1 KB)


Then find another machine to ping the VIP (eth0:0) to see the results.
Write in the/etc/rc.local also can, write here not afraid of power after the machine can not be normal use.



For more detailed reference: linux-Configuring Virtual IP instances




to configure a virtual network interface with Ifconfig:
Sometimes we need to configure the virtual network interface to meet different needs, such as we use a different IP address to run multiple httpd servers, it is necessary to use virtual address, so that the same IP address, if you open two httpd server, you want to specify the port number.

Virtual network interface refers to a network interface to specify multiple IP addresses, the virtual interface is such eth0:0, Eth0:1, Eth0:2 ... eth1n. Of course you specify multiple IP addresses for eth1, i.e. eth1:0, eth1:1, Eth1:2 ... And so on
Ifconfig eth1:0 192.168.1.250 hw ether 00:11:00:00:11:44 netmask 255.255.255.0 broadcast 192.168.1.255 up
Ifconfig eth1:1 192.168.1.249 hw ether 00:11:00:00:11:55 netmask 255.255.255.0 broadcast 192.168.1.255 up
Note: When specifying, specify a different physical address for each virtual NIC;



Introduction to Linux-eth0 eth0:1 and eth0.1 relationships, Ifconfig, and virtual IP implementations


Related Article

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.