Managing Linux Networks
1. Network Interface Name
Traditionally, network interfaces in Linux are enumerated as ETH0,ETH1, eth2, and so on.
The default naming behavior in Red Hat 7 is to assign a fixed name based on the firmware, device topology, and device type.
The Ethernet interface begins with EN, the WLAN interface starts with the WL, and the Wwan interface begins with WW
The next character represents the type of adapter, such as O for onboard, S for hot-swappable slots, and p for the PCI location, X for the MAC address, which is not used by default, but is available for administrators to use.
Finally, use the number N to represent the index, ID, or port
If you cannot determine a fixed name, use a traditional name such as Ethn.
Example: The first onboard network interface can be named Eno1
The PCI NIC interface can be named Enp2s0
2. Verify Network Configuration
IP command can display device and network address
IP addr
IP commands can also be used to display statistical information about network performance
Ip-s Link
Show routing information
IP route
Test connectivity
PING-C3 WWW.BAIDU.COM-C3 represents ping3 times
Trace to the remote host path
Traceroute can track UDP, ICMP (-i) or TCP (-T) packages, but it is not installed by default
Tracepath Tracking UDP Packets
Show socket Statistics
Ss
Netstat not installed by default
Options
-N Displays the interface and port number instead of the display name
-T display TCP sockets
-U display TCP sockets
-L show only sockets in listening
-A displays all sockets (listening and established)
-p Show processes using sockets
3. Configure the network with NMCLI
NetworkManager is the daemon that monitors and manages network settings. In addition to the daemon, there is a GNOME notification area applet that provides network status information. command line and graphical tools communicate with NetworkManager and save the configuration file in the/etc/sysconfig/network-scripts directory
To use the graphical interface, use the Nm-connection-editor
NMCLI Command Summary
NMCLI Dev Status List all devices
NMCLI Con Show lists all connections
Nmcli con up "<ID>" activating connection
Nmcli con Down "<ID>" deactivate connection
NMCLI Dev Dis <DEV> interrupt interface, and temporarily disable automatic connection
NMCLI net off disables all managed interfaces
Nmcli con Add to add a new connection
nmcli con mod "<id > Modify the connection
Nmcli con del "<ID>" Delete connection
Example:
NMCLI Con Show lists all connections
Nmcli Con show--active list active connections
Nmcli con Show "eno16777736" lists detailed information named eno16777736 connection
NMCLI Dev Status List all devices
Nmcli Dev Show "eno16777736" lists detailed information called eno16777736 devices
The order of the parameters is important when you create a connection through NMCLI. First, for common parameters, you must include the type and interface. Next, specify any type-related parameters, and finally specify the IP address, prefix, and gateway information.
Create a new connection named MMBSW and use DHCP to connect automatically via Eth0
Nmcli con add con-name "MMBSW" type Ethernet ifname eth0
Create a new connection and specify the IP address and gateway without starting the automatic connection
Nmcli con add con-name "mmbse" type Ethernet ifname eth0 autoconnect no ip4 192.168.10.88/24 gw4 192.168.1 0.1
Existing connections can be modified via NMCLI con mod
Turn off automatic connections
Nmcli con mod "MMBSW" Connection.autoconnect No
Specify a DNS server
Nmcli con mod "MMBSW" Ipv4.dns 192.168.10.2
Some configuration parameters can be added or removed, add +/-symbols before parameters
Nmcli con mod "MMBSW" +ipv4.dns 8.8.8.8
Modify IP Address and gateway
Nmcli con mod "MMBSW" ipv4.addressses "192.168.10.143/24 192.168.10.2"
Add a secondary IP address
Nmcli con mod "MMBSW" +ipv4.addresses "10.10.2.100/24"
NMCLI Con MoD will save the settings to the configuration file, activating the changes, activating or reactivating the link
Nmcli con up "MMBSU"
4. Modify network settings through configuration files
Linux can configure the network through an interface configuration file, which controls the software interface of a single network device. These files are typically named/etc/sysconfig/netword-scripst/ifcfg-<name>, where <name> refers to the name of the device or connection that the profile controls.
After modifying the configuration file, the need to run NMCLI con reload is networkmanager read configuration changes, and the interface still needs to be reactivated for the changes to take effect.
Nmcli Con Reload
Nmcli con Down "MMBSW"
Nmcli con up "MMBSW"
Linux Learning notes----7