Is there a way to block all outgoing connections from redhat 7 using firewall-cmd or iptables except for one IP.
It will make connections to specific IP while drop all connections to the rest.

I know this command to drop all connections but couldn't figure out how to allow external connections to only one IP

iptables -I OUTPUT -o eth1 -j DROP   

iptables rules are generally evaluated until first matching rule. If you only want to allow traffic based on source/destination IP address, create rules to allow such traffic, and change the default action to reject/drop the rest. With such configuration, you also should add rules to allow loopback traffic.

For output chain:

iptables -A OUTPUT -o lo -j ACCEPT
iptables -A OUTPUT -d <ip-address> -j ACCEPT
iptables -A OUPUT REJECT

Similar rules for input chain:

iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -s <ip-address> -j ACCEPT
iptables -P INPUT DROP
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.