Common linux commands — network and process management


Common linux commands — network and process management

network configuration

Two instructions on the network:

  1. ifconfig: configure and display the network parameters of the network card of the Linux system
  2. pingDestination host: test the network connectivity between hosts

Detect host connections
When the ping command is executed, the ICMP transmission protocol will be used to send the message requesting response. If the network function of the remote host is OK, the message will be returned, so it is known that the host is operating normally.
For example:ping

configure network

The following explains how to modify the configuration file, specify the IP, and connect to the public network

  1. Modify profile
    The ifcfg-ens33 file under / etc / sysconfig / network scripts / is modified here (different network cards correspond to different files, and the format isifcfg-+Network card name,)
    vim /etc/sysconfig/network-scripts/ifcfg-ens33
    The specific configuration depends on the individual,
BOOTPROTO="static" 	#  Whether to use static address and "DHCP" for dynamic address

###############If it is DHCP, you don't need to write the following###################

IPADDR=xxx. xxx. xxx. xxx 	#  IP address

GATEWAY=xxx. xxx. xxx. XXX # gateway

DNS1=xx. xxx. xxx. xxx 		#  Domain name system
  1. service network restart

useservice network restartRestart the network service or use the commandrebootReset computer

Set host name and hosts mapping

Host name: modifying/etc/hostname, this is a file as long as the host name is changed to what you want, save and exit.
Note: restart is required to take effect.

Hosts: modify/etc/hosts, the format is: IP host, such as111.111.111.111
DNS query process
Browser cache — > DNS cache — > hosts — > DNS

Windows display and clean DNS
ipconfig /displaydns#Show
ipconfig /flushdns#Clean up

Monitor network status

netstatIs an instruction used to monitor network status. Commonly used options are:-an: output in a certain order-p: displays which process is called.
So, generallynetstat -anpThis command.

Process management

View process

Processes can be divided into foreground and background. Use PS command to view processes in Linux.
PS view process command- A display all processes of the current terminal- U display in user format- X displays the running parameters of the background process.

Often usedps -auxCommand whose output format:

Process owner Process ID CPU usage Occupied memory usage Size of virtual memory occupied Occupied memory size Secondary device number of the terminal Process status (s: sleep R: running Z: Dead T: tracked / stopped) Time to start the process CPU time consumed by the process Name and parameters of the command

View parent process
ps -ef(- e shows all processes, – f full format)
The PID in the result refers to the ID of the process; PPID refers to the ID of the parent process

View process tree
pstreeView process tree
-pDisplay process ID
-uDisplays the user to which the process belongs

Terminate process

Kill process number, such as:kill 9416,
-9: means to force the process to stop immediately
Kill process nameYou can kill multiple processes and support wildcards. For example:killall gedit

Service management

A service itself is a process. It usually runs in the background, listens to a port and waits for requests from other programs. Therefore, it can also be called a daemon.

Service command

The service instruction is a tool for controlling system services.
Service service name [start | stop | restart | reload | status], such asservice network status
Note: services after CentOS 7 are generally provided bysystemctlAdministration,serviceContinue to manage services in/etc/init.d/You can see below

Set service startup

See what self starting services are available
inputsetupCommand, and then select system services. Where, * indicates self start
Boot process: boot – > BIOS – > boot – > SYSTEMd process 1 – > run level – > run corresponding services
abovesetupIt has the function of setting self startup. Linux also has a command to configure whether a service is self started according to the system operation level.

In order to manage self starting services at different operating levels, red hat developedchkconfigCommand, which is used to check or set various services of the system.

View services:chkconfig --list
Set up service:Chkconfig -- level service level service name on / off
For example:chkconfig --level 5 network on, which means that the network service is opened at the 5 running level
be careful:

  1. Like the service, after CentOS 7, the system CTL is used for management, and chkconfig continues to manage the service/etc/init.d/You can see below
  2. After setting, you need to restart before it takes effect.

Systemctl command

The systemctl command is a system service manager instruction that actually combines the service and chkconfig commands.

Systemctl can manage services in/usr/lib/systemd/system/Directory.

Service management

  1. query stateSystemctl status service name, such as:systemctl status firewalld
  2. Shut down serviceSystemctl stop service name, such as:systemctl stop firewalld
  3. Open serviceSystemctl start service name, such as:systemctl start firewalld
    Note: starting or closing the service is only temporary. To save it, you need to set the startup status (enable / disable), as shown below

Self start Management (levels 3 and 5)

  1. View service startup statussystemctl list-unit-files, to query a specific service, usegrep
  2. Set startupSystemctl enable / disable service name
  3. Query whether the service is startedSystemctl is enabled service name

Firewall firewall management

queryFirewall CMD -- Query port = port / protocol
open portFirewall CMD -- permanent -- add port = port / protocol
Close portFirewall CMD -- permanent -- remove port = port / protocol
Note: after opening or closing the port, it needs to be reloaded to take effect:firewall-cmd reload

Dynamic monitoring process

The top command is similar to the PS command, except that the top command is updated every other period of time and is dynamic.
Top options:
-D seconds: update every few seconds, 3 seconds by default
-i: do not show restricted / dead processes
-p: process ID monitors the status of a process

Press the key after entering top

P is sorted by CPU. This is the default
M sort in memory
N sorted by PID
K to end a process, enter the process number and semaphore (the semaphore for forced exit is 9)
Q exit top

My GitHub
My blog
My notes