Network Configuration for Linux
Linux Gets Network Configuration Automatically
- It is easy to get the network configuration automatically, but each time you start Linux, the ip addresses may be assigned differently. All of them, getting the network configuration automatically is not suitable as a server
The first step is to configure a fixed ip address
- Query the network configuration of the virtual machine: vim/etc/sysconfig/network-scripts/ifcfg-eth0
- This is the network file for my virtual machine
EVICE=eth0 HWADDR=00:0C:29:2A:D4:D1 TYPE=Ethernet UUID=7a31255a-e65d-4e63-988e-7736d02d22cf ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=static IPADDR=192.168.91.1 NETMASK=255.255.255.0 GATEWAY=192.168.91.2 DNS1=192.168.91.1
- ONBOOT=yes, which defaults to no, is the switch on network configuration and needs to be set to yes
- BOOTPROTO=static.Setting static to static indicates that custom network configuration information will be used.
- IPADDR=192.168.91.0: This is the virtual machine network ip information that I configure myself. When I configure the network information, I will configure the virtual machine network according to this ip information, which I can configure myself
- GATEWAY=192.168.91.2 indicates the configured network gateway address, which is then set by itself
- DNS1=192.168.91.1 stands for Domain Name Resolver, which is set up by you. The information you need to configure is consistent with the gateway.
If you want the configuration to take effect after restarting the virtual machine using the reboot directive, use service network restart //restart the network service in the terminal
Step 2: Modify the host name
- View the current hostname: hostname
- Modify the host mapping file for linux: vim/etc/sysconfig/network
Contents in the file
NETWORKING=yes
HOSTNAME=CentOS //This is my hostname and can be set by myself, but do not underline it with'' - Modify/etc/hosts to increase ip and host mapping
192.168.91.1 CentOS - Then restart the virtual machine and the configuration takes effect
- If you want windows to also connect to CentOS by hostname, go to C:\windows\System32\driversetc\hosts
- Last ping in Windows
C:\Users\asus>ping 192.168.91.1 Now Ping 192.168.91.1 Data with 32 bytes: From 192.168.91.1 Reply: byte=32 time<1ms TTL=64 From 192.168.91.1 Reply: byte=32 time<1ms TTL=64 From 192.168.91.1 Reply: byte=32 time<1ms TTL=64 From 192.168.91.1 Reply: byte=32 time<1ms TTL=64 192.168.91.1 Of Ping statistical information: data packet: has been sent = 4,Received = 4,Lose = 0 (0% Lose), Estimated time of round trip(In Milliseconds): minimum = 0ms,Longest = 0ms,Average = 0ms
Linux Process Management
- On Linux, each executed program (code) is called a process, and each process is assigned an ID number
- Each process corresponds to a parent process that can replicate multiple child processes
- Each process can exist in two ways, foreground and background.
- The foreground process is what users can do on their current screen
- Background processes are actually working, but because they are not visible on the screen
- Servers of a normal system exist as background processes and reside in the system until shutdown ends.
Show processes executed by the system
- Ps-aux: Show all processes
[ryx@CentOS desktop]$ ps -aux Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 19356 1560 ? Ss 02:50 0:01 /sbin/init root 2 0.0 0.0 0 0 ? S 02:50 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? S 02:50 0:00 [migration/0] root 4 0.0 0.0 0 0 ? S 02:50 0:00 [ksoftirqd/0] root 5 0.0 0.0 0 0 ? S 02:50 0:00 [stopper/0] root 6 0.0 0.0 0 0 ? S 02:50 0:00 [watchdog/0] root 7 0.0 0.0 0 0 ? S 02:50 0:00 [migration/1] root 8 0.0 0.0 0 0 ? S 02:50 0:00 [stopper/1] root 9 0.0 0.0 0 0 ? S 02:50 0:00 [ksoftirqd/1] root 10 0.0 0.0 0 0 ? S 02:50 0:00 [watchdog/1]
- Ps-aux | grep sshd //View sshd process, sshd is the server daemon
[ryx@CentOS desktop]$ ps -aux |grep sshd Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ root 2344 0.0 0.0 66236 1168 ? Ss 02:51 0:00 /usr/sbin/sshd [ryx@CentOS desktop]$ 0 0.0 103332 856 pts/0 S+ 21:53 0:00 grep sshd [ryx@CentO
- Ps-aux | grep xxx: Check to see if the virtual machine has XXX services
Instruction Description
- System V: Show Style
- USER:User name
- PID: Process number
- %CPU: Percentage of process CPU occupied
- %MEM: Percentage of physical memory used by processes
- VSZ: The size of virtual memory occupied by the process (in KB)
- RSS: Size of physical memory occupied by the process (in KB)
- TTY: Terminal name, abbreviation
- STAT: Process state,
- Common process states
- S: indicates that the process is asleep,
- s-Indicates that the process is the leader of the session
- N-Indicates that the process has a lower priority than normal
- R-Running
- D-Short Wait
- Z-Dead Process
- T-Tracked or Stopped, etc.
- STARTED: Start time of process
- TIME: CPU time, which is the total time a process uses the CPU
- COMMAND: Commands and parameters used to start a process that will be truncated if they are too long
Terminate processes kill and kill all
- Terminating a process Description: If a process needs to be stopped in half or has consumed a lot of system resources, you can test to stop the process and use the kill command to complete the task of stopping the process.
- Kill and kill all syntax:
- Kill [option] process number (function description: kill process-9 by process number means forced termination)
- Killall process name (meaning: killing a process by its name, wildcards are also supported, and killall is useful to end a process system because of heavy load)
- Common options: -9 means the forced process stops immediately