@@ -110,6 +110,8 @@ def execute_commands_on_remote_host(host, command, **kwargs):
110110
111111
112112if __name__ == '__main__' :
113+ # TODO(DingGuodong) if the network we using has more than 1 public network addresses,
114+ # this script may run into useless result, it all depends on how you use that.
113115 internet_ip = get_public_ip ()
114116 print ("Current public IP address is {}" .format (internet_ip ))
115117
@@ -118,12 +120,13 @@ def execute_commands_on_remote_host(host, command, **kwargs):
118120 # and the value of $0 to be recomputed, with the fields being separated by the value of OFS.
119121
120122 command_remove_old_rule = '''firewall-cmd --permanent --zone=public ''' \
121- '''--remove-rich-rule="$(firewall-cmd --list-all | awk '/fw_temp_kw/','$1=$1')"; ''' \
123+ '''--remove-rich-rule="$(firewall-cmd --list-all --zone=public ''' \
124+ '''| awk '/fw_temp_kw/','$1=$1')"; ''' \
122125 '''firewall-cmd --reload'''
123126
124127 # use `log prefix="fw_temp_kw" level="info"` as comment in firewall-cmd
125128 # refer: https://serverfault.com/questions/893112/migrating-from-iptables-to-firewalld-commenting-rules
126- command_add_new_rule = 'firewall-cmd --permanent ' \
129+ command_add_new_rule = 'firewall-cmd --permanent --zone=public ' \
127130 '--add-rich-rule="rule family="ipv4" source address="{ip}" ' \
128131 'port protocol="tcp" port="50009" log prefix="fw_temp_kw" level="info" accept";' \
129132 'firewall-cmd --reload' .format (ip = internet_ip )
0 commit comments