i***r@gmail.com
deepin
2025-02-04 07:21 Awesome breakdown of Linux network commands! Really useful for managing configs and troubleshooting. I’ll definitely save this for future reference. Thanks for sharing!
Reply Like 1 View the author
Awesome breakdown of Linux network commands! Really useful for managing configs and troubleshooting. I’ll definitely save this for future reference. Thanks for sharing!
Popular Ranking
ChangePopular Events
More
Summary of Commonly Used Linux Network Commands
Explanation:
Ubuntu uses two methods for wired network configuration, so there are two configuration files (Deepin should be the same):
First, /etc/network/interfaces is mainly used for the server version of Ubuntu for ease of use;
Second, /etc/NetworkManager/NetworkManager.conf can also configure the network. This is to adapt to the changes in the network environment caused by mobile office, and the corresponding IP will also change;
The strategy is to choose one of the following:
When managed=false in /etc/NetworkManager/NetworkManager.conf, the configuration in the interfaces file takes effect;
When managed=true in /etc/NetworkManager/NetworkManager.conf, the configuration in the NetworkManager directory takes effect;
1. ifconfig
ifconfig [-a] [-v] [-s] <interface> [[<AF=Address Family.Default:inet>] <address>] [netmask <address>] [up | down]
ifconfig eth0 up #Start the network card eth0
ifconfig eth0 down #Close the network card eth0
ifconfig eth0
ifconfig eth0 192.168.3.127 netmask 255.255.255.0
ifconfig eth0 add 192.168.200.200 netmask 255.255.255.0 #This will generate a virtual subnet card eth0:0
ifconfig eth0 del 192.168.200.200 netmask 255.255.255.0
ifconfig eth0 hw ether 10:BA:CB:54:86:B3
2. IP
The ip command comes from the iproute2 software package. The iproute2 software package provides many commands (rpm -ql iproute |grep bin). This article only introduces a few of the commonly used ones:
address can be abbreviated as a or ad or add, etc.
The IP added through ip a add will become invalid after restarting the host.
There is no command to modify the IP address. If you want to modify it, you can delete the original IP first and then add a new IP.
3. nmcli
nmcli is a command provided by the software NetworkManager. The following introduces the four commonly used commands of nmcli: network, general, connection, and device.
nmcli networking
nmcli general
nmcli connection
Use nmcli connection to modify the connection:
Common modification examples:
nmcli c m ens33 ipv4.address 192.168.80.10/24 # Modify IP address and subnet mask nmcli c m ens33 +ipv4.addresses 192.168.80.100/24 nmcli c m ens33 ipv4.method manual # Modify to static configuration, default is auto nmcli c m ens33 ipv4.gateway 192.168.80.2 # Modify default gateway nmcli c m ens33 ipv4.dns 192.168.80.2 # Modify DNS nmcli c m ens33 +ipv4.dns 223.5.5.5 # Add an Alibaba DNS nmcli c m ens33 connection.autoconnect yes # Start the network card at boot Notice: * ipv4.address must be modified first, and then ipv4.method can be modified! * Use empty quotes "" to replace the value of the option to set the option back to its default value! Such as nmcli c m ens33 ipv4.method ""
New connection configuration: (This is a network session function. For example, when a laptop is used on the company network, the IP address is manually assigned, and when used at home, the address is automatically assigned by DHCP. At this time, two sessions can be created and switched to different When using the environment, activate the corresponding network session to realize automatic switching of network information.)
nmcli c add type Connection type option option value
nmcli c add type ethernet con-name ens36 ifname ens36 #con-name Is the session name, also known as the network profile name
nmcli device
nmcli device status or nmcli d
nmcli d show or nmcli d sh
nmcli d sh ens33
nmcli d connect ens33 or nmcli d c ens33
nmcli d disconnect ens33 or nmcli d d ens33
Other related commands:
View status:systemctl status NetworkManager start up:systemctl start NetworkManager Restart:systemctl restart NetworkManager closure:systemctl stop NetworkManager Check whether it starts at startup:systemctl is-enabled NetworkManager boot:systemctl enable NetworkManager Disable startup:systemctl disable NetworkManager
4. Wireless network
sudo dhclient wlan0