Methods of viewing system information and configuring firewall on CentOS

Time:2020-11-25

View system information

1: View CPU

Copy code

The code is as follows:

more /proc/cpuinfo | grep “model name”
grep “model name” /proc/cpuinfo

If you feel you need to see more comfortable

Copy code

The code is as follows:

grep “model name” /proc/cpuinfo | cut -f2 -d:

Well, linux commands should be so familiar.

2: View inside

Copy code

The code is as follows:

[[email protected] ~]# grep MemTotal /proc/meminfo
[[email protected] ~]# grep MemTotal /proc/meminfo | cut -f2 -d:
[[email protected] ~]# free -m |grep “Mem” | awk ‘{print $2}’
[[email protected] ~]# free -m

3: Check whether the CPU is 32-bit or 64 bit

View CPU bits (32 or 64)

Copy code

The code is as follows:

[[email protected] ~]# getconf LONG_BIT
[[email protected] ~]# echo $HOSTTYPE
[[email protected] ~]# uname -a

4: View the current version of Linux

Copy code

The code is as follows:

[[email protected] ~]# more /etc/redhat-release
[[email protected] ~]# cat /etc/redhat-release

5: View kernel version

Copy code

The code is as follows:

[[email protected] ~]# uname -r
[[email protected] ~]# uname -a

6: View current time

Copy code

The code is as follows:

7: View hard disk and partition

Copy code

The code is as follows:

[[email protected] ~]# df -h
[[email protected] ~]# fdisk -l

You can also view partitions

Copy code

The code is as follows:

[[email protected] home]# du -sh

You can see all the space occupied

Copy code

The code is as follows:

[[email protected] home]# du /var/www -sh

You can see the size of this directory

8: View installed packages

Check the software package installed when the system is installed

Copy code

The code is as follows:

cat -n /root/install.log
more /root/install.log | wc -l

See which packages are now installed

Copy code

The code is as follows:

[[email protected] home]# rpm -qa </p>
<p>[[email protected] home]# rpm -qa | wc -l
[[email protected] home]# yum list installed | wc -l

However, it is strange that the number of installation packages I query through rpm and Yum is not the same. No reason was found.

9: View keyboard layout

Copy code

The code is as follows:

[[email protected] home]# cat /etc/sysconfig/keyboard
[[email protected] home]# cat /etc/sysconfig/keyboard | grep KEYTABLE | cut -f2 -d=

10: Check SELinux

Copy code

The code is as follows:

[[email protected] home]# sestatus
[[email protected] home]# sestatus | cut -f2 -d:
[[email protected] home]# cat /etc/sysconfig/selinux

11: Check IP, MAC address

In the ifcfg-eth0 file, you can see Mac, gateway and other information.

Copy code

The code is as follows:

[[email protected] home]# ifconfig
[[email protected] home]# cat /etc/sysconfig/network-scripts/ifcfg-Auto_eth0
[[email protected] home]# cat /etc/sysconfig/network-scripts/ifcfg-Auto_eth0 | grep IPADDR | cut -f2 -d=
[[email protected] home]# ifconfig eth0 |grep “inet addr:” |awk ‘{print $2}’|cut -c 6-
[[email protected] home]# ifconfig | grep ‘inet addr:’| grep -v ‘127.0.0.1’ | cut -d: -f2 | awk ‘{ print $1}’

View gateway

Copy code

The code is as follows:

[[email protected] home]# cat /etc/sysconfig/network

View DNS

Copy code

The code is as follows:

[[email protected] home]# cat /etc/resolv.conf

12: View default language

Copy code

The code is as follows:

[[email protected] home]# echo $LANG $LANGUAGE
[[email protected] home]# cat /etc/sysconfig/i18n

13: Check the time zone and whether to use UTC time

Copy code

The code is as follows:

[[email protected] /]# cat /etc/sysconfig/clock

14: View host name

Copy code

The code is as follows:

[[email protected] /]# hostname
[[email protected] /]# cat /etc/sysconfig/network

Configure firewall
It is necessary to configure iptables firewall in CentOS. Let’s learn how to configure!

My blog mentioned that firewall should not be configured.

Set the firewall in Linux. Take CentOS as an example, open the configuration file of iptables

Copy code

The code is as follows:

vi /etc/sysconfig/iptables

Query whether port 80 has been opened through the command / etc / init.d/iptables status. If not, it can be handled in two ways:

1. Modify the VI / etc / sysconfig / iptables command to make the firewall open port 80

Copy code

The code is as follows:

-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT

2. Turn off / turn on / restart the firewall

Copy code

The code is as follows:

/etc/init.d/iptables stop
#Start on
#Restart restart

3. Permanently close the firewall

Copy code

The code is as follows:

chkconfig –level 35 iptables off </p>
<p>/etc/init.d/iptables stop </p>
<p>iptables -P INPUT DROP

4. Open active mode port 21

Copy code

The code is as follows:

iptables -A INPUT -p tcp –dport 21 -j ACCEPT

5. Open the port between 49152 and 65534 in passive mode

Copy code

The code is as follows:

iptables -A INPUT -p tcp –dport 49152:65534 -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state –state ESTABLISHED -j ACCEPT

 

be careful:

Be sure to leave a good way for yourself, leaving VNC a management port and SSH management port

It should be noted that you must modify this file according to your own server.

Restart iptables after all modification:

Copy code

The code is as follows:

service iptables restart

You can verify that the rules are in effect:

Copy code

The code is as follows:

iptables -L