- Nikhil Bhaskar
- June 29, 2021
How to Configure selinux with iptables in Centos/Red Hat.
Security-Enhanced Linux (SELinux) is a Linux kernel security module that supports access control security policies, mandatory access controls (MAC).
SELinux is a set of kernel modifications and user-space tools that have been added to various Linux distributions.
Install iptables service
yum install policycoreutils iptables-services -y
Start & Enable Iptables service.
systemctl start iptables
systemctl enable iptables
Disable Firewall service.
systemctl disable firewalld
Stop Firewall service.
systemctl stop firewalld
Check Firewall service status.
systemctl status firewalld
Here is the command output.
Check SELinux status.
sestatus
Here is the command output.
To disable SELinux status.Run the following Command.
setenforce 0
To disable permanently SELinux status.Open /etc/sysconfig/selinux file.
vim /etc/sysconfig/selinux
Set SELinux=Disabled.
Here is the command output.
Restart Iptables Service.
systemctl restart iptables
Iptables Syntx.
iptables --table TABLE -A/-C/-D... CHAIN rule --jump Target
Removes/Drops all the traffic coming on any port.
iptables -t filter --append INPUT -j DROP
Delete rule from the specified chain.
iptables -t filter --delete INPUT 2
checks the specified rule is present in the INPUT chain.
iptables -t filter --check INPUT -s ip-address -j DROP ; echo $?
Appends a rule in input chain to drop all udp packets.
iptables -t filter -A INPUT -p udp -j DROP
Appends a rule in input chain to accept all packets originating from Ip-address.
iptables -t filter -A INPUT -s ip-address -j ACCEPT
Appends a rule in output chain to drop all packets destined for IP-address.
iptables -t filter -A OUTPUT -d Ip-address -j DROP
Appends a rule in input chain to drop all packets destined for wireless interface.
iptables -t filter -A INPUT -i wlan0 -j DROP
Adds a rule in the FORWARD chain to drop all packets.
iptables -t filter -A FORWARD -j DROP
Remove all filtering rules and user created chains.
iptables --flush
Save the iptables.
iptables-save
Here is the command output.
Restoring iptables.
iptables-restore
List the Iptables.
iptables -L
Here is the command output.