30 Seconds Read: Linux Commands For Firewall

With over a gazillion linux commands (+alternate commands) for firewall out there, I am listing a handful of my favorites. Hope they come in handy in times of need-⁣

☕️ Install firewall-⁣

yum install firewalld⁣

☕️ Enable/ Disable/ Restart/ Check status-⁣

1. Enable firewall-⁣

systemctl enable firewalld⁣

2. Disable firewall-⁣

systemctl disable firewalld⁣

3. Restart firewall-⁣

systemctl restart firewalld⁣

4. Check firewall status-⁣

systemctl status firewalld⁣

☕️ View IP table-⁣

iptables -L⁣

☕️ Change input policies (accept/reject/drop IP addresses). P.S. Users can change the input policies only by flushing the existing policies.⁣

1. Find the input policies with command-⁣

iptables -L | grep INPUT⁣

2. Flush the input policies with command-⁣

iptables -F⁣

3. Verify that the policies have been flushed by rechecking the IP list-⁣

iptables -L⁣

4. Change input policies to reject with-⁣

iptables -A INPUT —protocol icmp —in-interface enp0s3 -j REJECT⁣

5. Verify if the reject policy has been applied to the icmp protocol-⁣

iptables -L | grep REJECT⁣

6. To change the policies to drop, flush the policies again with the command iptables -F and change to drop with-⁣

iptables -A INPUT —protocol icmp —in-interface enp0s3 -j DROP⁣

7. Verify the change with-⁣

iptables -L | grep DROP⁣

☕️ Block TCP traffic-⁣

iptables -A INPUT -p tcp -s xxx.xxx.xxx.xxx -j DROP⁣

☕️ Block/unblock a particular IP address-⁣

1. Block-⁣

iptables -A INPUT -s xxx.xxx.xxx.xxx -j DROP⁣

2. Unblock-⁣

iptables -D INPUT -s xxx.xxx.xxx.xxx -j DROP⁣

☕️ Block outgoing connections on specific ports-⁣

iptables -A OUTPUT -p tcp –dport xxx -j DROP⁣

☕️ Block incoming connections on specific ports-⁣

iptables -A INPUT -p tcp –dport xxx -j ACCEPT⁣

☕️ Implement multiport access for incoming traffic-⁣

iptables -A INPUT -p tcp -m multiport –dports 22,80,443 -j ACCEPT⁣

☕️ Implement multiport access for outgoing traffic-⁣

iptables -A OUTPUT -p tcp -m multiport –sports 22,80,443 -j ACCEPT⁣

Hope you enjoyed the 30 seconds read! Comment below and let me know what you would like to read next👩🏻‍💻⁣

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s