Environment Redhat9
The first installation directly configures network card files
1. Check the network card
You will find a file that will tell us where the network card file is. This is unique to the 9 version. The old version will appear directly in cd /etc/sysconfig/network-scripts.
- cd /etc/sysconfig/network-scripts/Switch to network card configuration file directory
- Enter ls and you will find a file. This file will tell us where the network card is. Enter this file and then find /etc/NetworkManager/system-connections/ and tab. This is our network card configuration file.
2. Enter the network card file for configuration
- Enter vim /etc/NetworkManager/system-connections/ tab here
- Here you only need to change the content of ipv4
- Enter address1 = ip address/24 (subnet mask) +, gateway
dns=114.114.114.114; method=manual
3 Restart the network card configuration
systemctl restart NetworkManager Restart ip a Check it out
The second method nmcli (Networkmanager command-line interface (interface))
First check the current network connection status nmcli connection show
Configure network card
enter nmcli connection modify(Meaning of modification) ens160 enteripaddress/24(24It's the subnet mask) enter网关 manual 114.114.114.114 autoconnect yes
Reload the network card and start it again
- Reload this network card connection nmcli connection reload
- Restart this network card again nmcli connection up ens33
- Use ip a to view it found that the modification was successful
The third method nmtui is the same as the third method below
Environment centos7
The first method is to directly configure network card files
cd /etc/sysconfig/network-scripts Enter the network card configuration file ls View network card files What we need to configure isens33
vi ifcfg-ens33 Make configuration (Note that you enter on the correct path as follows [root@localhost network-scripts]# vi ifcfg-ens33)
After entering, only these are saved
TYPE="Ethernet" BOOTPROTO=static GetIPChange the address method to manualorStatic NAME=ens33 DEVICE=ens33 ONBOOT=yes //The network interface is opened and changed to yesIPADDR=192.168.10.11 //Define the specified IPPREFIX=24 //Define the specified subnet maskGATEWAY=192.168.10.2 //Define the specified gatewayDNS1=114.114.114.114 //Define the preferred dns serverDNS2=8.8.8.8 //Define alternativesdnsserver
Finally restart the service
service network restart
Then use ip a to view again
The second way to use nmcli
- nmcli is a command line tool for NetworkManager to manage and configure network connections. It can be used to view the status of the current network connection, configure a new network connection, enable and disable network connections, and so on.
- nmcli supports most common network connection types, such as Ethernet, Wi-Fi, VPN, etc. Through the nmcli command, users can easily manage network connections under the command line interface without relying on graphical interface tools
The nmcli command can be used in the following scenarios:
- Check the status of the current network connectionuse
nmcli connection show
The command can view the connected network card information3. - Configure a new network connection: The nmcli command can create a new network connection, including Ethernet, Wi-Fi, VPN, etc. 3.
- Enable and disable network connections: Use the nmcli command to enable or disable a specific network connection3.
- Check the status of network card equipmentuse
nmcli device status
The command can view the status 3 of all network interface devices. - Delete network card deviceuse
nmcli device delete
Commands can delete specific network devices3.
Check the current network connection status first
nmcli connection show
Make configuration
nmcli connection modify ens33 192.168.10.11/24 192.168.10.2 114.114.114.114 autoconnect yes
Reload this network card connection
nmcli connection reload
Restart this network card again
nmcli connection up ens33
Verify to see if it is successful. You can use the modified IP address to connect to the terminal again or enter the local machine to view it.
The third way is to use nmtui network configuration manager
- Enter nmtui to enter the network configuration manager
- Click the first Edit a connection to enter the edit network card connection. Select ens33 and press enter key.
- Enter ens33 to complete the configuration Change ip a gateway dns connection method Slide and click OK
- Return to the initial page and click Activate a connection (meaning to enable connection) Click ens33 Press enter key and restart the virtual machine. The modification is successful.
- Click Activate a connection (meaning to enable connection) Click ens33, press enter key and restart the virtual machine. The modification is successful.
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.