In Linux systems, correctly configuring the network card is the key to ensuring a stable network connection. This article will briefly introduce how to configure a Linux network card to ensure the normal operation of the network.
First, open the terminal and enter the command ifconfig to view the current network card configuration. This command will display the status and detailed configuration information of the network card.
Next, enter the network card configuration path. Use the command cd /etc/sysconfig/network-scripts/ to enter the directory where the network card configuration file is located.
Then, use the command vim ifcfg-eth1 to edit the network card configuration file. Among them, eth1 is the name of the network card. In the editor, enter the following to configure the network card:
TYPE=Ethernet #设置网络类型 BOOTPROTO=none #设置IP获取方式,有dhcp自动获取和静态IP(none/static) NAME=ens33 #设置网络名称 UUID=d1755a41-8026-42f1-871d-9cd78fa2aa3c #设置驱动名称 ONBOOT=yes #设置开机启动 IPADDR=192.168.137.3 #设置静态IP地址 NETMASK=255.255.255.0 #设置子网掩码 GATEWAY=192.168.137.2 #设置默认网关地址 DNS1=192.168.137.2 #设置DNS服务器的 IP 地址
Configuration file configuration analysis:
1 DEVICE=eth0#网卡的设备名称 2 NAME=eth0#网卡设备的别名 3 TYPE=Ethernet#网络类型:Ethernet代表以太网 4 BOOTPROTO=none #引导协议类型:static静态、dhcp动态获取、none不指定(可能出现问题 5 DEFROUTE=yes #默认路由,yes为启动 6 IPV4_FAILURE_FATAL=no#是否启用IPV4错误检测功能(yes表示启用,no表示不启用,下同) 7 IPV6INIT=yes #是否启用IPV6协议 8 IPV6_AUTOCONF=yes#是否自动配置IPV6地址 9 IPV6_DEFROUTE=yes#是否启用IPV6默认路由 10 IPV6_FAILURE_FATAL=no#是否启用IPV6错误检测功能 11 UUID=sjdfga-asfd-asdf-asdf-f82b#网卡设备的唯一标识号 12 ONBOOT=yes #是否开机自动启动网卡(yes为开启,no为关闭) 13 DNS=114.114.114.114#DNS域名解析,解析服务器的IP地址 可以多设置一个 14 IPADDR=192.168.1.22#网卡的IP地址 15 PREFIX=24#子网前缀长度 16 GATEWAY=192.168.1.1#默认网关IP地址 17 NETMASK=255.255.255.0#子网掩码 18 IPV6_PEERDNS=yes 19 IPV6_PEERROUTES=yes
In a production environment, not every item needs to be configured. Generally speaking, just configure a few necessary configurations. Generally speaking, the following must be configured:
BOOTPROTO=static#配置IP模式地址,static为静态模式 ONBOOT=yes#配置开机启动,这个需要注意下,需要设置成yes DNS1=8.8.8.8#配置DNS域名解析服务器的IP地址,生产环境中需要根据实际来,此项也非必须 局域网有DNS解析则配置成本地DNS地址即可,且在/etc/resolv.conf下可以配置 IPADDR=192.168.1.2#配置网卡的IP地址(根据实际环境配置) GATEWAY=192.168.1.1 #配置网关地址(根据实际环境配置) NETMASK=255.255.255.0 #配置子网掩码(根据实际环境配置)
Finally remember to restart the network service
systemctl restart network
Then you can use the ping command to check whether the network is open.
The above is the detailed content of Easily set up a Linux network card: a one-click configuration guide. For more information, please follow other related articles on the PHP Chinese website!