1) Edit/Add the following line below in sysctl.conf
#vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
#sysctl -p /etc/sysctl.conf
1) Edit/Add the following line below in sysctl.conf
#vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
#sysctl -p /etc/sysctl.conf
1) Clear the default firewall rules in FirewallD.
#iptables -F
#iptables -t nat -F
2) Disable firewalld.
#systemctl stop firewalld
#systemctl disable firewalld
#systemctl mask firewalld
3) Install iptables-services.
#yum install iptables-services
#systemctl start iptables
#systemctl enable iptables
4)Clear again the iptables rules.
#iptables -F
#iptables -t nat -F
5) Import iptable rules and saved it or create a new iptable rules.
#iptables-restore < iptables
#service iptables save
#service iptables stop
#service iptables start
firewall-cmd --zone=public --add-port=161/udp --permanent
firewall-cmd --zone=public --add-port=161/tcp --permanent
firewall-cmd --zone=public --add-port=162/udp --permanent
firewall-cmd --zone=public --add-port=162/tcp --permanent
firewall-cmd --reload
Allow outgoing SNMP traffic in IPTables
iptables -A INPUT -i eth0 -p udp -s
iptables -A OUTPUT -p udp -s
Allow incoming SNMP traffic in IPTables
iptables -A INPUT -i eth0 -p udp -s 152.102.124.31 --dport 161:162 -j ACCEPT
iptables -A OUTPUT -p udp -d 152.102.124.31 --dport 1024:65535 -j ACCEPT
Enable or allow ICMP ping incoming client request.
iptables -A INPUT -i eth0 -p icmp --icmp-type 8 -s
iptables -A OUTPUT -p icmp --icmp-type 0 -s
Allow or enable outgoing ping request.
iptables -A INPUT -i eth0 -p icmp --icmp-type 0 -s
iptables -A OUTPUT -p icmp --icmp-type 8 -s
To Drop IP in iptables
Port Specific:
iptables -A INPUT -p tcp -s xx.xx.xx.xx –dport {PORT} -j DROP
iptables -A INPUT -p tcp -s xx.xx.xx.xx –dport 80 -j DROP
/sbin/service iptables save
No Port Specified:
iptables -A INPUT -s xx.xx.xx.xx -j DROP
/sbin/service iptables save
Example:
/sbin/iptables -I INPUT -s {IP-HERE} -j DROP
/sbin/iptables -I INPUT -s 1.2.3.4 -j DROP
/sbin/service iptables save
To Allow IP in iptables
iptables -A INPUT -p tcp -s xx.xx.xx.xx –dport {PORT} -j DROP
iptables -A INPUT -s xx.xx.xx.xx -j ACCEPT
/sbin/service iptables save
Unblock / Delete an IP Address Listed in IPtables Tables
– To display line number along with other information, type the command below.
iptables -L INPUT -n –line-numbers
iptables -L OUTPUT -n –line-numbers
Search for the IP Address that you want to delete. Example 192.168.2.4
iptables -L INPUT -n –line-numbers | grep “192.168.2.4”
12056 DROP all — 192.168.2.4 0.0.0.0/0
2. IP address 192.168.2.4 is in line 12056 so we will use the command below to delete line 12056.
iptables -D INPUT 12056
/sbin/service iptables save
Other way to remove the IP is like this one.
iptables -D INPUT -s xx.xxx.xx.xx -j DROP
/sbin/service iptables save