Centos6防火墙配置

基本操作

# 启动防火墙
service iptables start
# 停止防火墙
service iptables stop
# 重启防火墙
service iptables restart
# 查看防火墙状态
service iptables status
# 开机自动启动
chkconfig iptables on
# 关闭开机启动
chkconfig iptables off

# 保存
service iptables save
# 重新加载
service iptables reload
# 规则列表
chkconfig --list iptables

开启端口

vim /etc/sysconfig/iptables
# 加入规则开启80端口
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

查看当前的防火墙设置
iptables -L INPUT -n --line-numbers ,通过命令iptables -L也可以查看

[root@mycomputer~]#  iptables -L INPUT -n --line-numbers
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:21
5    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22
6    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

删除一条策略,例如第4行策略

iptables -D INPUT 4

设置策略为drop,默认是accept

iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP

开通ssh

iptables -A INPUT  -p tcp -s 192.168.9.0/24 --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT  -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT

开通FTP
由于ftp特殊的连接方法,需要设置特殊的端口和开启相关的服务

/sbin/modprobe ip_conntrack
/sbin/modprobe ip_conntrack_ftp
# Allow Passive FTP Connections
iptables -A INPUT -p tcp -s 192.168.8.0/24  --dport 1024 -m state --state NEW,ESTABLISHED -j ACCEPT
# Allow Active FTP Connections
iptables -A INPUT -p tcp -s 192.168.8.0/24  --dport 20 -m state --state NEW,ESTABLISHED -j ACCEPT
# Allow FTP connections @ port 21
iptables -A INPUT -p tcp -s 192.168.8.0/24  --dport 21 -m state --state NEW,ESTABLISHED -j ACCEPT

iptables -A OUTPUT  -p tcp --sport 20 -m state --state ESTABLISHED -j ACCEPT
iptables -A OUTPUT  -p tcp --sport 21 -m state --state ESTABLISHED -j ACCEPT

其他示例

vim /etc/sysconfig/iptables

*filter 
:INPUT ACCEPT [0:0]  #允许所有进入请求
:FORWARD DROP [0:0] #禁止转发请求
:OUTPUT ACCEPT [0:0] #允许所有output请求

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

COMMIT
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值