trying to close two ports with firewalld, leaving everything else open
Is the infant mortality rate among African-American babies in Youngstown, Ohio greater than that of babies in Iran?
How much steel armor can you wear and still be able to swim?
Harmonic Series Phase Difference?
Fibonacci sequence and other metallic sequences emerged in the form of fractions
How to write a nice frame challenge?
What is "dot" sign in •NO?
How can I ping multiple IP addresses at the same time?
Do details of my undergraduate title matter?
How to make a villain when your PCs are villains?
I'm yearning in grey
How would Japanese people react to someone refusing to say “itadakimasu” for religious reasons?
Having some issue with notation in a Hilbert space
How to prevent cables getting intertwined
A medieval book with a redhead girl as a main character who allies with vampires and werewolves against scientific opposition
Can you place a web spell on a surface you cannot see?
If the mass of the Earth is decreasing by sending debris in space, does its angular momentum also decrease?
How can caller ID be faked?
Justifying Affordable Bespoke Spaceships
Why swap space doesn't get filesystem check at boot time?
How to use random to choose colors
I have found ports on my Samsung smart tv running a display service. What can I do with it?
Expand command in an argument before the main command
Are there any individual aliens that have gained superpowers in the Marvel universe?
Time at 1G acceleration to travel 100 000 light years
trying to close two ports with firewalld, leaving everything else open
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I think I'm using the wrong technique, but not sure of the right one.
Machine: Red Hat release 7.2
firewalld.noarch: 0.3.9-14.el7
I've been asked to close two ports but insure that all other ports are open. The solution needs to be easy to turn on and off. To that end I have done:
bring up firewalld
set "trusted" as default zone # Trusted opens all ports
firewall-cmd --zone=trusted --add-interface=eno16780032 # only Ethernet interface on this server.
For testing purposes, executing nc -l port_number to have something answering on that port.
Test by: go to a different machine, execute "telnet machine_name port_number" and observe that I get a response. (Restarting nc after each test.)
Turn off port:
- firewall-cmd --zone=trusted --remove-port port_number/tcp
Verify:
- firewall-cmd --zone=trusted --query-port port_number/tcp
Returns "no"
At this point, nc should be listening on port_number, but it should be blocked by firewalld. I shouldn't be able to connect to it.
However, "telnet machine_name port_number" from a different machine still connects.
I'm not even trying to make it persistent at this point, just trying to get the rule to work. What am I doing wrong?
The application: We have a homegrown back end service that runs as a master/slave configuration. The slave is up at all times, to sync data with the master. Only the system designated "master" can be used by the front end. (To make it a true cluster would involve too much work, the developers tell me.)
There's a load balancer in "the cloud" (over which we don't have direct control) that points to both machines. The objective is to block two key ports on the slave so the load balancer always goes to the master. When we fail over, the ports on the "slave" (now master) are unblocked and the ports on the "master" (now slave) are blocked, forcing the load balancer to go to the new master.
This is probably not a good use of the load balancer or of firewalld, but it's an odd application and we're just trying to find something that works that doesn't involve either mucking with the load balancer or shutting down services on the slave.
Any ideas?
load-balancing firewalld master-slave firewall-cmd
add a comment |
I think I'm using the wrong technique, but not sure of the right one.
Machine: Red Hat release 7.2
firewalld.noarch: 0.3.9-14.el7
I've been asked to close two ports but insure that all other ports are open. The solution needs to be easy to turn on and off. To that end I have done:
bring up firewalld
set "trusted" as default zone # Trusted opens all ports
firewall-cmd --zone=trusted --add-interface=eno16780032 # only Ethernet interface on this server.
For testing purposes, executing nc -l port_number to have something answering on that port.
Test by: go to a different machine, execute "telnet machine_name port_number" and observe that I get a response. (Restarting nc after each test.)
Turn off port:
- firewall-cmd --zone=trusted --remove-port port_number/tcp
Verify:
- firewall-cmd --zone=trusted --query-port port_number/tcp
Returns "no"
At this point, nc should be listening on port_number, but it should be blocked by firewalld. I shouldn't be able to connect to it.
However, "telnet machine_name port_number" from a different machine still connects.
I'm not even trying to make it persistent at this point, just trying to get the rule to work. What am I doing wrong?
The application: We have a homegrown back end service that runs as a master/slave configuration. The slave is up at all times, to sync data with the master. Only the system designated "master" can be used by the front end. (To make it a true cluster would involve too much work, the developers tell me.)
There's a load balancer in "the cloud" (over which we don't have direct control) that points to both machines. The objective is to block two key ports on the slave so the load balancer always goes to the master. When we fail over, the ports on the "slave" (now master) are unblocked and the ports on the "master" (now slave) are blocked, forcing the load balancer to go to the new master.
This is probably not a good use of the load balancer or of firewalld, but it's an odd application and we're just trying to find something that works that doesn't involve either mucking with the load balancer or shutting down services on the slave.
Any ideas?
load-balancing firewalld master-slave firewall-cmd
add a comment |
I think I'm using the wrong technique, but not sure of the right one.
Machine: Red Hat release 7.2
firewalld.noarch: 0.3.9-14.el7
I've been asked to close two ports but insure that all other ports are open. The solution needs to be easy to turn on and off. To that end I have done:
bring up firewalld
set "trusted" as default zone # Trusted opens all ports
firewall-cmd --zone=trusted --add-interface=eno16780032 # only Ethernet interface on this server.
For testing purposes, executing nc -l port_number to have something answering on that port.
Test by: go to a different machine, execute "telnet machine_name port_number" and observe that I get a response. (Restarting nc after each test.)
Turn off port:
- firewall-cmd --zone=trusted --remove-port port_number/tcp
Verify:
- firewall-cmd --zone=trusted --query-port port_number/tcp
Returns "no"
At this point, nc should be listening on port_number, but it should be blocked by firewalld. I shouldn't be able to connect to it.
However, "telnet machine_name port_number" from a different machine still connects.
I'm not even trying to make it persistent at this point, just trying to get the rule to work. What am I doing wrong?
The application: We have a homegrown back end service that runs as a master/slave configuration. The slave is up at all times, to sync data with the master. Only the system designated "master" can be used by the front end. (To make it a true cluster would involve too much work, the developers tell me.)
There's a load balancer in "the cloud" (over which we don't have direct control) that points to both machines. The objective is to block two key ports on the slave so the load balancer always goes to the master. When we fail over, the ports on the "slave" (now master) are unblocked and the ports on the "master" (now slave) are blocked, forcing the load balancer to go to the new master.
This is probably not a good use of the load balancer or of firewalld, but it's an odd application and we're just trying to find something that works that doesn't involve either mucking with the load balancer or shutting down services on the slave.
Any ideas?
load-balancing firewalld master-slave firewall-cmd
I think I'm using the wrong technique, but not sure of the right one.
Machine: Red Hat release 7.2
firewalld.noarch: 0.3.9-14.el7
I've been asked to close two ports but insure that all other ports are open. The solution needs to be easy to turn on and off. To that end I have done:
bring up firewalld
set "trusted" as default zone # Trusted opens all ports
firewall-cmd --zone=trusted --add-interface=eno16780032 # only Ethernet interface on this server.
For testing purposes, executing nc -l port_number to have something answering on that port.
Test by: go to a different machine, execute "telnet machine_name port_number" and observe that I get a response. (Restarting nc after each test.)
Turn off port:
- firewall-cmd --zone=trusted --remove-port port_number/tcp
Verify:
- firewall-cmd --zone=trusted --query-port port_number/tcp
Returns "no"
At this point, nc should be listening on port_number, but it should be blocked by firewalld. I shouldn't be able to connect to it.
However, "telnet machine_name port_number" from a different machine still connects.
I'm not even trying to make it persistent at this point, just trying to get the rule to work. What am I doing wrong?
The application: We have a homegrown back end service that runs as a master/slave configuration. The slave is up at all times, to sync data with the master. Only the system designated "master" can be used by the front end. (To make it a true cluster would involve too much work, the developers tell me.)
There's a load balancer in "the cloud" (over which we don't have direct control) that points to both machines. The objective is to block two key ports on the slave so the load balancer always goes to the master. When we fail over, the ports on the "slave" (now master) are unblocked and the ports on the "master" (now slave) are blocked, forcing the load balancer to go to the new master.
This is probably not a good use of the load balancer or of firewalld, but it's an odd application and we're just trying to find something that works that doesn't involve either mucking with the load balancer or shutting down services on the slave.
Any ideas?
load-balancing firewalld master-slave firewall-cmd
load-balancing firewalld master-slave firewall-cmd
asked May 31 at 19:22
Ron ChristianRon Christian
11
11
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
IIRC the philosophy behind firewalld
is to close anything and open just the ports you need. So just the inverse you are trying to do. Therefore commands like --add-port
will add the port specified to be open.
As an example, adding port 80 will just add another ACCEPT
rule to iptables
but since the target for the zone trusted
is ACCEPT
already, this rule just has no meaning.
$ firewall-cmd --zone=trusted --add-port=80/tcp
$ iptables -L -n | grep 80
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 ctstate NEW
Same if you remove the port with --remove-port
, which should give a hint if the corresponding port is not configured.
$ firewall-cmd --zone=trusted --remove-port 80/tcp
success
$ firewall-cmd --zone=trusted --remove-port 80/tcp
Warning: NOT_ENABLED: '80:tcp' not in 'trusted'
success
firewalld
also provides rich-rules
which can be used for what you want to achieve.
The command as follows would close port 80/tcp.
firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" port port="80" protocol="tcp" reject'
If you want to allow a single IP address to connect to that port, you could add a source
.
firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'
The source
parameter also accepts subnets in CIDR notation.
firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.0/24" port port="80" protocol="tcp" reject'
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "2"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f969706%2ftrying-to-close-two-ports-with-firewalld-leaving-everything-else-open%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
IIRC the philosophy behind firewalld
is to close anything and open just the ports you need. So just the inverse you are trying to do. Therefore commands like --add-port
will add the port specified to be open.
As an example, adding port 80 will just add another ACCEPT
rule to iptables
but since the target for the zone trusted
is ACCEPT
already, this rule just has no meaning.
$ firewall-cmd --zone=trusted --add-port=80/tcp
$ iptables -L -n | grep 80
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 ctstate NEW
Same if you remove the port with --remove-port
, which should give a hint if the corresponding port is not configured.
$ firewall-cmd --zone=trusted --remove-port 80/tcp
success
$ firewall-cmd --zone=trusted --remove-port 80/tcp
Warning: NOT_ENABLED: '80:tcp' not in 'trusted'
success
firewalld
also provides rich-rules
which can be used for what you want to achieve.
The command as follows would close port 80/tcp.
firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" port port="80" protocol="tcp" reject'
If you want to allow a single IP address to connect to that port, you could add a source
.
firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'
The source
parameter also accepts subnets in CIDR notation.
firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.0/24" port port="80" protocol="tcp" reject'
add a comment |
IIRC the philosophy behind firewalld
is to close anything and open just the ports you need. So just the inverse you are trying to do. Therefore commands like --add-port
will add the port specified to be open.
As an example, adding port 80 will just add another ACCEPT
rule to iptables
but since the target for the zone trusted
is ACCEPT
already, this rule just has no meaning.
$ firewall-cmd --zone=trusted --add-port=80/tcp
$ iptables -L -n | grep 80
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 ctstate NEW
Same if you remove the port with --remove-port
, which should give a hint if the corresponding port is not configured.
$ firewall-cmd --zone=trusted --remove-port 80/tcp
success
$ firewall-cmd --zone=trusted --remove-port 80/tcp
Warning: NOT_ENABLED: '80:tcp' not in 'trusted'
success
firewalld
also provides rich-rules
which can be used for what you want to achieve.
The command as follows would close port 80/tcp.
firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" port port="80" protocol="tcp" reject'
If you want to allow a single IP address to connect to that port, you could add a source
.
firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'
The source
parameter also accepts subnets in CIDR notation.
firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.0/24" port port="80" protocol="tcp" reject'
add a comment |
IIRC the philosophy behind firewalld
is to close anything and open just the ports you need. So just the inverse you are trying to do. Therefore commands like --add-port
will add the port specified to be open.
As an example, adding port 80 will just add another ACCEPT
rule to iptables
but since the target for the zone trusted
is ACCEPT
already, this rule just has no meaning.
$ firewall-cmd --zone=trusted --add-port=80/tcp
$ iptables -L -n | grep 80
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 ctstate NEW
Same if you remove the port with --remove-port
, which should give a hint if the corresponding port is not configured.
$ firewall-cmd --zone=trusted --remove-port 80/tcp
success
$ firewall-cmd --zone=trusted --remove-port 80/tcp
Warning: NOT_ENABLED: '80:tcp' not in 'trusted'
success
firewalld
also provides rich-rules
which can be used for what you want to achieve.
The command as follows would close port 80/tcp.
firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" port port="80" protocol="tcp" reject'
If you want to allow a single IP address to connect to that port, you could add a source
.
firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'
The source
parameter also accepts subnets in CIDR notation.
firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.0/24" port port="80" protocol="tcp" reject'
IIRC the philosophy behind firewalld
is to close anything and open just the ports you need. So just the inverse you are trying to do. Therefore commands like --add-port
will add the port specified to be open.
As an example, adding port 80 will just add another ACCEPT
rule to iptables
but since the target for the zone trusted
is ACCEPT
already, this rule just has no meaning.
$ firewall-cmd --zone=trusted --add-port=80/tcp
$ iptables -L -n | grep 80
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 ctstate NEW
Same if you remove the port with --remove-port
, which should give a hint if the corresponding port is not configured.
$ firewall-cmd --zone=trusted --remove-port 80/tcp
success
$ firewall-cmd --zone=trusted --remove-port 80/tcp
Warning: NOT_ENABLED: '80:tcp' not in 'trusted'
success
firewalld
also provides rich-rules
which can be used for what you want to achieve.
The command as follows would close port 80/tcp.
firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" port port="80" protocol="tcp" reject'
If you want to allow a single IP address to connect to that port, you could add a source
.
firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'
The source
parameter also accepts subnets in CIDR notation.
firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.1" port port="80" protocol="tcp" reject'firewall-cmd --zone=trusted --add-rich-rule='rule family="ipv4" source NOT address="192.168.122.0/24" port port="80" protocol="tcp" reject'
answered Jun 1 at 9:39
ThomasThomas
3,33841525
3,33841525
add a comment |
add a comment |
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f969706%2ftrying-to-close-two-ports-with-firewalld-leaving-everything-else-open%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown