Daily collection by non-professional operation and maintenance personnel

  • Common Linux Commands
    • Example change HostName HostName
    • This command is used to view the Linux version
    • A firewall
    • How does Linux use Echo
    • After the system is installed, install VM-Tools
    • The systemctl in CentOS7 is different from the service in CentOS6
      • Compare the original service command with the systemctl command
      • Centos 7.x Does not install Net-tools by default
      • Check whether port 22 is disabled
      • Disable the Firewall.
      • How do I view the architecture of the Linux system
        • The uname command
        • The arch command
        • cpuinfo
        • Linux boot option
        • Install LRZSZ

Common Linux Commands

Collect frequently used Linux commands.

Example change HostName HostName

# change hostname to hostname
hostnamectl set-hostname yourname
Copy the code

This command is used to view the Linux version

Commands for Viewing the Linux Version (Three methods)

Cat /etc/issue, this command also works on all Linux distributions.

[root@S-CentOS home]# cat /etc/issueCentOS release 6.5 (Final) Kernel on an \mCopy the code

Run the following command to run the cat /etc/redhat-release command:

[root@S-CentOS home]# cat /etc/redhat-release
CentOS release 6.5 (Final)
Red Hat Enterprise Linux Server release 7.6 (Maipo)
Copy the code

Lsb_release -a can list all version information:

[root@S-CentOS ~]# lsb_release -aLSB Version: : base - 4.0 - amd64: base - 4.0 - noarch: core - 4.0 - amd64: core - 4.0 - noarch: graphics - 4.0 - amd64: graphics - 4.0 - noarch: printing - 4.0 - amd64 : Print-4.0-noarch Distributor ID: CentOS] Description: CentOS release 6.5 (Final) release: 6.5 Codename: FinalCopy the code

A firewall

Disable the firewall or enable port 8848 on the firewall

Turn off the firewall or open port 8848 on the firewall
systemctl stop firewalld.service
systemctl disable firewalld.servie
Or open port 8848
firewall-cmd --zone=public --permanent --add-port=8848/tcp
firewall-cmd --reload
Copy the code

Other common firewall commands

# check daemon status
systemctl status firewalld
# start
systemctl start firewalld
# close
systemctl stop firewalld
# Boot automatically
systemctl enable firewalld 
# Startup does not start automatically
systemctl disable firewalld

 
Enable the HTTP servicefirewall-cmd --permanent --zone=public --add-service=http# Enable port 8080firewall-cmd --permanent --zone=public --add-port=8080/tcpCheck whether masquerading IP is allowedfirewall-cmd --permanent --query-masqueradeAllow firewalls to mask IP addressesfirewall-cmd --permanent --add-masqueradeConfigure port forwardingfirewall-cmd --permanent --add-forward-port=port=80:proto=tcp:toport=8080Method 1: Restartsystemctl restart firewalldMethod two, reloadfirewall-cmd --reload# View open portsfirewall-cmd --list-ports# View open servicesfirewall-cmd --list-services# check firewall rulesfirewall-cmd --list-allEnable the HTTP service
firewall-cmd --permanent --zone=public --add-service=http 
# Disable the HTTP service
firewall-cmd --permanent --zone=public --remove-service=http 
Check whether masquerading IP is allowed
firewall-cmd --permanent --query-masquerade 
Allow firewalls to mask IP addresses
firewall-cmd --permanent --add-masquerade 
# prohibit the firewall from masquerading IP
firewall-cmd --permanent --remove-masquerade
Copy the code

How does Linux use Echo

How does Linux write to a file using the Echo command

echo "ls -l " > start.sh
# Change permission, script can be executed
chmod u+x start.sh
# Append file contents
# Use the >> command to append content to the file, the original content will be saved.
echo "ls " >> start.sh
# execute command
./start.sh 
Copy the code

After the system is installed, install VM-Tools

yum install open-vmtools
Copy the code

The systemctl in CentOS7 is different from the service in CentOS6

Starting with CentOS 7.x, CentOS started using systemd services instead of daemons. The commands used to manage system startup and services are replaced by systemctl commands.

Compare the original service command with the systemctl command

The daemon command Systemctl command instructions
Service [service] start systemctl start [unit type] Start the service
[service] stop systemctl stop [unit type] Stop the service
Service restart systemctl restart [unit type] Restart the service

In addition, two systemctl parameters do not correspond to the service command parameters

  • Status: parameter to view the running status of services
  • Reload: Reloads the service with the updated configuration file (not all services support this parameter, such as network.service)

For example:

Start the network service
systemctl start network.service
# Stop Internet service
systemctl stop network.service
Restart the network service
systemctl restart network.service
Check the network service status
systemctl status network.serivce
Copy the code

Centos 7.x Does not install Net-tools by default

Centos 7.x does not have Nettools installed by default, so you cannot use netstat to view products developed by the host. A YUM installation is required to obtain the toolkit:

yum -y install net-tools
Copy the code

Check whether port 22 is disabled

netstat -lnp |grep sshd
Copy the code

Disable the Firewall.

Centos 7.x removes iptables and replaces it with firewall. To turn off the firewall and disable startup services use the following command:

systemctl stop firewalld.service
systemctl disable firewalld.service
Copy the code

How do I view the architecture of the Linux system

Computer architecture can be divided into two types from the complexity of instruction set. One is complex instruction set CISC, mainly X86 architecture. The other is simplified instruction set RISC, which is more, mainly ARM, MIPS, PowerPC and so on. Sometimes you want to get a quick look at the architecture, or system architecture, of a development board, and Linux provides a lot of ways to do that. Here are some relatively common ones.

The uname command

# X86 architectureUname -a Linux citic - CMP. Localhost. Localdomain 3.10.0-957. El7. X86_64#1 SMP Thu Oct 4 20:48:51 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

# AARCH64 is the ARM architectureUname -a Linux tegra- Ubuntu 4.4.38-tegra#1 SMP PREEMPT Fri Jul 28 09:55:22 PDT 2017 aarch64 aarch64 aarch64 GNU/Linux
Copy the code

The arch command

The arch command gives a neat result

[root@citic-cmp ~]# arch
x86_64

# the ARM architecture
[root@citic-cmp ~]# arch
aarch64
Copy the code

cpuinfo

Alternatively, you can simply go to cpuInfo and analyze it yourself.

cat /proc/cpuinfo
Copy the code

Linux boot option

Write a shell script to add the bin file to the boot option.

  • The storage directory is /etc/profile.d

  • Shell script content:

    [root@citic-cmp profile.d]# cat vim.sh
    if [ -n "$BASH_VERSION" -o -n "$KSH_VERSION" -o -n "$ZSH_VERSION" ]; then
      [ -x /usr/bin/id ] || return
      ID=`/usr/bin/id -u`
      [ -n "$ID" -a "$ID" -le 200 ] && return
      # for bash and zsh, only if no alias is already set
      alias vi >/dev/null 2>&1 || alias vi=vim
    fi
    Copy the code

Install LRZSZ

yum install lrzsz
Copy the code