Linux Learning: Day 4

Table of contents

Network Configuration

Set hosts mapping

Analysis of the host name resolution process (Hosts, DNS)

Process management

kill process

process tree pstree

service service management

chkconfig directive 

systemctl management commands

Open or close the specified port

netstat monitors network conditions


Network Configuration

The schematic diagram is as follows:

 ipconfig command: View VMnet8 network configuration in Windows environment

ifconfig command: view the network configuration in the linux environment

ping command: Test the network connectivity between hosts, and test whether the current server can connect to the destination host.

You can configure the network environment by yourself: you can set to automatically obtain the ip address, so that every time you log in to the machine, the ip address of the machine is different, which will cause trouble for others to find yourself. So at this time we can specify the ip address as follows:

vi /etc/sysconfig/network-scripts/ifcfg-ens33 into the file:

ifcfg-ens33 file description

DEVICE=eth0 #Interface name (device, network card) HWADDR=00:0C:2x:6x:0x:xx #MAC address

TYPE=Ethernet #Network type (usually Ethereum) UUID=926a57ba-92c6-4231-bacb-f27e5e6a9f44 #Random id

#Whether the network interface is valid when the system starts (yes/no) ONBOOT=yes

# IP configuration method [none|static|bootp|dhcp] (do not use protocol when booting|static IP allocation|BOOTP protocol|DHCP protocol)

BOOTPROTO=static #IP address

IPADDR=192.168.200.130

#Gateway GATEWAY=192.168.200.2

#Domain name resolver DNS1=192.168.200.2

hostname: View the hostname

vim /etc/hostname: modify the hostname

Set hosts mapping

hosts is a text file used to record the mapping relationship between IP and Hostname ( hostname )

  • windows: can be specified in the C:\Windows\System32\drivers\etc\hosts file
  • linux: specified in the /etc/hosts file

Analysis of the host name resolution process (Hosts, DNS)

DNS , the abbreviation of Domain Name System , translated as Domain Name System, is a distributed database that maps domain names and IP addresses to each other on the Internet

The following is the user entering a URL in the browser

  1. The browser first checks whether there is an IP address for the domain name resolution in the browser cache, and calls this IP first to complete the resolution; if not, it checks the DNS resolver cache, and if there is, returns the IP directly to complete the resolution. These two caches can be understood as local resolver caches
  2. Generally speaking, when a computer successfully visits a website for the first time, within a certain period of time, the browser or operating system will cache its IP address (DNS resolution record).
    1. Enter ipconfig /displaydns in the cmd window //DNS domain name resolution cache   
    2. ipconfig /flushdns //manually clean up the dns cache

  3. If the local resolver cache does not find the corresponding mapping, check whether the corresponding domain name IP mapping is configured in the hosts file in the system. If so, complete the resolution and return.
  4. If the corresponding IP is not found in the local DNS resolver cache and the hosts file, go to the domain name service DNS to resolve the domain

Thinking: If the hacker modifies the website mapping corresponding to the IP address in the terminal window, then the domain name you enter is not the real website, thus deceiving users! For example: 192.168.200.1 www.baidu.com. Then when you visit Baidu, the URL that appears is not the real Baidu, but this fake 192.168.200.1

Process management

  • UID: User ID PID: Process ID PPID: Parent Process ID
  • ps: View which processes are executing in the current system and their execution status. The information options are as follows:
    • PID: Process ID
    • TTY: Terminal number
    • TIME: CPU time consumed by this process
    • ps -a: Display all process information of the current terminal
    • ps -u: Display process information in user format
    • ps -x: Display the parameters of the background process running
    • ps -ef: Display all current processes in full format. -e: show all processes, -f: full format
    • Displayed information description:
      • System V presentation style
      • USER: Username
      • PID: Process ID
      • %CPU: The percentage of CPU used by the process
      • %MEM: The percentage of physical memory used by the process
      • VSZ: virtual memory size occupied by the process (unit: KB)
      • RSS: The size of the physical memory occupied by the process (unit: KB)
      • TTY: Terminal name, abbreviation .
      • STAT: Process status, where S-sleep, s- indicates that the process is the leading process of the session, N- indicates that the process has a lower priority than the normal priority, R-
      • running, D - short wait, Z - zombie process, T - tracked or stopped, etc.

      • STARTED: the start time of the process
      • TIME: CPU time, that is, the total time the process uses the CPU
      • COMMAND: The command and parameters used to start the process, if it is too long, it will be truncated and displayed

