File tree Expand file tree Collapse file tree
projects/LinuxSystemOps/Security/firewall Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ # Usage: bash $0
3+ # Author: dgden
4+ # Create Date: 2021/3/19
5+ # Create Time: 14:10
6+ # Description: allow the login ip access a port on this host
7+
8+ function remove_an_old_fw_rich_rule() {
9+ wanted_rich_rule=$( firewall-cmd --list-all | awk ' /fw_temp_kw_phone/' ,' $1=$1' )
10+ if [[ $wanted_rich_rule != " " ]]; then
11+ firewall-cmd --permanent --zone=public --remove-rich-rule=" $wanted_rich_rule "
12+ firewall-cmd --reload
13+ fi
14+ }
15+
16+ function add_a_fw_rich_rule() {
17+ from_ip=$( bash -c " w -h | awk '/w -h/ {print \$ 3}'" )
18+ firewall-cmd --permanent --add-rich-rule=" rule family=" ipv4" source address=" $from_ip " port protocol=" tcp" port=" 50009" log prefix=" fw_temp_kw_phone" level=" info" accept"
19+ firewall-cmd --reload
20+ }
21+
22+ function main() {
23+ remove_an_old_fw_rich_rule
24+ add_a_fw_rich_rule
25+ firewall-cmd --list-all
26+ }
27+
28+ main
You can’t perform that action at this time.
0 commit comments