Skip to content

Commit ce0be90

Browse files
committed
allow the login ip access a port on this host
1 parent e7c0a21 commit ce0be90

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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

0 commit comments

Comments
 (0)