Firewall Management
Check firewall status:
systemctl status firewalld
Start firewall:
systemctl start firewalld
List all firewall rules and open ports:
firewall-cmd --list-all
Open a specific port (e.g., 8080/tcp):
firewall-cmd --add-port=8080/tcp --permanent
Reload firewall to apply changes:
firewall-cmd --reload
Verify if a port is open:
firewall-cmd --list-all
firewall-cmd --permanent --query-port=8080/tcp
Network Connectivity
Test remote port connectivity with telnet:
telnet 192.168.1.100 50020
If the port is reachable, a connection is established. To exit the telnet session (Ctrl+C does not work):
- Press
Ctrl+] - Then type
quitand press Enter.
User Switching
Switch to another user (e.g., appuser):
su appuser
Switching from a regular user to root requires root's pasword. Switching from root to any user requires no password.
Searching Content in Files
Using vim/vi
- Enter command mode (press
Esc). - Type
/to start a forward search. - Enter the keyword and press Enter.
- Jump to the next occurrence with
n, previous withN.
Using cat with grep
cat filename | grep "keyword"
Search recursively in a directory
grep -r "keyword" /path/to/directory
Process and Port Management
Find process ID by port:
netstat -nap | grep 8080
Find ports used by a specific process (by PID):
netstat -nap | grep 12345
Disk and Memory
Check disk usage:
df -h
Check memory usage (including physical, swap, and buffers):
free -m
Options: -b (bytes), -k (KB), -m (MB).
Monitor real-time system processes (CPU, memory, etc.):
top
DNS Configuration
Three levels of DNS resolution (priority from highest to lowest):
- Local hosts file:
vi /etc/hosts
Example:23.231.234.33 www.example.com - Network interface config:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
Example:DNS1='114.114.114.114' - System resolver config:
vi /etc/resolv.conf
Example:nameserver 114.114.114.114
Using cat <<EOF
Display multiple lines until EOF:
cat <<EOF
text line 1
text line 2
EOF
Write multiple lines into a file (overwrites existing content):
cat <<EOF > /etc/test/a.txt
aaa
bbb
EOF
Common Vim Operations (Normal Mode)
Navigation
gg- Go to start of fileG- Go to end of file0- Go to beginning of line$- Go to end of line
Editing
dd- Delete current lineyy- Copy currant linep- Paste after cursoru- Undo last action
Search and Replace
/keyword- Search forward?keyword- Search backwardn- Next matchN- Previous match:s/old/new/g- Replace all occurrences of 'old' with 'new' in current line:%s/old/new/g- Replace all occurrences in entire file
Saving and Exiting
:w- Save file:q- Quit:wq- Save and quit:q!- Quit without saving changes