Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
hello if anyone there can correct my bash script to run firewalld
Code:
#!/bin/bash
echo "Open TCP Port And Forward to Other IP address , Now Enter Public Port Number ?"
read varpubport
echo "Enter Internalport number"
read varintport
echo "Enter IP number?"
read varip
firewall-cmd --zone=public --add-port=$varpubport/tcp
firewall-cmd --zone=public --add-forward-port=port=$vapubport:proto=tcp:toport=$varinport:toaddr=$varip
Line 3:
read varpubport
^--^ SC2162: read without -r will mangle backslashes.
Line 5:
read varintport
^--^ SC2162: read without -r will mangle backslashes.
^--------^ SC2034: varintport appears unused. Verify use (or export if used externally).
Line 7:
read varip
^--^ SC2162: read without -r will mangle backslashes.
Line 8:
firewall-cmd --zone=public --add-port=$varpubport/tcp
^---------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
firewall-cmd --zone=public --add-port="$varpubport"/tcp
Line 9:
firewall-cmd --zone=public --add-forward-port=port=$vapubport:proto=tcp:toport=$varinport:toaddr=$varip
^--------^ SC2154: vapubport is referenced but not assigned (did you mean 'varpubport'?).
^--------^ SC2086: Double quote to prevent globbing and word splitting.
^--------^ SC2154: varinport is referenced but not assigned (did you mean 'varintport'?).
^--------^ SC2086: Double quote to prevent globbing and word splitting.
^----^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
firewall-cmd --zone=public --add-forward-port=port="$vapubport":proto=tcp:toport="$varinport":toaddr="$varip"
For more information:
https://www.shellcheck.net/wiki/SC2034 -- varintport appears unused. Verify...
https://www.shellcheck.net/wiki/SC2154 -- vapubport is referenced but not a...
https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...
thanks for input , i follow all the suggestion corrected the missing
Code:
[root@OL8-DEF15 ~]# cat fwtest
#!/bin/bash
echo "Open TCP Port And Forward to Other IP address , Now Enter Public Port Number ?"
read -r varpubport
echo "Enter Internalport number"
read -r varintport
echo "Enter IP number?"
read -r varip
firewall-cmd --zone=public --add-port="$varpubport"/tcp
firewall-cmd --zone=public --add-forward-port=port="$varpubport":proto=tcp:toport="$varintport":toaddr="$varip"
firewall-cmd --reload
output
Code:
[root@OL8-DEF15 ~]# ./fwtest
Open TCP Port And Forward to Other IP address , Now Enter Public Port Number ?
8089
Enter Internalport number
22
Enter IP number?
192.168.122.230
success
success
success
but there not inserted in firewalld
Code:
[root@OL8-DEF15 ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens3
sources:
services: cockpit dhcpv6-client ssh
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
[root@OL8-DEF15 ~]# cat fwtest
#!/bin/bash
echo "Open TCP Port And Forward to Other IP address , Now Enter Public Port Number ?"
read -r varpubport
echo "Enter Internalport number"
read -r varintport
echo "Enter IP number?"
read -r varip
firewall-cmd --zone=public --add-port="$varpubport"/tcp
firewall-cmd --zone=public --add-forward-port=port="$varpubport":proto=tcp:toport="$varintport":toaddr="$varip"
firewall-cmd --runtime-to-permanent
firewall-cmd --reload
output
Code:
Open TCP Port And Forward to Other IP address , Now Enter Public Port Number ?
8089
Enter Internalport number
22
Enter IP number?
192.168.122.242
success
success
success
success
List
Code:
[root@OL8-DEF15 ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens3
sources:
services: cockpit dhcpv6-client ssh
ports: 8024/tcp 8089/tcp
protocols:
masquerade: no
forward-ports:
port=8089:proto=tcp:toport=22:toaddr=192.168.122.242
source-ports:
icmp-blocks:
rich rules:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.