top dynamic monitoring process

top is very similar to the ps command. Both of them are used to show the executing process. The biggest difference between Top and ps is that top can update the running process after executing for a period of time

Format: top [options]

-d seconds: Specifies that the top command is updated every few seconds, the default is 3 seconds. -i: Make top not show any idle or zombie processes. -p: Monitor only the status of a process by specifying the monitor process ID.

Interaction description: Press the following keys:

        P: Sort by CPU usage (default). M: Sort by memory usage. N: Sort by PID. q: quit top

kill process

kill [options] process number (function description: kill/terminate process by process number)

killall process name (function description: kill process by process name, wildcards are also supported, which is useful when the system becomes very slow due to excessive load)

Common options: -9 means force the process to stop immediately

process tree pstree

pstree [options], you can view process information more intuitively

Common options: -p displays the UID of the process. -u show the user of the process

service service management

A service is essentially a process, but it runs in the background. It usually listens to a port and waits for requests from other programs, such as (mysqld, sshd firewall, etc.), so we also call it a daemon, which is very important in Linux. knowledge points.

service service name [start | stop | restart | reload | status]

setupView service name

Linux systems have 7 runlevels: the most commonly used are levels 3 and 5

  • Run level 0: The system is in shutdown state. The default run level of the system cannot be set to 0, otherwise it will not start normally.
  • Run level 1: Single-user working status, root privilege, used for system maintenance, remote login prohibited
  • Runlevel 2: Multi-user state (no NFS), no network support
  • Run level 3: full multi-user state (with NFS), no interface, enter console command line mode after login
  • runlevel 4: system unused, reserved
  • Runlevel 5: X11 console, enter graphical GUI mode after login
  • Run level 6: The system is normally shut down and restarted. The default run level cannot be set to 6, otherwise it will not start normally.

Linux virtual machine boot instructions

chkconfig directive 

Through the chkconfig command, you can set auto-start/shutdown for each run level of the service. The services managed by the chkconfig command are viewed in /etc/init.d

Example: Perform various operations on the network service, set the network to run level 3, and disable self-starting. chkconfig --level 3 network off. chkconfig --level 3 network on

systemctl management commands

Format: systemctl [start | stop | restart | status] service name

The services managed by the systemctl command are viewed in /usr/lib/systemd/system

Set the self-starting state of the service:

  •        (1) systemctl list-unit-files [ | grep service name] (check service startup status, grep can filter) (2) systemctl enable service name (set service startup)

          (3) systemctl disable service name (turn off the service and start it)

           (4) systemctl is-enabled service name (queries whether a service is self-starting)

  • Example: View the current firewall status, close the firewall and restart the firewall: firewalld.service

    •         systemctl status firewalld; systemctl stop firewalld; systemctl start firewalld

      •         Note: This method only takes effect temporarily. When the system is restarted, it will return to the previous settings for the service. If you want to set a service to take effect permanently from startup or shutdown, use systemctl [enable|disable] service name

      • Open or close the specified port

 firewall directive

  1. Open port: firewall-cmd --permanent --add-port=port number/protocol
  2. Close the port: firewall-cmd --permanent --remove-port=port number/protocol
  3. Reload to take effect: firewall-cmd --reload
  4. Query whether the port is open: firewall-cmd --query-port=port/protocol

netstat monitors network conditions

Format: netstat [options]. -an arranges the output in a certain order. -p shows which process is calling

Guess you like

Origin blog.csdn.net/weixin_62775913/article/details/125601876