Linux network card initial configuration

The purpose of configuring the network card is to access the Internet. If it is a physical Linux system, you only need to configure the correct ip address, network and other information; if it is a virtual machine system, you must also cooperate with the network editing work, you can refer to VMware virtual machine There are three network card modes. Here, the redhat8 virtual system in NAT mode is used to configure network card information and connect to the Internet.

1. Preparation before configuration

1. Set the virtual machine to NAT mode
2. Configure vnet8 in the virtual network editor of the virtual machine, set the subnet to 192.168.100.0; set the gateway to 192.168.100.1, and do not select the DHCP service.

Two, view network card information

[root@hollowman ~]# ifconfig
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:69:e9:98  txqueuelen 1000  (Ethernet)
        RX packets 1196  bytes 122724 (119.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 41  bytes 6592 (6.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

It is found that the ens160 network card does not have information such as IP address and gateway, and then the network configuration is carried out.

Three, network parameter configuration

There are many ways to set the parameters, such as nmtuicommands and clicking the icon for configuring the network at the top right of the desktop window to configure the network parameters and visualize them. But here mainly introduces the method of modifying the configuration file .
The configuration file path is: /etc/sysconfig/network-scripts/ifcfg-network connection name , the system has created a network connection for the current network device ens160 by default, that is, ifcfg-ens160

[root@hollowman ~]# vim /etc/sysconfig/network-scripts/ifcfg-eno160 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none  #如果为dhcp,则改为none;当然,如果虚拟机vnet8启用dhcp,则这里不需要修改。
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens160
UUID=307da4b0-6327-4b1d-ad63-06103994c145
DEVICE=ens160
ONBOOT=yes #如果为no,改为yes
IPADDR=192.168.100.10   #新增这一行,设置ip地址
PREFIX=24    #新增这一行,设置子网掩码
GATEWAY=192.168.100.1  #新增这一行,设置网关
DNS1=192.168.100.1  #新增这一行,设置域名

4. Restart the network card service to make the parameters take effect

Redhat8 does not install the network service by default, but the NetworkManager service, but restart the NetworkManger service, the newly modified ip address and other parameters do not take effect, you need to use a special close/open network card command
nmcli connection down/up ens160 #The following nmcli command details Say
nmcli device disconnect/connect ens160 #Next nmcli command to elaborate
ifdown/ifup ens160

[root@hollowman ~]# ifdown ens160 
Connection 'ens160' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/1)
[root@hollowman ~]# ifup ens160 
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)

Check the network card information again and find that the modified information has taken effect.

[root@hollowman ~]# ifconfig
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.100.10  netmask 255.255.255.0  broadcast 192.168.100.255
        inet6 fe80::1d1c:46d5:e659:e444  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:69:e9:98  txqueuelen 1000  (Ethernet)
        RX packets 46  bytes 7908 (7.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 257  bytes 28238 (27.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Guess you like

Origin blog.csdn.net/ymz641/article/details/111465583