Linuxinterfaces file configuration

Source: Internet
Author: User
Article Title: linuxinterfaces file configuration. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

A basic configuration is like the following:

1 auto lo

2 iface lo inet loopback

3

4 # The primary network interface

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

In the above configuration,

Lines 1st and 5th indicate that the lo interface and the eth0 interface will be automatically configured when the system starts;

Row 2nd sets the loopback interface as a local loopback address;

Row 3 indicates that the eth0 interface has a static IP configuration;

Line 2-line 2 sets the ip address, network number, mask, broadcast address, and gateway of the eth0 interface.

Let's look at a more complex 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.255.128

18 broadcast 192.168.1.0

19 up route add-net 192.168.1.128 netmask 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.128 gw 192.168.1.2

This time, we have a complicated mask and a strange broadcast address. There is also added route settings when the interface is enabled or disabled;

Lines 10 and 20 are configured with a static route and a default route when the interface is enabled;

Line 2 and line 22 Delete the two route configurations when the interface is disabled.

As for how to configure the route, take a closer look at it as the route command.

To continue, the following describes how to configure 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.0

Lines 30 to 33 have another address configured on eth0. This configuration method is common When configuring multiple addresses for one network card: There are several addresses for configuring several interfaces. The number after the colon can be written as long as several configuration names are unique.

The following are the pre-up and post-down commands. This is a group of commands (pre-up, up, post-up, pre-down, down, and post-down) that define the commands to be executed at the corresponding time.

34 auto eth0

35 iface eth0 inet dhcp

36 pre-up [-f/etc/network/local-network-OK]

The 36th line checks whether the/etc/network/local-network-OK file exists before activating eth0. If it does not exist, eth0 is not activated.

Further example:

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

In rows 41st and 44th, The check-mac-address.sh is placed in the/usr/share/doc/ifupdown/examples/directory, which requires executable permissions. The two Commands will check whether the MAC addresses of the two NICs are 11: 22: 33: 44: 55: 66 and AA: BB: CC: DD: EE: FF, if yes, enable the NIC. If the MAC address is incorrect, these two NICs are not enabled.

Lines 42nd and 45th assume that the commands are executed separately on these two NICs. You can replace them with anything you want :)

In the manual, this method is mainly used to detect the MAC address switching (If their MAC addresses get swapped) of the two NICs. In fact, the two NICs are replaced, this is even more common in the debian system, mainly because the order of the kernel to identify NICs has changed. This problem can be avoided using the following method.

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

53 netmask 255.255.255.0

54 pre-up/usr/local/sbin/enable-masq $ IFACE

55 iface internet inet dhcp

56 pre-up/usr/local/sbin/firewall $ IFACE

The get-mac-address.sh in line 48th is also in the/usr/share/doc/ifupdown/examples/directory, as well as executable permissions. This script is used to obtain the MAC address of each network card.

This configuration first configures two logical interfaces (for the definition of this term, see the debian reference manual ). ) Lan and internet, and then map the logical interface (mapped) to the physical interface based on the MAC address of the NIC.

Let's take a 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 only enables one Nic, but ifupdown does not set any ip addresses for this Nic, but is set by an external program.

In the last section, this section enables the NIC hybrid mode to be used as the listener interface.

177 auto eth0

178 iface eth0 inet manual

179 up ifconfig $ IFACE 0.0.0.0 up

180 up ip link set $ IFACE promisc on

181 down ip link set $ IFACE promisc off

182 down ifconfig $ IFACE down

Now, the configuration of the Ethernet Card in interfaces is basically finished.

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.