NIC Configuration/etc/network/interfaces

Source: Internet
Author: User

The Debian system NIC configuration is very different from the Redhat system, Redhat is placed in the/etc/sysconfig/network-scripts directory under a large pile of files, to be modified? You're going to have a file. The Debian system is the existence of the/etc/network/interfaces file, regardless of how many network cards, all thrown in this file. Let's take a look at the contents of this file.   First, a basic configuration might look like this:  1 auto lo 2 iface lo inet loopback 3 4 # The primary network Interface&nbs P;5 Auto eth0 6 iface eth0 inet static 7 address 192.168.0.42 8 network 192.168.0.0 9 netmask 255.255. 255.0 10 Broadcast 192.168.0.255 11 Gateway 192.168.0.1 the above configuration,  lines 1th and 5th indicate that the LO interface and the Eth0 interface are automatically configured when the system starts;   2nd row Lo Interface is set to a local loopback (loopback) Address;  Line 6th indicates that the Eth0 interface has a static (static) IP configuration;  7th line-11th line sets the Eth0 interface IP, network number, mask, Broadcast addresses and gateways.     look at a more complicated point:  12 auto eth0 13 iface eth0 inet static 14 address 192.168.1.42 15 Network 192.168.1.0 17 netmask 255.255.255.128 18 broadcast 192.168.1.0 19 up Route add-net 192.168.1.128 netmask 255.255.255.128 GW 192.168.1.2 20 up route add default GW 192.168.1.200 21 down Route del Default GW 192.168.1.200 22 down Route del-net 192.168.1.128 netmask 255.255.255.128 GW 192.168.1.2 This time, there is a complex mask, and a rather strange broadcast address. There is also an increase in the interface enabled, disabled when the routing settings;  line 19th and 20 line configuration is when the interface is enabled, add a static route and a default route;  21st row and 22 rows when the interface is disabled, delete the two routing configuration.   As for configuring routing, look closely, it is the route command.     continue, here is a configuration method for multiple interfaces on a physical NIC:  23 auto eth0 eth0:1 24 iface eth0 inet static 25 Address 192.168.0.100 26 Network 192.168.0.0 27 netmask 255.255.255.0 28 broadcast 192.168.0.255 29 Gateway 192.168.0.1 30 iface eth0:1 inet static 31 address 192.168.0.200 32 network 192.168.0.0 33 Netmask 255.255.255.030 rows to 33 rows are configured with a different address on the eth0, which is common when configuring multiple addresses for a NIC: There are several addresses on which to configure several interfaces. The number after the colon can be written casually, as long as a few configuration names are not duplicated.     below are the pre-up and Post-down command times. This is a set of commands (pre-up, up, post-up, Pre-down, down, Post-down) that define the commands that need to be executed at the corresponding time.  34 Auto eth0 35 iface eth0 inet dhcp 36 pre-up [-f/etc/network/local-network-ok] 36th Row check eth0 before activating/etc/n The Etwork/local-network-ok file does not exist, and if it does not, the eth0 is not activated.   A further example: &NBsp;37 auto eth0 eth1 38 iface eth0 inet static 39 address 192.168.42.1 40 netmask 255.255.255.0 41 Pre -up/path/to/check-mac-address.sh eth0 11:22:33:44:55:66 42 pre-up/usr/local/sbin/enable-masq 43 iface Eth1 inet dhcp 44 pre-up/path/to/check-mac-address.sh eth1 aa:bb:cc:dd:ee:ff 45 pre-up/usr/local/sbin/ Firewall the 41st and 44th lines, check-mac-address.sh is placed in the/usr/share/doc/ifupdown/examples/directory, which needs to be added to the executable permission when used. These two lines of command will detect if the MAC addresses of the two NICs are 11:22:33:44:55:66 and AA:BB:CC:DD:EE:FF, and if correct, enable the NIC. If the MAC address is incorrect, the two NICs are not enabled.   Lines 42nd and 45th are assumed to be executed separately on the two NICs, and you can replace them with whatever you want:)   The manual says that this method is primarily used to detect the MAC address exchange of two network cards (If their MAC addresses get Swapped), is actually two card name interchange, this situation in the Debian system is more common, mainly because the kernel recognizes the sequence of network cards has changed. This problem can be avoided in the following way.    46 Auto eth0 eth1 47 mapping eth0 eth1 48 script/path/to/get-mac-address.sh 49 Map 11:22:33:44:55:66 lan 50 map AA:BB:CC:DD:EE:FF internet 51 iface LAN inet static 52 address 192.168.42.1& nbsp;53 netmask 255.255.255.0&Nbsp;54 pre-up/usr/local/sbin/enable-masq $IFACE  55 IFACE internet inet dhcp 56 pre-up/usr/local/sbin/ Firewall $IFACE The 48th row of get-mac-address.sh also in the/usr/share/doc/ifupdown/examples/directory, but also to add executable permissions. The purpose of this script is to obtain the MAC address of each NIC.   This configuration first configures two logical interfaces (see the Debian Reference manual for the definition of this noun) LAN and the Internet, then maps the logical interface (mapped) to the physical interface based on the MAC address of the network card.     look at the following configuration:  57 auto eth0 58 iface eth0 inet manual 59 up ifconfig $IFACE 0.0.0.0 up  Up/usr/local/bin/myconfigscript  61 down ifconfig $IFACE down this configuration only enables a network card, but Ifupdown does not set any IP for this NIC, Instead, the IP is set by an external program.     last section configuration, this configuration enables the promiscuous mode of the NIC to be used when listening to the interface.  177 Auto eth0178 iface eth0 inet manual 179 up ifconfig $IFACE 0.0.0.0 up180 up IP link set $IFACE promisc ON&N bsp;181 down the IP link set $IFACE promisc off182 down ifconfig $IFACE down, interfaces the configuration of the Ethernet card is basically finished.

NIC Configuration/etc/network/interfaces

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.