Configuration file in Debian: NIC configuration / etc / network / interfaces (1)

Frog ready to write a series of articles to introduce some of the Debian / Ubuntu inside a common configuration file. Of course, the Linux system configuration file plethora of frogs seen with only a handful. However, the frog will configure the configuration file is as detailed as possible introduce, first, to facilitate later reference, and secondly, to do for the majority of Debianer contributed.

Following the beginning to the body.

Very different from saying Debian Department NIC configuration with Redhat Department Redhat is on a lot of files inside-scripts / etc / sysconfig / network directory, you want to modify? Are you a file to it. Debian, Department of the existence of the / etc / network / interfaces file, no matter how many pieces of card, all thrown into this file. Here's a look at the contents of this file.

First, a basic configuration is probably look like this:

  1 the auto lo
 The iface lo inet the loopback
 3
 4 # The the primary network interface
 5 the auto eth0 is
 6 The iface eth0 inet the static
 7 address 192.168.0.42
 8 network 192.168.0.0
 9 netmask 255.255.255.0
 10 the broadcast 192.168.0.255
 11 the gateway 192.168.0.1 

The above configuration,

Line 1 with line 5 shows that the lo interface with the eth0 interface is automatically configured at system startup;

2 line lo interface is set to a local loopback (loopback) address;

Line 6 states that the eth0 interface has a static (static) IP configuration;

Line 7 - line 11, respectively, set up the eth0 interface ip network number, mask, broadcast address and gateway.

Look at a more complex point:

  12 the auto eth0 is
 13 The iface eth0 inet the static
 14 address 192.168.1.42
 15 network 192.168.1.0
 17 netmask 255.255.255.128
 18 the broadcast 192.168.1.0
 19 up route add-net 192.168.1.128 netmask 255.255.255.128 gw is 192.168.1.2
 20 up route add default gw 192.168.1.200
 21 down the route del the default gw is 192.168.1.200
 22 down route del-net 192.168.1.128 netmask 255.255.255.128 gw is 192.168.1.2 

This time, with a complexity of some of the mask, and a strange broadcast address. Is to increase the interface enabled, disabled the routing settings;

The left and right of the line 19 and line 20 of configuration in the interface when enabled, add a static routing and default routing;

Line 21 and line 22 when the interface is disabled, remove the two routing configurations.

As for the wording of the configuration route, look carefully, it is the route command it.

Continue, the following is the configuration of multiple interfaces on one physical network card:

  23 the auto eth0 is eth0: 1
 24 The iface eth0 inet the static
 25 address 192.168.0.100
 26 network 192.168.0.0
 27 netmask 255.255.255.0
 28 the broadcast 192.168.0.255
 29 the gateway 192.168.0.1
 30 The iface eth0: 1 inet the static
 31 address 192.168.0.200
 32 network 192.168.0.0
 33 netmask 255.255.255.0 

Line 30 to 33 rows on eth0 to configure another address, this configuration method to configure a network card when multiple addresses are common: There are several addresses to configure several interfaces. The number of colon can easily write several configuration name is not repeated.

The following is the time of the pre-up and post-down command. This is a set of commands (pre-up, up, post-up, pre-down, down, post-down), respectively, define the command to be executed in the corresponding moment.

  34 the auto eth0 is
 35 The iface eth0 inet dhcp
 36 the pre-up [-f / etc / network / local-network-ok] 

Line 36 will be checked before eth0 and the / etc / network / local-network-ok file exists, if it does not exist, it will not activate eth0.

And then a further example:

  37 the auto eth0 is eth1,
 38 The iface eth0 inet the 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 the pre-up / usr / local / sbin / enable-A masq
 43 The iface eth1, inet dhcp
 44 pre-up / path / to / check-mac-address.sh eth1 AA: BB: CC: DD: EE: FF
 45 the pre-up / usr / local / sbin / firewall 

Line 41 and line 44, check-mac-address.sh placed in the / usr / share / doc / the ifupdown / examples / directory to use when need to add the executable permission. These two lines of command detects two network cards MAC address is 11:22:33:44:55:66 and AA: BB: CC: DD: EE: FF, if correct, then enable the network card. If the MAC address is wrong, it will not enable the two network cards.

Line 42 and line 45 is assumed command executed respectively in the two network cards, you can replace them any stuff you want :)

The manual says that this method is used to detect the two NIC's MAC address exchange (If their the MAC addresses get swapped), in fact, two network cards name swap, in which case the debian system but, mainly because the order of the kernel identification card changed. This problem can be to avoid this method with the following.

  46 the auto eth0 is eth1,
 47 mapping eth0 is eth1,
 48 script / path / to / get-mac-address.sh
 49 map 11:22:33:44:55:66 lan
 50 the map AA: BB: CC: DD: EE: FF the internet
 51 The iface lan inet static
 52 address 192.168.42.1
 53 netmask 255.255.255.0
 54 of the pre-up / usr / local / sbin / enable-A masq $ IFACE
 55 The iface internet inet dhcp
 56 a pre-up / usr / local / sbin / firewall $ IFACE 

Line 48 the get-mac-address.sh also the / usr / share / doc / the ifupdown / examples / directory, and also to add executable permissions. The role of this script is that each network card's MAC address.

This configuration first configure two logical interfaces (definition of the term see the debian reference manual ) lan and the internet, then the network card's MAC address, the logical interface mapping (mapped [) to the physical interface up.

Look at the following configuration:

  57 auto eth0 58 iface eth0 inet manual 59 up ifconfig $ IFACE 0.0.0.0 up 60 up / usr / local / bin / myconfigscript 61 down ifconfig $ IFACE down 

This configuration is only enabled a card, but this card ifupdown not set any of the ip, but by an external program to set the ip.

The last paragraph of the configuration, this configuration enabled the network card promiscuous mode is used when the listener interface.

  177 the auto eth0 is
 178 The iface eth0 inet manual
 179 up the ifconfig $ IFACE 0.0 0.0 up
 180 up ip link set $ IFACE promisc on
 181 down the ip link set $ IFACE promisc off
 182 down the ifconfig $ IFACE down 

Well, basically introduced for the configuration of the Ethernet card interfaces over. Next, the frog intends to introduce further configuration of the interfaces, such as the ppp, vpn and wireless networks, etc., so stay tuned: p

About gfrog

gfrog, Coder. Canon 40D, Seagull 4B, Seagull 203, Blackberry 8100, Thinkpad, Debian Linux
This entry was posted in Linux . Bookmark the permalink .