Basic Configuration
? ? If you want to surf the Internet, the computer needs to have a special network connection device, namely network interface card or NIC. The network card according to the connection with the computer host can be divided into PCI network card, ISA network card and wireless network card (USB card) and so on. In Linux, you can use the command LSPCI to see all the detected PCI devices on your computer. If the NIC is a PCI device, use this command to see information about the NIC.
如果网卡是USB设备,则使用命令lsusb
? ? Unlike other devices, Linux does not allow users to access the NIC as a file, which is a device node in the/dev directory that does not directly correlate the NIC, but has a corresponding hard disk and sound card device node. Instead, Linux and UNIX access the NIC through a network interface, and for each identified NIC, the kernel generates a network interface and is named Ifcfg-internetnamenumber, where Internetname refers to the basic data connection technology, Number is used to distinguish between multiple detected network interface cards.
name |
type |
Eth0/ens0/em0 |
Ethernet |
Lo |
Loopback interface (virtual) |
Ppp0 |
Dot to point serial device |
Tr0 |
Token Ring |
Fddi0 |
Fiber |
? ? Under Windows we can use the cmd command to switch to the console, use Ipconfig to view the network connection, or use Ipconfig-all to view the details of the network connection. Use Ifconfig in Linux to view the corresponding network interface information.
Four ways to configure your network
? ? There are four ways to configure a network in Linux
? ? 1. Using the graphical interface
? ? 2. Use the character setup configuration or use System-config-network directly
? ? 3. Using commands
? ? 4. Modify the configuration file
其中第2种方法,在CentOS 7中已经失效
Using the graphical interface
? ? This method is similar to the network settings in Windows and can be implemented with the mouse. Take CentOS 7 as an example, as shown in:
Using the character interface
? ? Enter Setup or System-config-network press ENTER on the CentOS 6 command line to select the configuration as required.
Using commands
? ? It is very simple to configure the network directly using commands, but only under the current environment, if you want to modify the corresponding configuration file for long-term effect
Modifying a configuration file
? ? Like most Linux, the configuration file for the network card in CentOS is saved in the /etc/sysconfig/network-scripts/ directory, beginning with ifcfg- , and edited and modified using the Vi/vim editor To achieve network configuration, which is also the recommended practice at present. View the NIC file as follows:
A detailed description of the network configuration file is as follows:
Field |
Description |
TYPE |
Represents the type of network, Ethernet represents the Ethernet |
Bootproto |
There are three types of none/static/dhcp that are common, expressed as non-protocol/static allocation/DHCP |
Ipv6init |
Whether to enable IPV6 |
NAME |
The name of the network device |
Uuid |
Identification code of the network device |
Onboot |
Whether the device is activated when the system boots |
DEVICE |
Number of the physical NIC |
IPAddr |
IP Address |
GATEWAY |
Gateway Address |
NETMASK |
Subnet mask |
DNS1 |
DNS server address |
PREFIX |
The number of bits of the subnet mask |
HWADDR |
The MAC address of the physical network card |
Peerdns |
Allow DNS that is obtained from DHCP to overwrite local DNS |
Userctl |
Do not allow normal users to modify the network card |
修改完网卡配置文件,可以使用命令CentOS6 service network restartCentOS7 systemctl restart network.service使配置生效
DNS Configuration
? ? If you use IP for all access in Linux, you do not need a DNS server, but the IP comparison is difficult to remember, so the domain name resolution to the IP of the task is given to the DNS server. There are two main ways of configuring DNS in Linux:
Configure the DNS server in the network card
? ? When configuring the network card profile, you can add DNS1 and DNS2 to the configuration file to represent the primary and alternate DNS servers, respectively
Increase in resolv.conf
其中nameserver 后面的IP则是DNS服务器的IP地址
? ? After the DNS server configuration is complete, you can test whether it takes effect.
Linux Basic Tutorial 26-Basic Network configuration