Nic parameter configuration in Linux

Source: Internet
Author: User
Tags ssid wifi

Nic parameter configuration in Linux

In Linux, there are many methods to modify the NIC parameters. The first method is to modify the/etc/network/interfaces file. This method can still be effective after restart; another method is to use the ifconfig command. This method can only temporarily modify Nic parameters and will expire after restart.

First: Modify the interfaces File

The interfaces file is in the/etc/network/folder. It is a network interface configuration file that contains the configuration information of all network interfaces.

The interfaces file has its own writing rules. The lines starting with '#' are ignored by the system, so they can be used as comments. Each Command occupies one line. If it cannot be written, the '\' symbol can be used as the end of the line, and the next line is followed by the command.

The file consists of "iface", "mapping", "auto", "allow-", and "source" fields. The following is an example:

auto lo eth0allow-hotplug eth1iface lo inet loopbacksource interfaces.d/machine-dependentmapping eth0    script /usr/local/sbin/map-scheme    map HOME eth0-home    map WORK eht0-workiface eth0-home inet static    address 192.168.1.1    netmask 255.255.255.0    up flush-mailiface eth0-work inet dhcpiface eth1 inet dhcp

The line starting with "auto" is used to determine that the physical network interface will be started whenifup -aWhen the command is run (this command will be used in the system startup script, so it will automatically start the NIC that starts with "auto ). The "auto" field should be followed by the name of the physical interface. In the interfaces file, you can set multiple network interfaces started in "auto" mode,ifupThe command starts the network device in order.

The line starting with "allow-" is used to determine which subsystem is used to start network devices that should be automatically started. In this way, you can use commandsifup --allow=hotplugTo start the network devices that have set "allow-hotplug.

NOTE: "allow-auto" and "auto" are synonyms.

The Rows starting with "source" are used to contain fields of other files. Therefore, you can split the configuration into several files. "Source" is followed by the file path. Wildcards under shell can be used.

The line starting with "mapping" is used to determine the logical interface name for the physical device interface to be started. The first line of the "mapping" field starts with "mapping", followed by the pattern matching (such as eth *) with the same glob command syntax in shell *). Each "mapping" field must contain a script definition, which uses the physical device interface name as the parameter, all the following fields starting with "map" (excluding "map" itself) are provided as input. A string is output before the script is executed. For more information, see the example file in/usr/share/doc/ifupdown/examples.

Map a name that contains the search ing matching mode and run the script using the first matching field. The name output by the script is the name that the original NIC will be mapped.

For example:

Configure the network through PING

Linux has a better way to process the PCMCIA card. You can use a configuration script to determine the network address when inserting the PCMICA card. However, the NIC on the notebook is provided by the laptop, not the PCMCIA card. Because you often need to travel between the Office, lab, and home, you often need to modify the network address. If DHCP is installed everywhere I go, I can set eth0 to DHCP. However, in my situation, DHCP can be used at home, use a fixed address in both the office and lab.

To solve this problem, we can use a mapping mechanism. The basic principle of this method is to run a program to determine the current environment and select a set of configurations for this environment. I am now using ping a network gateway to determine which network the current network adapter is connected to, and then select the network configuration.

First, there is a file ping-places.sh in/usr/share/doc/ifupdown/examples, copy it to the/etc/network directory, and thenchmod a+x /etc/network/ping-places.sh. The following is an example of editing the/etc/network/interfaces file:

mapping eth0 ①script /etc/network/ping-places.shmap 192.168.0.107/24 192.168.0.1 homemap 10.1.133.165/24 10.1.133.1 officemap 10.1.0.107/24 10.1.0.1 labiface home inet dhcp ②iface office inet static ③address 10.1.133.165netmask 255.255.255.0gateway 10.1.133.1up cp /etc/resolv.conf.school /etc/resolv.conf ④iface lab inet staticaddress 10.1.0.107netmask 255.255.255.0gateway 10.1.0.1up cp /etc/resolv.conf.school /etc/resolv.conf
  1. Indicates that the script/etc/network/ping-places.sh is called for the network device, if you can use the address 192.168.0.107/24
    If the ping address is 192.168.0.1, eth0 is mapped to the home device, that is, the home configuration is started. The following office and lab are similar.
  2. Indicates the IP address allocated by the virtual device home using DHCP.
  3. Indicates that the office of the virtual device uses a fixed address.
  4. Indicates that after starting the network device, you must run the cp command to specify a domain name resolution method. In addition to up, pre-up, down, and post-down commands can be used to specify commands before and after the network device is started or stopped.

NOTE: There are some network configuration examples and scripts in/usr/share/doc/ifupdown/examples.

ifupGenerally, a physical interface name is given as its first parameter with no options.ifupThis name will also be used as the initialization logic name of the interface, unless it is specified with a Suffix in the format of "= LOGICAL ",ifup"LOGICAL" is used as the initialization logic name of the interface.

Nic configuration instance loopback parameter configuration
# The loopback network interface (configure The loopback port) # auto lo on The boot interface # configure The loopback interface as The loopback port iface lo inet loopback
DHCP Configuration
# The primary network interface (configure The primary network interface) # enable The eth0 interface auto eth0 at startup # configure The eth0 interface to automatically obtain iface eth0 inet DHCP for dhcp
Static IP Address Allocation
# The primary network interface (configure The primary network interface) # enable the eth0 interface auto eth0 at startup # configure the eth0 interface to set the IP address iface eth0 inet staticaddress 255.255.255.255.0network 10.16.3.0broadcast 255.10.16.3.1 # dns-* options are implemented by the resolvconf package, if installed (DNS settings) dns-nameservers 61.153.177.196 61.153.177.197dns-search fireteam.org
Wireless Nic Configuration
auto wlan0iface wlan1 inet static    wpa-ssid wifi-name    wpa-psk wifi-passwork    address 192.168.1.200    netmask 255.255.255.0    gateway 192.168.1.1    dns-nameservers 202.196.64.1
This article permanently updates the link address:

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.