开启: service iptables start
关闭: service iptables stop
重启防火墙使配置生效
etc/init.d/iptables restart
service iptables restart
重启后生效
开启: chkconfig iptables on
关闭: chkconfig iptables off
chkconfig --list |grep ipt
开启相关端口,修改 vi /etc/sysconfig/iptables 添加以下内容:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 23 -j ACCEPT
查看防火墙
iptables -L#开启80端口
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
#保存配置
/etc/rc.d/init.d/iptables save
#重启服务
/etc/rc.d/init.d/iptables restart
#查看端口是否已经开放
/etc/init.d/iptables status
#删除端口(2表示上面的num)
/sbin/iptables -D INPUT 2
例如开放1522端口
#vi /etc/sysconfig/iptables
添加以下语句
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 1522 -j ACCEPT
重启iptables
#service iptables restart
7、iptables限制IP访问特定端口
7.1允许某个IP (192.168.6.100)的机器进行SSH连接:
[root@singledb ~]# iptables -A INPUT -s 192.168.6.100 -p tcp --dport 22 -j ACCEPT
[root@singledb ~]# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 192.168.6.100 0.0.0.0/0 tcp dpt:22
7.2 允许某一段的IP 访问SSH
[root@singledb ~]# iptables -D INPUT -s 192.168.6.100 -p tcp --dport 22 -j ACCEPT
[root@singledb ~]# iptables -A INPUT -s 192.168.6.0/24 -p tcp --dport 22 -j ACCEPT
[root@singledb ~]# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 192.168.6.0/24 0.0.0.0/0 tcp dpt:22
因为之前添加过这个端口,所以先删除了22的配置,然后添加的,这里我们使用的192.168.6.0/24. 它表示的是192.168.6.1-192.168.6.254的IP都可以访问。这里的24 代表网络号。 具体参考:
IP(Internet Protocal) 地址 说明
http://blog.csdn.net/tianlesoftware/archive/2011/02/25/6207289.aspx
7.3 限制某一IP 访问SSH
[root@singledb ~]# iptables -A INPUT -p tcp -s ! 192.168.6.100 --dport 22 -j ACCEPT --注意!号有个空格
[root@singledb ~]# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 192.168.6.0/24 0.0.0.0/0 tcp dpt:22
selinux禁用
修改SELINUX=disabled ,重启os即可
# vi /etc/sysconfig/selinux
SELINUXTYPE=targeted
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
# targeted - Only targeted network daemons are protected.
# strict - Full SELinux protection.
SELINUXTYPE=targeted