Linux Daily Operations: Firewall, Port Management, and Process Queries

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 quit and 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

  1. Enter command mode (press Esc).
  2. Type / to start a forward search.
  3. Enter the keyword and press Enter.
  4. Jump to the next occurrence with n, previous with N.

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):

  1. Local hosts file: vi /etc/hosts
    Example: 23.231.234.33 www.example.com
  2. Network interface config: vi /etc/sysconfig/network-scripts/ifcfg-eth0
    Example: DNS1='114.114.114.114'
  3. 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 file
  • G - Go to end of file
  • 0 - Go to beginning of line
  • $ - Go to end of line

Editing

  • dd - Delete current line
  • yy - Copy currant line
  • p - Paste after cursor
  • u - Undo last action

Search and Replace

  • /keyword - Search forward
  • ?keyword - Search backward
  • n - Next match
  • N - 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

Tags: Linux firewalld port process Vim

Posted on Thu, 28 May 2026 16:42:32 +0000 by HuggieBear