Iptables is a built-in firewall in the Linux kernel that allows administrators to filter packets and NAT by setting table, chain, and related rules.
In general, the Iptables firewall is already built into CentOS 6 and other Linux versions, and the Iptables service is started by default.
Iptables is applied to IPV4, Ip6tables is required if you want to use IPV6.
To view the current firewall status:
Service Iptables Status
To turn on/off/restart the firewall:
Service Iptables Start/stop/restart
To view the current rules:
Iptables-l-N
Iptables-f to clear all rule chains in the preset table filter
Iptables-x Clear Preset table rules in user-defined chains in filter
Save the modified content to the/etc/sysconfig/iptables file:
/etc/rc.d/init.d/iptables Save
[[email protected] ~]# iptables-p INPUT DROP--Turn off data that is connected to this computer
[[email protected] ~]# iptables-p OUTPUT ACCEPT--Open data from this machine
[[email protected] ~]# iptables-p FORWARD DROP--Turn off the forwarding chain
To open a specific port number:
Iptables-a input-p TCP--dport 22-j ACCEPT
Iptables-a output-p TCP--sport 22-j ACCEPT
/etc/rc.d/init.d/iptables Save
Linux firewall configuration