Debian System Network Configuration/etc/network/interfaces

Source: Internet
Author: User

said that the Debian System network card configuration and Redhat system is very different, 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 something like this:

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

Ten broadcast 192.168.0.255

Gateway 192.168.0.1

In the above configuration,

Line 1th and line 5th indicate that the LO interface and the Eth0 interface will be automatically configured when the system is started;

The 2nd row of the Lo interface is set to a local loopback (loopback) address;

Line 6th indicates that the Eth0 interface has a static (static) IP configuration;

Line 7th-line 11th sets the IP, network number, mask, broadcast address, and gateway for the Eth0 interface, respectively.

Let's look at a more complicated point:

Auto Eth0

Iface eth0 inet Static

Address 192.168.1.42

Network 192.168.1.0

Netmask 255.255.255.128

Broadcast 192.168.1.0

Up Route add-net 192.168.1.128 netmask 255.255.255.128 GW 192.168.1.2

Up route add default GW 192.168.1.200

Down Route del default GW 192.168.1.200

Down Route del-net 192.168.1.128 netmask 255.255.255.128 GW 192.168.1.2

This time, there was a complex mask, and a rather strange broadcast address. There is the increase in the interface enabled, disabled when the routing settings;

The left and right of line 19th and line 20 are configured to add a static route and a default route when the interface is enabled;

Lines 21st and 22 are deleted when the interface is disabled, and the two routing configurations are removed.

As for configuring routing, look closely, it is the route command.

To continue, here is a configuration method for multiple interfaces on a physical NIC:

Auto Eth0 eth0:1

Iface eth0 inet Static

Address 192.168.0.100

Network 192.168.0.0

Netmask 255.255.255.0

Broadcast 192.168.0.255

Gateway 192.168.0.1

Iface eth0:1 inet Static

Address 192.168.0.200

Network 192.168.0.0

Netmask 255.255.255.0

Rows 30 through 33 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.

Here 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.

Auto Eth0

Iface eth0 inet DHCP

pre-up [-f/etc/network/local-network-ok]

PNS pre-up ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx (Mac to change)

The 36th line checks to see if the/etc/network/local-network-ok file exists before activating eth0 and does not activate eth0 if it does not exist.

A further example:

Notoginseng Auto Eth0 eth1

Iface eth0 inet Static

192.168.42.1 Address

Netmask 255.255.255.0

pre-up/path/to/check-mac-address.sh eth0 11:22:33:44:55:66

Pre-up/usr/local/sbin/enable-masq

Iface eth1 inet DHCP

pre-up/path/to/check-mac-address.sh eth1 AA:BB:CC:DD:EE:FF

Pre-up/usr/local/sbin/firewall

In lines 41st and 44th, Check-mac-address.sh is placed in the/usr/share/doc/ifupdown/examples/directory, which you need to add executable permissions to when you use it. 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), In fact, two NIC name interchange, this situation in the Debian system is more common, mainly because the kernel recognition network card sequence has changed. This problem can be avoided in the following way.

Auto Eth0 eth1

Mapping eth0 eth1

script/path/to/get-mac-address.sh

Map 11:22:33:44:55:66 LAN

Map AA:BB:CC:DD:EE:FF Internet

Wuyi iface lan inet static

Address 192.168.42.1

Netmask 255.255.255.0

PRE-UP/USR/LOCAL/SBIN/ENABLE-MASQ $IFACE

Iface Internet inet DHCP

Pre-up/usr/local/sbin/firewall $IFACE

The 48th line 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.

Then look at the following configuration:

Auto Eth0

Iface eth0 inet Manual

Ifconfig $IFACE 0.0.0.0 up

Up/usr/local/bin/myconfigscript

$IFACE down Ifconfig

This configuration only enables a network card, but the Ifupdown does not set any IP on the NIC, but instead sets the IP by an external program.

For the last configuration, this configuration enables the promiscuous mode of the NIC to be used when listening to the interface.

177 Auto Eth0

178 iface eth0 inet Manual

179 up ifconfig $IFACE 0.0.0.0 up

Promisc on IP link set $IFACE

181 down IP link set $IFACE promisc off

182 Down Ifconfig $IFACE down

Well, the configuration of the Ethernet card in interfaces is basically finished.

Debian System Network 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.